-
Notifications
You must be signed in to change notification settings - Fork 0
250 lines (213 loc) · 8.29 KB
/
Copy pathrelease.yml
File metadata and controls
250 lines (213 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
249
250
name: Build & Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
tag:
description: '要构建的 Tag(如 v0.2.0)'
required: true
type: string
permissions: {}
concurrency:
group: release-${{ github.event.inputs.tag || github.ref_name }}
cancel-in-progress: false
jobs:
# ===== Stage 1: 三平台并行构建 =====
build:
runs-on: ${{ matrix.os }}
permissions:
contents: read
strategy:
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]
env:
RELEASE_TAG: ${{ github.event.inputs.tag || github.ref_name }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ env.RELEASE_TAG }}
- uses: actions/setup-node@v4
with:
node-version: '22'
- name: Install dependencies
run: npm install
- name: Build Vite
run: npm run build
- name: Package Electron
env:
CSC_IDENTITY_AUTO_DISCOVERY: 'false'
run: npx electron-builder --config electron-builder.yml --publish never
- name: Prepare artifacts (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
New-Item -ItemType Directory -Force artifacts-upload | Out-Null
Copy-Item release\*.exe artifacts-upload\ -ErrorAction SilentlyContinue
Set-Location artifacts-upload
$files = Get-ChildItem -File -Exclude SHA256SUMS | Select-Object -ExpandProperty Name
foreach ($f in $files) {
$hash = (Get-FileHash -Algorithm SHA256 $f).Hash.ToLower()
"$hash $f" | Out-File -Encoding ASCII -Append SHA256SUMS
}
Write-Output "=== Prepared artifacts ==="
Get-ChildItem | Select-Object Name, Length
- name: Prepare artifacts (Unix)
if: matrix.os != 'windows-latest'
shell: bash
run: |
mkdir -p artifacts-upload
cp release/*.exe release/*.dmg release/*.AppImage release/*.deb artifacts-upload/ 2>/dev/null || true
cd artifacts-upload
shopt -s nullglob
for f in *; do
[ "$f" = "SHA256SUMS" ] && continue
sha256sum "$f"
done > SHA256SUMS
echo "=== Prepared artifacts ==="
ls -la
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: binaries-${{ matrix.os }}
path: artifacts-upload/*
if-no-files-found: error
retention-days: 14
# ===== Stage 2: 创建并发布 Release =====
release:
runs-on: ubuntu-latest
needs: build
permissions:
actions: read
contents: write
env:
RELEASE_TAG: ${{ github.event.inputs.tag || github.ref_name }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
path: release-assets
merge-multiple: true
- name: Verify artifacts
run: |
echo "=== Downloaded artifacts ==="
ls -la release-assets/
echo
# Validate each platform
find release-assets/ -maxdepth 1 -name "*.exe" | grep -q . && echo "✓ Windows" || echo "✗ Windows MISSING"
find release-assets/ -maxdepth 1 -name "*.dmg" | grep -q . && echo "✓ macOS" || echo "✗ macOS MISSING"
find release-assets/ -maxdepth 1 \( -name "*.AppImage" -o -name "*.deb" \) | grep -q . && echo "✓ Linux" || echo "✗ Linux MISSING"
- name: Create and publish Release
run: |
set -euo pipefail
VERSION="${RELEASE_TAG#v}"
# Collect binary filenames
cd release-assets
BINARIES=(*)
echo "Binaries to upload: ${BINARIES[*]}"
# Build release notes
cat > /tmp/notes.md << NOTES
## SunCode ${RELEASE_TAG}
### 文件
| 文件 | SHA256 |
|------|--------|
NOTES
while read -r hash name; do
echo "| ${name} | \`${hash}\` |" >> /tmp/notes.md
done < SHA256SUMS 2>/dev/null || true
cat >> /tmp/notes.md << NOTES
### 安装
- **Windows**: 下载 \`.exe\` 安装程序或便携版
- **macOS**: 下载 \`.dmg\` 拖入 Applications
- **Linux**: 下载 \`.AppImage\` 并 \`chmod +x\`,或 \`.deb\` 用 \`sudo dpkg -i\` 安装
> 未签名应用,Windows 可能提示 SmartScreen,macOS 需右键打开。
NOTES
cat /tmp/notes.md
# Remove any existing draft for this tag
IS_DRAFT=$(gh release view "${RELEASE_TAG}" --json isDraft --jq .isDraft 2>/dev/null || echo "")
if [ "${IS_DRAFT}" == "true" ]; then
echo "Removing existing draft..."
gh release delete "${RELEASE_TAG}" --yes
fi
if [ "${IS_DRAFT}" == "false" ]; then
echo "::error::Release ${RELEASE_TAG} already published"
exit 1
fi
# Create release directly (not draft — just ship it)
gh release create "${RELEASE_TAG}" \
--title "SunCode ${RELEASE_TAG}" \
--notes-file /tmp/notes.md \
"${BINARIES[@]}"
echo "::notice::✅ Release ${RELEASE_TAG} 发布成功"
- name: Generate and upload update metadata
run: |
set -euo pipefail
VERSION="${RELEASE_TAG#v}"
RELEASE_DATE=$(date -u +%Y-%m-%dT%H:%M:%S.000Z)
cd release-assets
# ── Windows NSIS: latest.yml ──
# Match the NSIS installer specifically (artifactName: SunCode-Setup-${version}.${ext}).
# Do NOT pick the portable build — its filename has a space that GitHub mangles to a dot,
# and portable builds are not used for auto-update anyway.
NSIS_EXE=$(ls *-Setup-*.exe 2>/dev/null | head -1 || echo "")
if [ -z "$NSIS_EXE" ]; then
echo "::warning::No NSIS installer found (expected *-Setup-*.exe); skipping latest.yml"
fi
if [ -n "$NSIS_EXE" ]; then
SIZE=$(stat -c%s "$NSIS_EXE" 2>/dev/null || stat -f%z "$NSIS_EXE")
SHA512=$(sha512sum "$NSIS_EXE" | awk '{print $1}')
{
echo "version: ${VERSION}"
echo "files:"
echo " - url: ${NSIS_EXE}"
echo " sha512: ${SHA512}"
echo " size: ${SIZE}"
echo "path: ${NSIS_EXE}"
echo "sha512: ${SHA512}"
echo "releaseDate: ${RELEASE_DATE}"
} > latest.yml
echo "=== latest.yml ==="
cat latest.yml
gh release upload "${RELEASE_TAG}" latest.yml --clobber
fi
# ── Linux AppImage: latest-linux.yml ──
APPIMAGE=$(ls *.AppImage 2>/dev/null | head -1 || echo "")
if [ -n "$APPIMAGE" ]; then
SIZE=$(stat -c%s "$APPIMAGE" 2>/dev/null || stat -f%z "$APPIMAGE")
SHA512=$(sha512sum "$APPIMAGE" | awk '{print $1}')
{
echo "version: ${VERSION}"
echo "files:"
echo " - url: ${APPIMAGE}"
echo " sha512: ${SHA512}"
echo " size: ${SIZE}"
echo "path: ${APPIMAGE}"
echo "sha512: ${SHA512}"
echo "releaseDate: ${RELEASE_DATE}"
} > latest-linux.yml
echo "=== latest-linux.yml ==="
cat latest-linux.yml
gh release upload "${RELEASE_TAG}" latest-linux.yml --clobber
fi
# ── macOS DMG: latest-mac.yml ──
DMG=$(ls *.dmg 2>/dev/null | head -1 || echo "")
if [ -n "$DMG" ]; then
SIZE=$(stat -c%s "$DMG" 2>/dev/null || stat -f%z "$DMG")
SHA512=$(sha512sum "$DMG" | awk '{print $1}')
{
echo "version: ${VERSION}"
echo "files:"
echo " - url: ${DMG}"
echo " sha512: ${SHA512}"
echo " size: ${SIZE}"
echo "path: ${DMG}"
echo "sha512: ${SHA512}"
echo "releaseDate: ${RELEASE_DATE}"
} > latest-mac.yml
echo "=== latest-mac.yml ==="
cat latest-mac.yml
gh release upload "${RELEASE_TAG}" latest-mac.yml --clobber
fi
echo "::notice::✅ Update metadata uploaded"