.github/workflows/action.yaml #689
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |