-
Notifications
You must be signed in to change notification settings - Fork 256
140 lines (122 loc) · 4.36 KB
/
release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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-') }}