Skip to content

Commit

Permalink
CI: self-hosted macos runner
Browse files Browse the repository at this point in the history
  • Loading branch information
northsea4 committed Feb 17, 2024
1 parent b314755 commit 9cb15e5
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 28 deletions.
48 changes: 24 additions & 24 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ on:
tags:
- 120*
- pre-20*
workflow_dispatch:
inputs:
tag:
description: 'Tag'
required: false

env:
PYTHON_VERSION: '3.9'
# MACOS_BUNDLE_ID: com.mdcxuniverse.mdcx

jobs:
init-matrix:
Expand All @@ -24,10 +28,16 @@ jobs:
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"}')
# 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
# setup-python没有aarch64的python3.9,这里指定python3.10
items+=('{"build":"macos", "os": ["self-hosted", "macOS", "ARM64"], "arch": "aarch64", "python": "3.10"}')
fi
# 合并items到json数组
matrix="matrix=["
Expand All @@ -54,12 +64,12 @@ jobs:
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
python-version: ${{ matrix.python || env.PYTHON_VERSION }}
cache: pip

- name: Install libraries
- name: Install libraries - macOS
if: ${{ matrix.build == 'macos' }}
run: |
# FIX: No package 'gobject-introspection-1.0' found
Expand All @@ -83,29 +93,17 @@ jobs:
- name: Build macOS app - macOS
if: ${{ matrix.build == 'macos' }}
run: |
bash ./build-macos.sh --create-dmg --version "${{ github.ref_name }}"
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: 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' }}
Expand All @@ -118,6 +116,7 @@ jobs:
uses: svenstaro/upload-release-action@2.7.0
if: ${{ matrix.build == 'macos' }}
with:
overwrite: true
asset_name: MDCx-$tag-${{ matrix.build }}-${{ matrix.arch }}.dmg
file: dist/MDCx.dmg
prerelease: ${{ startsWith(github.ref, 'refs/tags/pre-') }}
Expand All @@ -128,6 +127,7 @@ jobs:
uses: svenstaro/upload-release-action@2.7.0
if: ${{ matrix.build == 'windows' }}
with:
overwrite: true
asset_name: MDCx-$tag-${{ matrix.build }}-${{ matrix.arch }}.exe
file: dist/MDCx.exe
prerelease: ${{ startsWith(github.ref, 'refs/tags/pre-') }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/

# Vscode
.vscode/

config.ini
MDCx.config
userdata/
Expand Down
27 changes: 23 additions & 4 deletions build-macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ do
--help|-h)
echo "Usage: build-macos.sh [options]"
echo "Options:"
echo " --version, -v Specify the version number. Required!"
echo " --version, -v Specify the version number. \
The value within config.ini.default file will be usded if not specified."
echo " --create-dmg, -dmg Create DMG file. Default is false."
exit 0
;;
Expand All @@ -29,10 +30,28 @@ do
done


# Check if APP_VERSION is set
# 从配置文件获取应用版本
getAppVersionFromConfig () {
local configPath="$1"
if [[ -f "$configPath" ]]; then
local version=$(cat $configPath | grep -oi 'version\s*=\s*[0-9]\+' | grep -oi '[0-9]\+$')
echo $version
else
echo ''
fi
}


# Check APP_VERSION
if [ -z "$APP_VERSION" ]; then
echo "❌ Please specify the version number using --version option!"
exit 1
echo "APP_VERSION is not set. Trying to get it from config.ini.default..."
APP_VERSION=$(getAppVersionFromConfig "config.ini.default")
if [ -z "$APP_VERSION" ]; then
echo "❌ APP_VERSION is not set and cannot be found in config.ini.default!"
exit 1
else
echo "APP_VERSION is set to $APP_VERSION"
fi
fi


Expand Down

0 comments on commit 9cb15e5

Please sign in to comment.