|
1 | 1 | name: Build & Release |
2 | 2 |
|
3 | | -permissions: |
4 | | - contents: write |
5 | | - |
6 | 3 | on: |
7 | 4 | release: |
8 | 5 | types: [published] |
9 | 6 | workflow_dispatch: |
10 | 7 | inputs: |
11 | 8 | tag: |
| 9 | + description: 'Release tag (e.g., v1.2.3)' |
12 | 10 | required: true |
13 | 11 | type: string |
14 | 12 |
|
15 | | -jobs: |
16 | | - build-windows: |
17 | | - name: Build Windows x64 App |
18 | | - runs-on: windows-latest |
19 | | - steps: |
20 | | - - name: Checkout code |
21 | | - uses: actions/checkout@v5 |
22 | | - - name: Set up Python |
23 | | - uses: actions/setup-python@v6 |
24 | | - with: |
25 | | - python-version: '3.14' |
26 | | - - name: Install dependencies |
27 | | - run: | |
28 | | - python -m venv .venv |
29 | | - .venv\Scripts\activate |
30 | | - python -m pip install --upgrade pip |
31 | | - pip install pyinstaller |
32 | | - pip install -r requirements.txt |
33 | | - - name: Build app with PyInstaller |
34 | | - run: | |
35 | | - .venv\Scripts\pyinstaller ./tchMaterial-parser.spec |
36 | | - cd dist |
37 | | - mv tchMaterial-parser.exe tchMaterial-parser-windows-x64.exe |
38 | | - - name: Upload Release Asset |
39 | | - uses: softprops/action-gh-release@v2 |
40 | | - with: |
41 | | - files: dist/tchMaterial-parser-windows-x64.exe |
42 | | - tag_name: ${{ inputs.tag || github.ref_name }} |
43 | | - env: |
44 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 13 | +permissions: |
| 14 | + contents: read |
45 | 15 |
|
| 16 | +concurrency: |
| 17 | + group: release-${{ inputs.tag || github.ref_name }} |
| 18 | + cancel-in-progress: false |
| 19 | + |
| 20 | +env: |
| 21 | + PYTHON_VERSION: '3.14' |
| 22 | + SPEC_PATH: 'tchMaterial-parser.spec' |
| 23 | + DIST_DIR: 'dist' |
| 24 | + |
| 25 | +jobs: |
46 | 26 | build-linux: |
47 | | - name: Build Linux x64 App |
48 | | - runs-on: ubuntu-latest |
| 27 | + name: Build (Linux) |
| 28 | + runs-on: ${{ matrix.runs_on }} |
| 29 | + strategy: |
| 30 | + fail-fast: false |
| 31 | + matrix: |
| 32 | + include: |
| 33 | + - runs_on: ubuntu-latest |
| 34 | + artifact_name: tchMaterial-parser-linux-x64 |
| 35 | + - runs_on: ubuntu-24.04-arm |
| 36 | + artifact_name: tchMaterial-parser-linux-arm64 |
| 37 | + defaults: |
| 38 | + run: |
| 39 | + shell: bash |
49 | 40 | steps: |
50 | 41 | - name: Checkout code |
51 | 42 | uses: actions/checkout@v5 |
| 43 | + |
52 | 44 | - name: Set up Python |
53 | 45 | uses: actions/setup-python@v6 |
54 | 46 | with: |
55 | | - python-version: '3.14' |
| 47 | + python-version: ${{ env.PYTHON_VERSION }} |
| 48 | + cache: pip |
| 49 | + cache-dependency-path: requirements.txt |
| 50 | + |
| 51 | + - name: Create virtual environment |
| 52 | + run: python -m venv .venv |
| 53 | + |
56 | 54 | - name: Install dependencies |
57 | 55 | run: | |
58 | | - python -m venv .venv |
59 | | - source .venv/bin/activate |
60 | | - python -m pip install --upgrade pip |
61 | | - pip install pyinstaller |
62 | | - pip install -r requirements.txt |
63 | | - - name: Build app with PyInstaller |
| 56 | + ./.venv/bin/python -m pip install --upgrade pip |
| 57 | + ./.venv/bin/python -m pip install pyinstaller -r requirements.txt |
| 58 | +
|
| 59 | + - name: Build app |
64 | 60 | run: | |
65 | | - .venv/bin/pyinstaller ./tchMaterial-parser.spec |
66 | | - cd dist |
67 | | - mv tchMaterial-parser tchMaterial-parser-linux-x64 |
68 | | - - name: Upload Release Asset |
69 | | - uses: softprops/action-gh-release@v2 |
| 61 | + ./.venv/bin/python -m PyInstaller ${{ env.SPEC_PATH }} |
| 62 | + mv "${{ env.DIST_DIR }}/tchMaterial-parser" "${{ env.DIST_DIR }}/${{ matrix.artifact_name }}" |
| 63 | +
|
| 64 | + - name: Upload artifact |
| 65 | + uses: actions/upload-artifact@v4 |
70 | 66 | with: |
71 | | - files: dist/tchMaterial-parser-linux-x64 |
72 | | - tag_name: ${{ inputs.tag || github.ref_name }} |
73 | | - env: |
74 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 67 | + name: ${{ matrix.artifact_name }} |
| 68 | + path: ${{ env.DIST_DIR }}/${{ matrix.artifact_name }} |
| 69 | + if-no-files-found: error |
75 | 70 |
|
76 | | - build-linux-arm64: |
77 | | - name: Build Linux ARM64 App |
78 | | - runs-on: ubuntu-24.04-arm |
| 71 | + build-windows: |
| 72 | + name: Build (Windows) |
| 73 | + runs-on: windows-latest |
| 74 | + defaults: |
| 75 | + run: |
| 76 | + shell: pwsh |
79 | 77 | steps: |
80 | 78 | - name: Checkout code |
81 | 79 | uses: actions/checkout@v5 |
| 80 | + |
82 | 81 | - name: Set up Python |
83 | 82 | uses: actions/setup-python@v6 |
84 | 83 | with: |
85 | | - python-version: '3.14' |
| 84 | + python-version: ${{ env.PYTHON_VERSION }} |
| 85 | + cache: pip |
| 86 | + cache-dependency-path: requirements.txt |
| 87 | + |
| 88 | + - name: Create virtual environment |
| 89 | + run: python -m venv .venv |
| 90 | + |
86 | 91 | - name: Install dependencies |
87 | 92 | run: | |
88 | | - python -m venv .venv |
89 | | - source .venv/bin/activate |
90 | | - python -m pip install --upgrade pip |
91 | | - pip install pyinstaller |
92 | | - pip install -r requirements.txt |
93 | | - - name: Build app with PyInstaller |
| 93 | + .\.venv\Scripts\python -m pip install --upgrade pip |
| 94 | + .\.venv\Scripts\python -m pip install pyinstaller -r requirements.txt |
| 95 | +
|
| 96 | + - name: Build app |
94 | 97 | run: | |
95 | | - .venv/bin/pyinstaller ./tchMaterial-parser.spec |
96 | | - cd dist |
97 | | - mv tchMaterial-parser tchMaterial-parser-linux-arm64 |
98 | | - - name: Upload Release Asset |
99 | | - uses: softprops/action-gh-release@v2 |
| 98 | + .\.venv\Scripts\python -m PyInstaller $env:SPEC_PATH |
| 99 | + Move-Item "$env:DIST_DIR\\tchMaterial-parser.exe" "$env:DIST_DIR\\tchMaterial-parser-windows-x64.exe" |
| 100 | +
|
| 101 | + - name: Upload artifact |
| 102 | + uses: actions/upload-artifact@v4 |
100 | 103 | with: |
101 | | - files: dist/tchMaterial-parser-linux-arm64 |
102 | | - tag_name: ${{ inputs.tag || github.ref_name }} |
103 | | - env: |
104 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 104 | + name: tchMaterial-parser-windows-x64.exe |
| 105 | + path: ${{ env.DIST_DIR }}/tchMaterial-parser-windows-x64.exe |
| 106 | + if-no-files-found: error |
105 | 107 |
|
106 | 108 | build-macos: |
107 | | - name: Build macOS ARM64 App |
| 109 | + name: Build (macOS ARM64) |
108 | 110 | runs-on: macos-latest |
| 111 | + defaults: |
| 112 | + run: |
| 113 | + shell: bash |
109 | 114 | steps: |
110 | 115 | - name: Checkout code |
111 | 116 | uses: actions/checkout@v5 |
112 | | - |
| 117 | + |
113 | 118 | - name: Set up Python |
114 | 119 | uses: actions/setup-python@v6 |
115 | 120 | with: |
116 | | - python-version: '3.12' # 推荐使用 3.12 稳定版 |
117 | | - |
| 121 | + python-version: ${{ env.PYTHON_VERSION }} |
| 122 | + cache: pip |
| 123 | + cache-dependency-path: requirements.txt |
| 124 | + |
| 125 | + - name: Create virtual environment |
| 126 | + run: python -m venv .venv |
| 127 | + |
118 | 128 | - name: Install dependencies |
119 | 129 | run: | |
120 | | - python -m venv .venv |
121 | | - source .venv/bin/activate |
122 | | - python -m pip install --upgrade pip |
123 | | - pip install pyinstaller |
124 | | - pip install -r requirements.txt |
125 | | - |
126 | | - - name: Build app with PyInstaller |
127 | | - run: | |
128 | | - # 激活虚拟环境 |
129 | | - source .venv/bin/activate |
130 | | - |
131 | | - # 执行打包命令 |
132 | | - # --clean: 清理缓存 |
133 | | - # --onefile: 强制生成单文件 |
134 | | - # --name: 指定输出文件名 |
135 | | - # --add-data: 打包资源文件 (格式为 源路径:目标路径) |
136 | | - # src/tchMaterial-parser.pyw: 你的入口脚本 |
137 | | - |
138 | | - pyinstaller --clean --onefile --name tchMaterial-parser \ |
139 | | - --add-data "res:res" \ |
140 | | - --add-data "version.txt:." \ |
141 | | - src/tchMaterial-parser.pyw |
142 | | -
|
143 | | - - name: Sign the binary |
144 | | - run: | |
145 | | - # 对生成的单文件进行 Ad-hoc 签名 |
146 | | - # 这一步是解决“文件已损坏”的核心 |
147 | | - codesign --force --deep --sign - dist/tchMaterial-parser |
| 130 | + ./.venv/bin/python -m pip install --upgrade pip |
| 131 | + ./.venv/bin/python -m pip install pyinstaller -r requirements.txt |
| 132 | +
|
| 133 | + - name: Build app |
| 134 | + run: ./.venv/bin/python -m PyInstaller ${{ env.SPEC_PATH }} |
| 135 | + |
| 136 | + - name: Ad-hoc sign app bundle |
| 137 | + run: codesign --force --deep --sign - "${{ env.DIST_DIR }}/tchMaterial-parser.app" |
148 | 138 |
|
149 | 139 | - name: Create zip archive |
150 | 140 | run: | |
151 | | - cd dist |
152 | | - # 改名为带架构后缀的文件名 |
153 | | - mv tchMaterial-parser tchMaterial-parser-mac-arm64 |
154 | | - |
155 | | - # 赋予可执行权限(双重保险) |
156 | | - chmod +x tchMaterial-parser-mac-arm64 |
157 | | - |
158 | | - # 压缩为 zip |
159 | | - zip -r tchMaterial-parser-mac-arm64.zip tchMaterial-parser-mac-arm64 |
160 | | -
|
161 | | - - name: Upload Release Asset |
| 141 | + cd "${{ env.DIST_DIR }}" |
| 142 | + zip -r "tchMaterial-parser-mac-arm64.zip" "tchMaterial-parser.app" |
| 143 | +
|
| 144 | + - name: Upload artifact |
| 145 | + uses: actions/upload-artifact@v4 |
| 146 | + with: |
| 147 | + name: tchMaterial-parser-mac-arm64.zip |
| 148 | + path: ${{ env.DIST_DIR }}/tchMaterial-parser-mac-arm64.zip |
| 149 | + if-no-files-found: error |
| 150 | + |
| 151 | + release: |
| 152 | + name: Publish release |
| 153 | + runs-on: ubuntu-latest |
| 154 | + needs: |
| 155 | + - build-linux |
| 156 | + - build-windows |
| 157 | + - build-macos |
| 158 | + permissions: |
| 159 | + contents: write |
| 160 | + steps: |
| 161 | + - name: Download artifacts |
| 162 | + uses: actions/download-artifact@v4 |
| 163 | + with: |
| 164 | + path: dist |
| 165 | + merge-multiple: true |
| 166 | + |
| 167 | + - name: Upload release assets |
162 | 168 | uses: softprops/action-gh-release@v2 |
163 | 169 | with: |
164 | | - files: dist/tchMaterial-parser-mac-arm64.zip |
| 170 | + files: | |
| 171 | + dist/tchMaterial-parser-windows-x64.exe |
| 172 | + dist/tchMaterial-parser-linux-x64 |
| 173 | + dist/tchMaterial-parser-linux-arm64 |
| 174 | + dist/tchMaterial-parser-mac-arm64.zip |
165 | 175 | tag_name: ${{ inputs.tag || github.ref_name }} |
166 | | - env: |
167 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
168 | | - |
|
0 commit comments