Ver 120240207 #17
Workflow file for this run
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
name: Build and Release | |
on: | |
release: | |
types: [ published ] | |
push: | |
tags: | |
- 120* | |
- pre-20* | |
env: | |
PYTHON_VERSION: '3.9' | |
# MACOS_BUNDLE_ID: com.mdcxuniverse.mdcx | |
jobs: | |
init-matrix: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
# https://github.com/actions/runner/issues/1985#issuecomment-1573518052 | |
- name: Set matrix | |
id: set-matrix | |
run: | | |
items=() | |
# https://docs.github.com/zh/actions/hosting-your-own-runners/managing-self-hosted-runners/adding-self-hosted-runners | |
# items+=('{"build":"macos", "os": ["self-hosted", "macOS", "ARM64"], "arch": "aarch64"}') | |
items+=('{"build": "macos", "os": "macos-latest", "arch": "x86_64"}') | |
items+=('{"build": "windows", "os": "windows-latest", "arch": "x86_64"}') | |
# 合并items到json数组 | |
matrix="matrix=[" | |
for ((i=0; i<${#items[@]}; i++)); do | |
matrix+=" ${items[i]}" | |
if ((i != ${#items[@]}-1)); then | |
matrix+="," | |
fi | |
done | |
matrix+="]" | |
# 输出matrix到GITHUB_OUTPUT | |
echo $matrix >> $GITHUB_OUTPUT | |
build-app: | |
needs: init-matrix | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
include: ${{fromJson(needs.init-matrix.outputs.matrix)}} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: ${{ env.PYTHON_VERSION }} | |
cache: pip | |
- name: Install libraries | |
if: ${{ matrix.build == 'macos' }} | |
run: | | |
# FIX: No package 'gobject-introspection-1.0' found | |
# https://tutorials.technology/solved_errors/osx-gobject-introspection-1_0-found.html | |
brew install gobject-introspection | |
- name: Install dependencies - macOS | |
if: ${{ matrix.build == 'macos' }} | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements-mac.txt | |
pip install pyinstaller==5.8.0 | |
- name: Install dependencies - Windows | |
if: ${{ matrix.build == 'windows' }} | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
pip install pyinstaller==5.8.0 | |
- name: Build macOS app - macOS | |
if: ${{ matrix.build == 'macos' }} | |
run: | | |
chmod +x build-macos.sh | |
./build-macos.sh | |
# cd dist | |
ls -al dist | |
rm dist/MDCx | |
# `upload-artifact`会使文件丢失可执行权限。解决思路,先把`dist`打包成zip,再上传 | |
zip -r MDCx.app.zip dist | |
ls -al | |
- name: Build Windows app - Windows | |
if: ${{ matrix.build == 'windows' }} | |
run: ./build-action | |
# - name: Upload artifact - macOS | |
# uses: actions/upload-artifact@v3 | |
# if: ${{ matrix.build == 'macos' }} | |
# with: | |
# name: MDCx-${{ matrix.build }}-${{ matrix.arch }} | |
# path: | | |
# ./**.app.zip | |
# | |
# - name: Upload artifact - Windows | |
# uses: actions/upload-artifact@v3 | |
# if: ${{ matrix.build == 'windows' }} | |
# with: | |
# name: MDCx-${{ matrix.build }}-${{ matrix.arch }} | |
# path: | | |
# .\MDCx | |
- name: Get changelog | |
id: get-changelog | |
if: ${{ matrix.build == 'macos' }} | |
run: | | |
echo 'CHANGELOG<<EOF' >> $GITHUB_OUTPUT | |
cat changelog.md >> $GITHUB_OUTPUT | |
echo 'EOF' >> $GITHUB_OUTPUT | |
- name: Create Release - macOS | |
uses: svenstaro/[email protected] | |
if: ${{ matrix.build == 'macos' }} | |
with: | |
asset_name: MDCx-$tag-${{ matrix.build }}-${{ matrix.arch }}.app.zip | |
file: MDCx.app.zip | |
prerelease: ${{ startsWith(github.ref, 'refs/tags/pre-') }} | |
body: | | |
${{ steps.get-changelog.outputs.CHANGELOG }} | |
- name: Create Release - Windows | |
uses: svenstaro/[email protected] | |
if: ${{ matrix.build == 'windows' }} | |
with: | |
asset_name: MDCx-$tag-${{ matrix.build }}-${{ matrix.arch }}.exe | |
file: dist/MDCx.exe | |
prerelease: ${{ startsWith(github.ref, 'refs/tags/pre-') }} |