Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持 GitHub Actions 自动编译 #109

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 145 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
name: Bundle with Pyinstaller
on:
push:
branches: '*'
tags: 'v*'

jobs:
frontend:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.set_tag.outputs.tag }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- id: set_tag
run: |
if ${{ startsWith(github.ref, 'refs/tags/v') }}; then
echo "tag=${GITHUB_REF#refs/tags/v}" >> "$GITHUB_OUTPUT"
else
echo "tag=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
fi

- uses: actions/setup-node@v4
with:
node-version: 18

- name: Build Frontend
working-directory: frontend
run: |
npm install
npm run build

- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: frontend
path: frontend/dist

backend:
needs: frontend
strategy:
matrix:
os: [macos, ubuntu, windows]
runs-on: ${{ matrix.os }}-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Download Frontend
uses: actions/download-artifact@v4
with:
name: frontend
path: frontend/dist

- uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install Dependencies (Host Native)
if: matrix.os != 'macos'
run: |
python3 -m venv venv
${{ matrix.os == 'windows' && 'venv\\Scripts\\activate' || 'source venv/bin/activate' }}
pip3 install -r requirements.txt
pip3 install pyinstaller

- name: Install Dependencies (macOS Universal)
if: matrix.os == 'macos'
run: |
python3 -m venv venv
source venv/bin/activate
pip3 download --no-cache-dir --only-binary=:all: \
--platform=macosx_10_13_universal2 \
-d downloads \
-r requirements.txt \
pyinstaller
pip3 install --upgrade --no-cache-dir --no-index --only-binary=:all: \
--find-links downloads \
-r requirements.txt \
pyinstaller

- name: Bundle blivechat (Linux)
if: matrix.os == 'ubuntu'
run: |
source venv/bin/activate
pyinstaller --noconfirm \
--add-data="data:data" \
--add-data="log:log" \
--add-data="frontend/dist:frontend/dist" \
--name blivechat \
--contents-directory . \
main.py

- name: Bundle blivechat (macOS Universal)
if: matrix.os == 'macos'
run: |
source venv/bin/activate
pyinstaller --noconfirm \
--add-data="data:data" \
--add-data="log:log" \
--add-data="frontend/dist:frontend/dist" \
--name blivechat \
--contents-directory . \
--target-arch universal2 \
main.py

- name: Bundle blivechat (Windows)
if: matrix.os == 'windows'
run: |
venv\\Scripts\\activate
pyinstaller --noconfirm `
--add-data="data;data" `
--add-data="log;log" `
--add-data="frontend\dist;frontend\dist" `
--name blivechat `
--contents-directory . `
main.py

- name: Package Bundle
working-directory: dist
run: 7z a -tzip blivechat-${{ needs.frontend.outputs.tag }}-${{ matrix.os }}-x64.zip blivechat

- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: blivechat-${{ matrix.os }}-x64
path: dist/blivechat-*.zip

release:
needs: backend
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download Artifact
uses: actions/download-artifact@v4

- name: Create Release
uses: softprops/action-gh-release@v2
with:
files: ./**/blivechat-*.zip