Skip to content

Build and Release

Build and Release #5

Workflow file for this run

name: Build and Release
on:
release:
types: [ published ]
push:
tags:
- 120*
- pre-20*
workflow_dispatch:
inputs:
tag:
description: 'Tag'
required: false
env:
PYTHON_VERSION: '3.9'
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=()
items+=('{"build": "macos", "os": "macos-latest", "arch": "x86_64"}')
items+=('{"build": "windows", "os": "windows-latest", "arch": "x86_64"}')
# https://docs.github.com/zh/actions/hosting-your-own-runners/managing-self-hosted-runners/adding-self-hosted-runners
# 如果设置了 secrets `SELF_HOSTED_MACOS_ARM64_RUNNER`,则添加到矩阵
SELF_HOSTED_MACOS_ARM64_RUNNER=${{ secrets.SELF_HOSTED_MACOS_ARM64_RUNNER }}}
if [ -n "$SELF_HOSTED_MACOS_ARM64_RUNNER" ]; then
items+=('{"build":"macos", "os": ["self-hosted", "macOS", "ARM64"], "arch": "aarch64"}')
fi
# 合并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 - macOS
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: |
version="${{ github.ref_name }}"
# 如果是手动触发,则使用输入的tag
if [ -n "${{ github.event.inputs.tag }}" ]; then
version="${{ github.event.inputs.tag }}"
fi
bash ./build-macos.sh --create-dmg --version "$version"
- name: Build Windows app - Windows
if: ${{ matrix.build == 'windows' }}
run: ./build-action
- 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/upload-release-action@2.7.0
if: ${{ matrix.build == 'macos' }}
with:
asset_name: MDCx-$tag-${{ matrix.build }}-${{ matrix.arch }}.dmg
file: dist/MDCx.dmg
prerelease: ${{ startsWith(github.ref, 'refs/tags/pre-') }}
body: |
${{ steps.get-changelog.outputs.CHANGELOG }}
- name: Create Release - Windows
uses: svenstaro/upload-release-action@2.7.0
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-') }}