-
Notifications
You must be signed in to change notification settings - Fork 3
179 lines (156 loc) · 6.24 KB
/
Copy pathbuild-exe-release.yml
File metadata and controls
179 lines (156 loc) · 6.24 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
name: Build Backend EXE and Release
on:
push:
branches:
- main
tags:
- 'v*.*.*'
workflow_dispatch:
permissions:
contents: write
jobs:
build-and-release:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Resolve release tag and message
id: version
shell: pwsh
run: |
git fetch --tags --force
$latestMsg = git log -1 --pretty=%B | Out-String
$latestMsg = $latestMsg.TrimEnd()
if (-not $latestMsg) {
$latestMsg = "No commit message"
}
$releaseBody = "HKLHaoBin`n$latestMsg"
if ("${{ github.ref_type }}" -eq "tag") {
$tag = "${{ github.ref_name }}"
Write-Host "Tag trigger detected, use existing tag: $tag"
} else {
$tags = git tag --list "v*.*.*"
$versionTags = @()
foreach ($t in $tags) {
if ($t -match '^v(\d+)\.(\d+)\.(\d+)$') {
$versionTags += [PSCustomObject]@{
Tag = $t
Major = [int]$matches[1]
Minor = [int]$matches[2]
Patch = [int]$matches[3]
}
}
}
if ($versionTags.Count -eq 0) {
$tag = "v1.0.0"
} else {
$latest = $versionTags |
Sort-Object -Property @{Expression = 'Major'; Descending = $true}, @{Expression = 'Minor'; Descending = $true}, @{Expression = 'Patch'; Descending = $true} |
Select-Object -First 1
if ($latest.Minor -ge 9) {
$tag = "v$($latest.Major + 1).0.0"
} else {
$nextMinor = $latest.Minor + 1
$tag = "v$($latest.Major).$nextMinor.0"
}
}
Write-Host "Create and push new tag: $tag"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag $tag
git push origin $tag
}
"tag=$tag" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
$delimiter = [guid]::NewGuid().ToString()
"release_body<<$delimiter" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
$releaseBody | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
$delimiter | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
- name: Inject version into backend.py and updater.py
shell: pwsh
run: |
$version = "${{ steps.version.outputs.tag }}".TrimStart('v')
$placeholder = 'APP_VERSION = "0.0.0-dev"'
$newLine = "APP_VERSION = ""$version"""
foreach ($target in @('.\backend.py', '.\updater.py')) {
$content = Get-Content $target -Raw
if (-not $content.Contains($placeholder)) {
Write-Error "Placeholder for version not found in $target"
exit 1
}
$content = $content.Replace($placeholder, $newLine)
Set-Content -Path $target -Value $content -Encoding UTF8
}
- name: Verify injected version in backend.py and updater.py
shell: pwsh
run: |
$version = "${{ steps.version.outputs.tag }}".TrimStart('v')
foreach ($target in @('.\backend.py', '.\updater.py')) {
$matches = Select-String -Path $target -Pattern '^APP_VERSION = "([^"]+)"' -AllMatches
if ($matches.Count -ne 1) {
Write-Error "Expected exactly one APP_VERSION assignment in $target, found $($matches.Count)"
exit 1
}
$value = $matches[0].Matches[0].Groups[1].Value
if ($value -ne $version) {
Write-Error "Injected version mismatch in $target. Expected $version, found $value"
exit 1
}
}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-backend.txt
pip install pyinstaller
- name: Build backend.exe
shell: pwsh
run: |
pyinstaller --noconfirm backend.spec
- name: Build updater.exe
shell: pwsh
run: |
pyinstaller --noconfirm --onefile --console ".\updater.py"
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: backend-and-updater.exe
path: |
dist/backend.exe
dist/updater.exe
if-no-files-found: error
- name: Prepare release zip
shell: pwsh
run: |
New-Item -ItemType Directory -Path release -Force | Out-Null
New-Item -ItemType Directory -Path release/LyricSphere.exe -Force | Out-Null
Copy-Item dist/backend.exe release/LyricSphere.exe/backend.exe -Force
Copy-Item dist/updater.exe release/LyricSphere.exe/updater.exe -Force
Copy-Item templates release/LyricSphere.exe/templates -Recurse -Force
$staticDest = "release/LyricSphere.exe/static"
New-Item -ItemType Directory -Path $staticDest -Force | Out-Null
foreach ($dir in @('assets','public','icons','monaco')) {
if (Test-Path "static/$dir") {
Copy-Item "static/$dir" "$staticDest/$dir" -Recurse -Force
}
}
if (Test-Path LyricSphere.exe.zip) {
Remove-Item LyricSphere.exe.zip -Force
}
Compress-Archive -Path release/LyricSphere.exe/* -DestinationPath LyricSphere.exe.zip -Force
$hash = Get-FileHash -Algorithm SHA256 -Path LyricSphere.exe.zip
$hash.Hash | Out-File -FilePath LyricSphere.exe.zip.sha256 -Encoding ascii
- name: Upload release asset
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.tag }}
name: LyricSphere.exe
body: ${{ steps.version.outputs.release_body }}
files: |
LyricSphere.exe.zip
LyricSphere.exe.zip.sha256
fail_on_unmatched_files: true