-
Notifications
You must be signed in to change notification settings - Fork 1
248 lines (214 loc) · 8.29 KB
/
release.yml
File metadata and controls
248 lines (214 loc) · 8.29 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
244
245
246
247
248
name: Release Build
on:
workflow_dispatch:
inputs:
release_type:
description: 'Release type'
required: true
type: choice
options:
- stable
- prerelease
- development
default: 'stable'
permissions:
contents: write
jobs:
prepare_release:
name: Prepare Release
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
version: ${{ steps.version.outputs.version }}
upload_url: ${{ steps.create_release.outputs.upload_url }}
is_prerelease: ${{ steps.version.outputs.is_prerelease }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.14'
- name: Generate Version
id: version
run: python .github/scripts/generate_release_version.py --type ${{ github.event.inputs.release_type }}
- name: Update Version in Files
run: |
VERSION="${{ steps.version.outputs.version }}"
echo "Updating version to $VERSION"
# Update pyproject.toml
sed -i "s/version = \".*\"/version = \"$VERSION\"/" pyproject.toml
# Update __init__.py
sed -i "s/__version__ = \".*\"/__version__ = \"$VERSION\"/" src/switchcraft/__init__.py
# Update file_version_info.txt
python .github/scripts/update_version_info.py "$VERSION"
- name: Generate Changelog
id: changelog
run: |
python .github/scripts/generate_changelog.py --output changelog.md
# Read changelog content into a variable safely (multiline)
{
echo 'CHANGELOG_BODY<<EOF'
cat changelog.md
echo ""
echo 'EOF'
} >> "$GITHUB_ENV"
- name: Commit and Tag
run: |
VERSION="${{ steps.version.outputs.version }}"
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add pyproject.toml src/switchcraft/__init__.py file_version_info.txt
# Only commit if there are changes
if ! git diff --cached --quiet; then
echo "Changes detected, committing version bump..."
git commit -m "chore(release): bump version to $VERSION [skip ci]"
git push origin main
else
echo "No changes detected, version files are already up to date."
fi
# Always tag and push the tag
git tag "v$VERSION"
git push origin "v$VERSION"
- name: Create GitHub Release
id: create_release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.version.outputs.version }}
name: ${{ github.event.inputs.release_type == 'stable' && format('Release v{0}', steps.version.outputs.version) || github.event.inputs.release_type == 'prerelease' && format('Pre-release v{0}', steps.version.outputs.version) || format('Development Build v{0}', steps.version.outputs.version) }}
body: |

${{ env.CHANGELOG_BODY }}
draft: false
prerelease: ${{ github.event.inputs.release_type != 'stable' }}
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update Main Branch to Dev Version
if: ${{ github.event.inputs.release_type == 'stable' }}
run: |
VERSION="${{ steps.version.outputs.version }}"
# Calculate next dev version (increment patch and add -dev)
MAJOR=$(echo $VERSION | cut -d. -f1)
MINOR=$(echo $VERSION | cut -d. -f2)
PATCH=$(echo $VERSION | cut -d. -f3)
NEXT_PATCH=$((PATCH + 1))
DEV_VERSION="${MAJOR}.${MINOR}.${NEXT_PATCH}-dev"
echo "Setting development version to $DEV_VERSION"
# Update version files
sed -i "s/version = \".*\"/version = \"$DEV_VERSION\"/" pyproject.toml
sed -i "s/__version__ = \".*\"/__version__ = \"$DEV_VERSION\"/" src/switchcraft/__init__.py
python .github/scripts/update_version_info.py "$DEV_VERSION"
# Commit
git add pyproject.toml src/switchcraft/__init__.py file_version_info.txt
git commit -m "chore: bump version to $DEV_VERSION for development [skip ci]"
git push origin main
build:
name: Build Artifacts
needs: prepare_release
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: windows-latest
build_flags: "-All"
asset_path: "dist/SwitchCraft-windows.exe"
asset_name: "SwitchCraft-windows.exe"
- os: ubuntu-latest
build_flags: "-Modern"
asset_path: "dist/SwitchCraft-linux"
asset_name: "SwitchCraft-linux"
- os: macos-latest
build_flags: "-Modern"
asset_path: "dist/SwitchCraft"
asset_name: "SwitchCraft-macos"
steps:
- uses: actions/checkout@v6
with:
ref: v${{ needs.prepare_release.outputs.version }}
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.14'
# Cache PyInstaller
- uses: actions/cache@v5
with:
path: build
key: ${{ matrix.os }}-build-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
${{ matrix.os }}-build-
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install ".[modern,gui]"
pip install pyinstaller build
- name: Build with Script
run: |
# Call the unified build script
pwsh ./scripts/build_release.ps1 ${{ matrix.build_flags }}
env:
TERM: xterm
- name: Rename MacOS Artifact (if needed)
if: matrix.os == 'macos-latest'
run: |
# Script produces 'dist/SwitchCraft' on Mac.
# We might want to rename it to match asset_name expected
mv dist/SwitchCraft dist/${{ matrix.asset_name }} || true
shell: bash
# --- Windows Specific Signing & Uploads ---
- name: Decode Signing Certificate
if: matrix.os == 'windows-latest'
env:
SIGNING_CERT: ${{ secrets.SIGNING_CERT }}
run: |
if ($env:SIGNING_CERT) {
$certBytes = [System.Convert]::FromBase64String($env:SIGNING_CERT)
[System.IO.File]::WriteAllBytes("cert.pfx", $certBytes)
}
shell: pwsh
- name: Sign Windows Artifacts
if: matrix.os == 'windows-latest'
env:
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
run: |
if (Test-Path "cert.pfx") {
$signtool = Get-ChildItem -Path "C:\Program Files (x86)\Windows Kits" -Include signtool.exe -Recurse | Select-Object -Last 1
if ($signtool) {
# Sign everything executable in dist
Get-ChildItem dist\*.exe | ForEach-Object {
Write-Host "Signing $_..."
& $signtool.FullName sign /f "cert.pfx" /p "$env:SIGNING_PASSWORD" /tr http://timestamp.digicert.com /td sha256 /fd sha256 $_.FullName
}
}
}
shell: pwsh
- name: Upload Core Assets
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.prepare_release.outputs.version }}
files: |
dist/${{ matrix.asset_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload Windows Extras (Legacy, CLIs, Installers, Addons)
if: matrix.os == 'windows-latest'
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.prepare_release.outputs.version }}
files: |
dist/SwitchCraft-Legacy.exe
dist/SwitchCraft-CLI-windows.exe
dist/SwitchCraft-Setup.exe
dist/SwitchCraft-Legacy-Setup.exe
dist/*.zip
dist/*.whl
dist/*.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Cleanup Certificate
if: always() && matrix.os == 'windows-latest'
run: |
if (Test-Path "cert.pfx") { Remove-Item "cert.pfx" -Force }
shell: pwsh