-
Notifications
You must be signed in to change notification settings - Fork 6
243 lines (206 loc) · 9.28 KB
/
dev_package_and_upload.yml
File metadata and controls
243 lines (206 loc) · 9.28 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
name: Nuitka Package and Upload(dev)
on:
workflow_dispatch:
inputs:
run:
description: '运行 build.py'
required: true
default: 'true'
type: choice
options:
- 'true'
- 'false'
test:
description: '测试'
required: true
default: 'true'
type: choice
options:
- 'true'
- 'false'
config_path:
description: '测试模式时用的配置文件路径(非测试时请忽略)'
required: true
type: string
default: 'package/nuitka_test_config.yml'
# push:
# branches:
# - dev
# paths:
# - 'package/nuitka_config.yml'
jobs:
package-and-upload:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest,ubuntu-24.04-arm,windows-latest] # windows-11-arm没有对应的 Python
env:
PYTHON_VERSION: '3.10'
NUITKA_CACHE_DIR: ${{ github.workspace }}/nuitka-cache
UPXVERSION: '5.0.1'
# 添加必要的权限
permissions:
contents: write # 允许创建发布和上传资源
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set Timezone to China Standard Time on Windows
if: ${{ runner.os == 'Windows' }}
run: tzutil /s "China Standard Time"
shell: pwsh
- name: Set Timezone to China Standard Time on Linux
if: ${{ runner.os == 'Linux' }}
run: sudo timedatectl set-timezone Asia/Shanghai
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Cache UPX
id: cache-upx
uses: actions/cache@v4
with:
path: upx
key: ${{ runner.os }}-${{ runner.arch }}-upx-v${{ env.UPXVERSION }}
restore-keys: |
${{ runner.os }}-${{ runner.arch }}-upx-
- name: Create UPX directory
if: ${{ steps.cache-upx.outputs.cache-hit != 'true' }}
run: mkdir -p ./upx
- name: Install UPX on Linux
if: ${{ runner.os == 'Linux' && steps.cache-upx.outputs.cache-hit != 'true' }}
run: |
UPX_URL="https://github.com/upx/upx/releases/download/v${{ env.UPXVERSION }}/upx-${{ env.UPXVERSION }}-${{ runner.arch == 'X64' && 'amd64' || 'arm64' }}_linux.tar.xz"
curl -L "$UPX_URL" -o upx.tar.xz
tar -xf upx.tar.xz -C ./upx --strip-components=1
chmod +x ./upx/upx
shell: bash
- name: Install UPX on Windows
if: ${{ runner.os == 'Windows' && steps.cache-upx.outputs.cache-hit != 'true' }}
run: |
$arch = if (("${{ runner.arch }}" -eq "amd64") -or ("${{ runner.arch }}" -eq "X64")) { "win64" } else { "win32" }
$upxVersion = "${{ env.UPXVERSION }}"
$upxUrl = "https://github.com/upx/upx/releases/download/v$upxVersion/upx-$upxVersion-$arch.zip"
Invoke-WebRequest -Uri $upxUrl -OutFile upx.zip
Expand-Archive -Path upx.zip -DestinationPath ./upx -Force
# Windows 版本的 UPX 解压后在子目录中,需要移动到根目录
Move-Item -Path "./upx/upx-$upxVersion-$arch/*" -Destination ./upx -Force
shell: pwsh
- name: Verify UPX installation
run: |
./upx/upx --version
shell: bash
- name: get pip cache dir on Windows
if: ${{ runner.os == 'Windows' }}
id: pip-cache-dir-window
run: echo "pip-cache-dir=$(pip cache dir)" >> $env:GITHUB_OUTPUT
- name: get pip cache dir on Linux
if: ${{ runner.os == 'Linux' }}
id: pip-cache-dir-linux
run: echo "pip-cache-dir=$(pip cache dir)" >> $GITHUB_OUTPUT
- name: pip cache
uses: actions/cache@v4
with:
path: ${{ runner.os == 'Windows' && steps.pip-cache-dir-window.outputs.pip-cache-dir || steps.pip-cache-dir-linux.outputs.pip-cache-dir }}
key: ${{ runner.os }}-${{ runner.arch }}-pip-${{ github.event.inputs.test && hashFiles(github.event.inputs.config_path) || hashFiles('package/nuitka_build.py') }}
restore-keys: |
${{ runner.os }}-${{ runner.arch }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install nuitka pyyaml ordered-set==4.1.0 wheel==0.38.4 zstandard==0.20.0
# - name: insatll mingw
# run: |
# mkdir C:\Users\%username%\AppData\Local\Nuitka\Nuitka\Cache\downloads\gcc\x86_64\14.2.0posix-19.1.1-12.0.0-msvcrt-r2
# curl -o C:\Users\%username%\AppData\Local\Nuitka\Nuitka\Cache\downloads\gcc\x86_64\14.2.0posix-19.1.1-12.0.0-msvcrt-r2\winlibs-x86_64-posix-seh-gcc-14.2.0-llvm-19.1.1-mingw-w64msvcrt-12.0.0-r2.zip https://github.com/brechtsanders/winlibs_mingw/releases/download/14.2.0posix-19.1.1-12.0.0-msvcrt-r2/winlibs-x86_64-posix-seh-gcc-14.2.0-llvm-19.1.1-mingw-w64msvcrt-12.0.0-r2.zip
# tar -xf C:\Users\%username%\AppData\Local\Nuitka\Nuitka\Cache\downloads\gcc\x86_64\14.2.0posix-19.1.1-12.0.0-msvcrt-r2\winlibs-x86_64-posix-seh-gcc-14.2.0-llvm-19.1.1-mingw-w64msvcrt-12.0.0-r2.zip -C C:\Users\%username%\AppData\Local\Nuitka\Nuitka\Cache\downloads\gcc\x86_64\14.2.0posix-19.1.1-12.0.0-msvcrt-r2\
# - name: Fix Python encoding (Windows)
# run: |
# # 设置Python使用UTF-8编码
# [System.Environment]::SetEnvironmentVariable('PYTHONUTF8', '1', 'Process')
# # 设置控制台编码为UTF-8
# chcp.com 65001
- name: Install dependencies on Linux
if: ${{ runner.os == 'Linux' }}
run: |
sudo apt-get update -y
sudo apt-get install -y ccache
echo 'export PATH="/usr/lib/ccache:$PATH"' >> ~/.bashrc
source ~/.bashrc
sudo apt-get install -y patchelf
- name: Cache Nuitka cache directory
uses: actions/cache@v4
with:
path: ${{ env.NUITKA_CACHE_DIR }}
key: nuitka-${{ runner.os }}-${{ runner.arch }}-python-${{ env.PYTHON_VERSION }}-nuitka-${{ github.event.inputs.test && hashFiles(github.event.inputs.config_path) || hashFiles('package/nuitka_build.py') }}
restore-keys: |
nuitka-${{ runner.os }}-${{ runner.arch }}-python-${{ env.PYTHON_VERSION }}-
nuitka-${{ runner.os }}-${{ runner.arch }}-
- name: Run packaging script on Windows
if: ${{ github.event.inputs.run == 'true' && github.event.inputs.test == 'false' && runner.os == 'Windows' }}
run: |
# 设置Python使用UTF-8编码
[System.Environment]::SetEnvironmentVariable('PYTHONUTF8', '1', 'Process')
# 设置控制台编码为UTF-8
chcp.com 65001
python ./package/nuitka_build.py ./package/nuitka_config.yml
- name: Run Test packaging script on Windows
if: ${{ github.event.inputs.run == 'true' && github.event.inputs.test == 'true' && runner.os == 'Windows' }}
run: |
# 设置Python使用UTF-8编码
[System.Environment]::SetEnvironmentVariable('PYTHONUTF8', '1', 'Process')
# 设置控制台编码为UTF-8
chcp.com 65001
python ./package/nuitka_build.py ${{ github.event.inputs.config_path }}
- name: Run packaging script on Linux
if: ${{ github.event.inputs.run == 'true' && github.event.inputs.test == 'false' && runner.os == 'Linux' }}
run: |
python ./package/nuitka_build.py ./package/nuitka_config.yml
- name: Run Test packaging script on Linux
if: ${{ github.event.inputs.run == 'true' && github.event.inputs.test == 'true' && runner.os == 'Linux' }}
run: |
python ./package/nuitka_build.py ${{ github.event.inputs.config_path }}
# 按理说不用检测 Release 是否已经发布,运行
- name: Check if Release exists
id: check_release
uses: actions/github-script@v6
with:
script: |
const tagName = process.env.TAG_NAME;
try {
const response = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: tagName
});
const releaseId = response.data.id;
console.log(`Release '${tagName}' already exists with ID: ${releaseId}`);
core.setOutput('exists', 'true');
core.setOutput('release_id', releaseId);
} catch (error) {
if (error.status === 404) {
console.log(`Release '${tagName}' does not exist`);
core.setOutput('exists', 'false');
core.setOutput('release_id', '');
} else {
core.setFailed(`Failed to check release: ${error.message}`);
throw error;
}
}
env:
TAG_NAME: 'v25.07.08'
- name: Use Release ID
if: ${{ steps.check_release.outputs.exists == 'true' }}
run: |
echo "Existing Release ID: ${{ steps.check_release.outputs.release_id }}"
# 这里可以使用 release_id 进行更新操作
# 例如:gh release upload ${{ steps.check_release.outputs.release_id }} dist/*
- name: Upload files with wildcards
if: ${{ github.event.inputs.run == 'true' }}
uses: actions/upload-artifact@v4
with:
name: ${{ runner.os }}-${{ runner.arch }}-${{ github.event.inputs.test && 'test-' || 'beta-' }}artifact
path: |
./dist/*
retention-days: 14
if-no-files-found: warn
overwrite: true