-
Notifications
You must be signed in to change notification settings - Fork 43
465 lines (403 loc) · 20.3 KB
/
action.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
on:
schedule:
# 每天 05:00 执行(北京时间 13:00)
- cron: '0 5 * * *'
# 允许手动执行
workflow_dispatch:
inputs:
targetVersion:
# 目标版本。不提供时会自动检查、更新代码版本、发布 latest release,提供了则不会更新代码版本,release 也不会 latest
description: 'Calibre version'
required: false
default: ''
jobs:
check-update:
runs-on: ubuntu-latest
outputs:
build: ${{ steps.post.outputs.build }}
update: ${{ steps.post.outputs.update }}
version: ${{ steps.post.outputs.version }}
steps:
- name: fetch all tags
uses: actions/checkout@v4
if: ${{ inputs.targetVersion != '' }}
with:
fetch-depth: 0
- name: fetch latest tag
uses: actions/checkout@v4
if: ${{ inputs.targetVersion == '' }}
- name: Pre-check
id: pre
if: ${{ inputs.targetVersion != '' }}
run: |
calibre_url="https://raw.githubusercontent.com/kovidgoyal/calibre/v${{ inputs.targetVersion }}/src/calibre/db/backend.py"
status_code=`curl -L -s -o /dev/null -w "%{http_code}" "${calibre_url}"`
if [ ${status_code} = "200" ]; then
if [ ! $(git tag -l "v${{ inputs.targetVersion }}") ]; then
echo "Target version check OK"
echo "build=1" >> $GITHUB_OUTPUT
echo "update=0" >> $GITHUB_OUTPUT
echo "version=${{ inputs.targetVersion }}" >> $GITHUB_OUTPUT
else
# 本仓库 Tag 已存在
echo "Tag exists"
echo "::error title=Tag exists::Perhaps a patch for v${{ inputs.targetVersion }} has been created"
echo "build=0" >> $GITHUB_OUTPUT
echo "update=0" >> $GITHUB_OUTPUT
fi
else
# 目标版本不存在
echo "Target version not found"
echo "::error title=Invalid version::Calibre v${{ inputs.targetVersion }} not exists"
echo "build=0" >> $GITHUB_OUTPUT
echo "update=0" >> $GITHUB_OUTPUT
fi
cat $GITHUB_OUTPUT
- name: Check Version
id: check
if: ${{ inputs.targetVersion == '' }}
run: |
curl -L -k https://code.calibre-ebook.com/latest -o REMOTE_VERSION
echo "version=$(cat REMOTE_VERSION)" >> $GITHUB_OUTPUT
if diff --brief REMOTE_VERSION CALIBRE_VERSION > /dev/null; then
echo "::notice title=Calibre Version not Changed::$(cat REMOTE_VERSION)"
echo "build=0" >> $GITHUB_OUTPUT
echo "update=0" >> $GITHUB_OUTPUT
else
echo "::notice title=New Version Found!::$(cat REMOTE_VERSION)"
echo "build=1" >> $GITHUB_OUTPUT
echo "update=1" >> $GITHUB_OUTPUT
fi
- name: Post-check
id: post
run: |
if [ "${{ inputs.targetVersion }}" = '' ]; then
echo "build=${{ steps.check.outputs.build }}" >> $GITHUB_OUTPUT
echo "update=${{ steps.check.outputs.update }}" >> $GITHUB_OUTPUT
echo "version=${{ steps.check.outputs.version }}" >> $GITHUB_OUTPUT
else
echo "build=${{ steps.pre.outputs.build }}" >> $GITHUB_OUTPUT
echo "update=${{ steps.pre.outputs.update }}" >> $GITHUB_OUTPUT
echo "version=${{ steps.pre.outputs.version }}" >> $GITHUB_OUTPUT
fi
build:
runs-on: ubuntu-latest
needs: check-update
if: needs.check-update.outputs.build == '1'
env:
CALIBRE_VERSION: ${{ needs.check-update.outputs.version }}
patch_linux_x64_v1: linux-x64-patch-backend-v${{ needs.check-update.outputs.version }}.zip
patch_linux_x64_v2: linux-x64-patch-backend+update-v${{ needs.check-update.outputs.version }}.zip
patch_linux_x64_txz: linux-x64-patched-v${{ needs.check-update.outputs.version }}.txz
patch_linux_arm64_v1: linux-arm64-patch-backend-v${{ needs.check-update.outputs.version }}.zip
patch_linux_arm64_v2: linux-arm64-patch-backend+update-v${{ needs.check-update.outputs.version }}.zip
patch_linux_arm64_txz: linux-arm64-patched-v${{ needs.check-update.outputs.version }}.txz
patch_mac_v1: mac-patch-backend-v${{ needs.check-update.outputs.version }}.zip
patch_mac_v2: mac-patch-backend+update-v${{ needs.check-update.outputs.version }}.zip
outputs:
pyver: ${{ steps.pyver.outputs.PYTHON_VERSION }}
steps:
- uses: actions/checkout@v3
- name: Install Dependencies
run: |
sudo apt-get update
echo "Installing 7z"
curl -L https://www.7-zip.org/a/7z2408-linux-x64.tar.xz -o 7z.tar.xz
mkdir 7z
tar Jxf 7z.tar.xz -C 7z
echo "PATH=$(pwd)/7z:$PATH" >> $GITHUB_ENV
./7z/7zz i
- name: Download packages
run: |
echo "Downloading Linux x64 packages v$CALIBRE_VERSION"
curl -L "https://download.calibre-ebook.com/$CALIBRE_VERSION/calibre-$CALIBRE_VERSION-x86_64.txz" -o calibre-x64.txz
echo "Downloading Linux arm64 packages v$CALIBRE_VERSION"
curl -L "https://download.calibre-ebook.com/$CALIBRE_VERSION/calibre-$CALIBRE_VERSION-arm64.txz" -o calibre-arm64.txz
echo "Downloading Mac packages v$CALIBRE_VERSION"
curl -L "https://download.calibre-ebook.com/$CALIBRE_VERSION/calibre-$CALIBRE_VERSION.dmg" -o calibre.dmg
echo "Download Calibre source"
git clone --depth 1 --branch v$CALIBRE_VERSION https://github.com/kovidgoyal/calibre.git
- name: Extract packages
run: |
echo "Extracting Linux x64 packages"
mkdir calibre-linux-x64
tar Jxvf calibre-x64.txz -C calibre-linux-x64
echo "Extracting Linux arm64 packages"
mkdir calibre-linux-arm64
tar Jxvf calibre-arm64.txz -C calibre-linux-arm64
echo "Extracting Mac packages"
./7z/7zz x -y -ocalibre-mac calibre.dmg calibre.app/Contents/Frameworks/plugins/python-lib.bypy.frozen calibre.app/Contents/Frameworks/calibre-launcher.dylib
- name: Get Python version
id: pyver
run: |
PYV="$(find ./calibre-linux-x64/lib -name 'libpython*' | grep -oP '(?<=libpython)\d\.\d+')"
echo "::notice title=Calibre Python Version::$PYV"
echo "PYTHON_VERSION=$PYV" >> $GITHUB_OUTPUT
- uses: actions/setup-python@v4
with:
python-version: ${{ steps.pyver.outputs.PYTHON_VERSION }}
cache: 'pip'
- name: Install Python requirements
run: |
pip install -r requirements.txt
- name: Patch py
run: |
echo "[=] Patch backend.py"
python patch_backend.py --os unix calibre/src/calibre/db/backend.py backend.py
python compile.py backend.py backend.pyc
echo "[=] Patch update.py"
python patch_update.py calibre/src/calibre/gui2/update.py update.py
python compile.py update.py update.pyc
- name: Patch bypy linux x64
run: |
mkdir -p lib/calibre-extensions/
echo "[=] Patch Linux x64 bypy"
echo "[==] Patch bypy:backend.pyc"
chmod 644 calibre-linux-x64/lib/calibre-extensions/python-lib.bypy.frozen
python patch_bypy.py \
--os linux \
--bypy calibre-linux-x64/lib/calibre-extensions/python-lib.bypy.frozen \
--launcher calibre-linux-x64/lib/libcalibre-launcher.so \
--new-pyc-file backend.pyc \
--embed_path "calibre/db/backend.pyc"
cp calibre-linux-x64/lib/calibre-extensions/python-lib.bypy.frozen \
lib/calibre-extensions/python-lib.bypy.frozen
zip -r $patch_linux_x64_v1 lib
echo "[==] Patch bypy:update.pyc"
python patch_bypy.py \
--os linux \
--bypy calibre-linux-x64/lib/calibre-extensions/python-lib.bypy.frozen \
--launcher calibre-linux-x64/lib/libcalibre-launcher.so \
--new-pyc-file update.pyc \
--embed_path "calibre/gui2/update.py"
cp calibre-linux-x64/lib/calibre-extensions/python-lib.bypy.frozen \
lib/calibre-extensions/python-lib.bypy.frozen
zip -r $patch_linux_x64_v2 lib
tar Jcf $patch_linux_x64_txz calibre-linux-x64/*
- name: Patch bypy linux arm64
run: |
mkdir -p lib/calibre-extensions/
echo "[=] Patch Linux arm64 bypy"
echo "[==] Patch bypy:backend.pyc"
chmod 644 calibre-linux-arm64/lib/calibre-extensions/python-lib.bypy.frozen
python patch_bypy.py \
--os linux \
--bypy calibre-linux-arm64/lib/calibre-extensions/python-lib.bypy.frozen \
--launcher calibre-linux-arm64/lib/libcalibre-launcher.so \
--new-pyc-file backend.pyc \
--embed_path "calibre/db/backend.pyc"
cp calibre-linux-arm64/lib/calibre-extensions/python-lib.bypy.frozen \
lib/calibre-extensions/python-lib.bypy.frozen
zip -r $patch_linux_arm64_v1 lib
echo "[==] Patch bypy:update.pyc"
python patch_bypy.py \
--os linux \
--bypy calibre-linux-arm64/lib/calibre-extensions/python-lib.bypy.frozen \
--launcher calibre-linux-arm64/lib/libcalibre-launcher.so \
--new-pyc-file update.pyc \
--embed_path "calibre/gui2/update.py"
cp calibre-linux-arm64/lib/calibre-extensions/python-lib.bypy.frozen \
lib/calibre-extensions/python-lib.bypy.frozen
zip -r $patch_linux_arm64_v2 lib
tar Jcf $patch_linux_arm64_txz calibre-linux-arm64/*
- name: Patch bypy macOS
run: |
echo "[=] Patch macOS bypy"
echo "[==] Patch bypy:backend.pyc"
chmod 644 calibre-mac/calibre.app/Contents/Frameworks/plugins/python-lib.bypy.frozen
python patch_bypy.py \
--os mac \
--bypy calibre-mac/calibre.app/Contents/Frameworks/plugins/python-lib.bypy.frozen \
--launcher calibre-mac/calibre.app/Contents/Frameworks/calibre-launcher.dylib \
--new-pyc-file backend.pyc \
--embed_path "calibre/db/backend.pyc"
cp calibre-mac/calibre.app/Contents/Frameworks/plugins/python-lib.bypy.frozen .
zip $patch_mac_v1 python-lib.bypy.frozen
echo "[==] Patch bypy:update.pyc"
python patch_bypy.py \
--os mac \
--bypy calibre-mac/calibre.app/Contents/Frameworks/plugins/python-lib.bypy.frozen \
--launcher calibre-mac/calibre.app/Contents/Frameworks/calibre-launcher.dylib \
--new-pyc-file update.pyc \
--embed_path "calibre/gui2/update.py"
cp calibre-mac/calibre.app/Contents/Frameworks/plugins/python-lib.bypy.frozen .
zip $patch_mac_v2 python-lib.bypy.frozen
- uses: actions/upload-artifact@v3
with:
name: patch_linux_x64_v1
path: ${{ env.patch_linux_x64_v1 }}
- uses: actions/upload-artifact@v3
with:
name: patch_linux_x64_v2
path: ${{ env.patch_linux_x64_v2 }}
- uses: actions/upload-artifact@v3
with:
name: patch_linux_x64_txz
path: ${{ env.patch_linux_x64_txz }}
- uses: actions/upload-artifact@v3
with:
name: patch_linux_arm64_v1
path: ${{ env.patch_linux_arm64_v1 }}
- uses: actions/upload-artifact@v3
with:
name: patch_linux_arm64_v2
path: ${{ env.patch_linux_arm64_v2 }}
- uses: actions/upload-artifact@v3
with:
name: patch_linux_arm64_txz
path: ${{ env.patch_linux_arm64_txz }}
- uses: actions/upload-artifact@v3
with:
name: patch_mac_v1
path: ${{ env.patch_mac_v1 }}
- uses: actions/upload-artifact@v3
with:
name: patch_mac_v2
path: ${{ env.patch_mac_v2 }}
build-win:
runs-on: windows-latest
needs: [check-update, build]
env:
CALIBRE_VERSION: ${{ needs.check-update.outputs.version }}
patch_win_v1: win-patch-backend-v${{ needs.check-update.outputs.version }}.zip
patch_win_v2: win-patch-backend+update-v${{ needs.check-update.outputs.version }}.zip
patch_win_msi: win-patched-${{ needs.check-update.outputs.version }}.msi
if: needs.check-update.outputs.build == '1'
steps:
- uses: actions/checkout@v3
- name: Install Dependencies
run: |
echo "Downloading msi2xml"
curl -L https://sourceforge.net/projects/msi2xml/files/msi2xml/2.2.1/msi2xml-2.2.1.957-bin.zip/download -o msi2xml.zip
Expand-Archive msi2xml.zip -DestinationPath .
- name: Download packages
run: |
echo "Downloading Windows msi v$Env:CALIBRE_VERSION"
curl -L "https://download.calibre-ebook.com/$Env:CALIBRE_VERSION/calibre-64bit-$Env:CALIBRE_VERSION.msi" -o calibre.msi
echo "Download Calibre source"
git clone --depth 1 --branch v$Env:CALIBRE_VERSION https://github.com/kovidgoyal/calibre.git
- uses: actions/setup-python@v4
with:
python-version: ${{ needs.build.outputs.pyver }}
cache: 'pip'
- name: Install Python requirements
run: |
pip install -r requirements.txt
- name: Extract
run: |
.\msi2xml.exe -c calibre-win calibre.msi
- name: Patch py
run: |
echo "[=] Patch backend.py"
python patch_backend.py --os win calibre\src\calibre\db\backend.py backend.py
python compile.py backend.py backend.pyc
echo "[=] Patch update.py"
python patch_update.py calibre\src\calibre\gui2\update.py update.py
python compile.py update.py update.pyc
- name: Patch bypy
run: |
mkdir -p Calibre2\app\bin
echo "[=] Patch bypy"
$launcher=python xmltool.py find calibre.xml calibre-launcher.dll
echo "launcher: $launcher"
$bypy=python xmltool.py find calibre.xml python-lib.bypy.frozen
echo "bypy: $bypy"
echo "[==] Patch bypy:backend.pyc"
python patch_bypy.py `
--os win `
--bypy $bypy `
--launcher $launcher `
--new-pyc-file backend.pyc `
--embed_path "calibre/db/backend.pyc"
cp $bypy Calibre2\app\bin\python-lib.bypy.frozen
Compress-Archive `
-Path .\Calibre2 `
-DestinationPath $Env:patch_win_v1
echo "[==] Patch bypy:update.pyc"
python patch_bypy.py `
--os win `
--bypy $bypy `
--launcher $launcher `
--new-pyc-file update.pyc `
--embed_path "calibre/gui2/update.py"
cp $bypy Calibre2\app\bin\python-lib.bypy.frozen
Compress-Archive `
-Path .\Calibre2 `
-DestinationPath $Env:patch_win_v2
echo "[=] Patch xml"
python xmltool.py patch calibre.xml python-lib.bypy.frozen $bypy
- name: Repack
run: |
.\xml2msi.exe -o $Env:patch_win_msi calibre.xml
- uses: actions/upload-artifact@v3
with:
name: patch_win_v1
path: ${{ env.patch_win_v1 }}
- uses: actions/upload-artifact@v3
with:
name: patch_win_v2
path: ${{ env.patch_win_v2 }}
- uses: actions/upload-artifact@v3
with:
name: patch_win_msi
path: ${{ env.patch_win_msi }}
update-upload:
runs-on: ubuntu-latest
needs: [check-update, build, build-win]
env:
CALIBRE_VERSION: ${{ needs.check-update.outputs.version }}
patch_win_v1: win-patch-backend-v${{ needs.check-update.outputs.version }}.zip
patch_win_v2: win-patch-backend+update-v${{ needs.check-update.outputs.version }}.zip
patch_win_msi: win-patched-${{ needs.check-update.outputs.version }}.msi
patch_linux_x64_v1: linux-x64-patch-backend-v${{ needs.check-update.outputs.version }}.zip
patch_linux_x64_v2: linux-x64-patch-backend+update-v${{ needs.check-update.outputs.version }}.zip
patch_linux_x64_txz: linux-x64-patched-v${{ needs.check-update.outputs.version }}.txz
patch_linux_arm64_v1: linux-arm64-patch-backend-v${{ needs.check-update.outputs.version }}.zip
patch_linux_arm64_v2: linux-arm64-patch-backend+update-v${{ needs.check-update.outputs.version }}.zip
patch_linux_arm64_txz: linux-arm64-patched-v${{ needs.check-update.outputs.version }}.txz
patch_mac_v1: mac-patch-backend-v${{ needs.check-update.outputs.version }}.zip
patch_mac_v2: mac-patch-backend+update-v${{ needs.check-update.outputs.version }}.zip
steps:
- uses: actions/checkout@v3
- name: Update Code
if: needs.check-update.outputs.update == '1'
run: |
echo -n $CALIBRE_VERSION > CALIBRE_VERSION
git config --local user.email [email protected]
git config --local user.name github-actions
git add CALIBRE_VERSION
git commit -m "Action: Update to v$CALIBRE_VERSION"
git push
- uses: actions/download-artifact@v3
- name: Create Release
uses: softprops/[email protected]
with:
body: |
## Calibre v${{ env.CALIBRE_VERSION }}
### 文件说明
- backend.zip:只实现了路径不翻译。
- backend+update.zip:在 backend 的基础上还 patch 了更新检查链接和新版本下载链接。使用这个补丁,Calibre 检查更新时会以本项目的版本为准,下版本下载链接也被替换成了本项目 latest releases 地址。
- .msi/.txz:将 backend+update 补丁重新打包后的完整安装包
### 可能有用的链接们
- 原版下载地址:https://calibre-ebook.com/download
- 原版 Win:https://calibre-ebook.com/dist/win64
- 原版 Linux x64:https://calibre-ebook.com/dist/linux-x86_64
- 原版 Linux arm64:https://calibre-ebook.com/dist/linux-arm64
- 原版 macOS:https://calibre-ebook.com/dist/osx
draft: false
tag_name: v${{ env.CALIBRE_VERSION }}
# 因为 softprops/action-gh-releas 还没加 make_latest 选项,所以先用 prerelease 标记
# 相关 PR:https://github.com/softprops/action-gh-release/pull/304
prerelease: ${{ !needs.check-update.outputs.update }}
files: |
patch_win_v1/${{ env.patch_win_v1 }}
patch_win_v2/${{ env.patch_win_v2 }}
patch_win_msi/${{ env.patch_win_msi }}
patch_linux_x64_v1/${{ env.patch_linux_x64_v1 }}
patch_linux_x64_v2/${{ env.patch_linux_x64_v2 }}
patch_linux_x64_txz/${{ env.patch_linux_x64_txz }}
patch_linux_arm64_v1/${{ env.patch_linux_arm64_v1 }}
patch_linux_arm64_v2/${{ env.patch_linux_arm64_v2 }}
patch_linux_arm64_txz/${{ env.patch_linux_arm64_txz }}
patch_mac_v1/${{ env.patch_mac_v1 }}
patch_mac_v2/${{ env.patch_mac_v2 }}