.github/workflows/action.yaml #174
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: | |
# 每天 00:00 执行 | |
- cron: '0 0 * * *' | |
# 允许手动执行 | |
workflow_dispatch: | |
jobs: | |
check-update: | |
runs-on: ubuntu-latest | |
outputs: | |
changed: ${{ steps.check-version.outputs.changed }} | |
version: ${{ steps.check-version.outputs.version }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Check Version | |
id: check-version | |
run: | | |
curl -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 "changed=0" >> $GITHUB_OUTPUT | |
else | |
echo "::notice title=New Version Found!::$(cat REMOTE_VERSION)" | |
echo "changed=1" >> $GITHUB_OUTPUT | |
fi | |
build: | |
runs-on: ubuntu-latest | |
needs: check-update | |
if: needs.check-update.outputs.changed == '1' | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Install Dependencies | |
run: | | |
sudo apt-get update | |
echo "Installing msitools" | |
sudo apt-get install msitools | |
echo "Installing 7z" | |
curl https://www.7-zip.org/a/7z2201-linux-x64.tar.xz -o 7z.tar.xz | |
mkdir 7z | |
tar -xJf 7z.tar.xz -C 7z | |
echo "PATH=$(pwd)/7z:$PATH" >> $GITHUB_ENV | |
- name: Download packages | |
env: | |
CALIBRE_VERSION: ${{ needs.check-update.outputs.version }} | |
run: | | |
echo "Downloading backend.py v$CALIBRE_VERSION" | |
curl "https://raw.githubusercontent.com/kovidgoyal/calibre/v$CALIBRE_VERSION/src/calibre/db/backend.py" -o backend-original.py | |
ascii_filename_times=$(grep -o "ascii_filename" ./backend-original.py | wc -l) | |
echo "::notice title=\"ascii_filename\" appeared $ascii_filename_times times in backend.py::$ascii_filename_times" | |
echo "Downloading Windows installer v$CALIBRE_VERSION" | |
curl "https://download.calibre-ebook.com/$CALIBRE_VERSION/calibre-64bit-$CALIBRE_VERSION.msi" -o calibre.msi | |
echo "Downloading Linux x64 packages v$CALIBRE_VERSION" | |
curl "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 "https://download.calibre-ebook.com/$CALIBRE_VERSION/calibre-$CALIBRE_VERSION-arm64.txz" -o calibre-arm64.txz | |
echo "Downloading Mac packages v$CALIBRE_VERSION" | |
curl "https://download.calibre-ebook.com/$CALIBRE_VERSION/calibre-$CALIBRE_VERSION.dmg" -o calibre.dmg | |
- name: Extract packages | |
run: | | |
echo "Extracting Windows installer" | |
msiextract calibre.msi -C calibre-win | |
echo "Extracting Linux x64 packages" | |
mkdir calibre-linux-x64 | |
tar Jxf calibre-x64.txz -C calibre-linux-x64 | |
echo "Extracting Linux arm64 packages" | |
mkdir calibre-linux-arm64 | |
tar Jxf 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: | | |
echo "Installing Python Dependencies" | |
pip install -r requirements.txt | |
- name: Build | |
env: | |
CALIBRE_VERSION: ${{ needs.check-update.outputs.version }} | |
run: | | |
python main.py --version $CALIBRE_VERSION | |
- name: on error | |
if: ${{ failure() }} | |
run: | | |
echo "msiextract version" | |
msiextract --version | |
echo "7z version" | |
./7z/7zz i | |
ls -lh calibre-win/PFiles/Calibre2/app/bin/python-lib.bypy.frozen calibre-win/PFiles/Calibre2/app/bin/calibre-launcher.dll calibre-linux-x64/lib/calibre-extensions/python-lib.bypy.frozen calibre-linux-x64/lib/libcalibre-launcher.so calibre-linux-arm64/lib/calibre-extensions/python-lib.bypy.frozen calibre-linux-arm64/lib/libcalibre-launcher.so calibre-mac/calibre.app/Contents/Frameworks/plugins/python-lib.bypy.frozen calibre-mac/calibre.app/Contents/Frameworks/calibre-launcher.dylib | |
# echo "ls -lR" | |
# ls -lR | |
- name: Update Code | |
env: | |
CALIBRE_VERSION: ${{ needs.check-update.outputs.version }} | |
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 | |
- name: Create Release | |
uses: softprops/[email protected] | |
with: | |
body: Calibre v${{ needs.check-update.outputs.version }} | |
draft: false | |
tag_name: v${{ needs.check-update.outputs.version }} | |
files: | | |
patch-win-${{ needs.check-update.outputs.version }}.zip | |
patch-linux-x64-${{ needs.check-update.outputs.version }}.zip | |
patch-linux-arm64-${{ needs.check-update.outputs.version }}.zip | |
patch-mac-${{ needs.check-update.outputs.version }}.zip |