Skip to content

Commit 5199d2a

Browse files
author
linyuan.yang
committed
release
1 parent afefac9 commit 5199d2a

1 file changed

Lines changed: 102 additions & 23 deletions

File tree

.github/workflows/release.yml

Lines changed: 102 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- platform: macos-latest
2121
args: '--target x86_64-apple-darwin'
2222
rust-target: x86_64-apple-darwin
23-
- platform: ubuntu-22.04
23+
- platform: ubuntu-24.04
2424
args: ''
2525
rust-target: ''
2626
- platform: windows-latest
@@ -61,7 +61,7 @@ jobs:
6161
${{ matrix.platform }}-cargo-
6262
6363
- name: Install Linux deps
64-
if: matrix.platform == 'ubuntu-22.04'
64+
if: startsWith(matrix.platform, 'ubuntu-')
6565
run: |
6666
sudo apt-get update
6767
sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev libpipewire-0.3-dev patchelf
@@ -100,8 +100,7 @@ jobs:
100100
releaseBody: ${{ steps.notes.outputs.body }}
101101
releaseDraft: true
102102
prerelease: false
103-
includeUpdaterJson: true
104-
updaterJsonPreferNsis: true
103+
includeUpdaterJson: false
105104
args: ${{ matrix.args }}
106105

107106
publish-manifest:
@@ -148,9 +147,9 @@ jobs:
148147
# run already created the draft, its body is stuck on whatever was there. Force it.
149148
gh release edit "$TAG" -R "$REPO" --notes "$BODY"
150149
151-
# 给桌面产物文件名加系统标识(tauri-action 上传时不含)。
150+
# 给桌面产物文件名加系统和架构标识(tauri-action 上传时不含)。
152151
# 此 job needs: release-desktop,所有桌面 matrix 已完成,不会再有旧名文件上传。
153-
# sed 不加 $ 行尾锚,.sig 后缀会自动保留;latest.json 不匹配规则,留待后续删除
152+
# sed 不加 $ 行尾锚,.tar.gz / .zip / .sig 后缀会自动保留
154153
- name: Rename desktop assets with OS tag
155154
env:
156155
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -175,32 +174,112 @@ jobs:
175174
fi
176175
done
177176
178-
- name: Sync updater manifest to updater channel
177+
- name: Generate updater manifest
179178
env:
180179
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
181180
REPO: ${{ github.repository }}
182181
TAG: ${{ steps.release.outputs.tag }}
183182
ASSET_VERSION: ${{ steps.release.outputs.version }}
184183
run: |
185-
if ! gh release download "$TAG" -R "$REPO" -p "latest.json" -O latest.json; then
186-
echo "::error::latest.json not found on release $TAG — no platform produced an updater manifest"
187-
exit 1
188-
fi
189-
# 上一步已重命名更新载荷文件,latest.json 里的 URL 需同步改写,否则更新器会 404。
190-
# latest.json 只含 app.tar.gz / setup.exe / AppImage 三类载荷 URL;base64 签名字段不含这些模式,g 全局替换安全。
191-
sed -i -E \
192-
-e "s#sbox_aarch64\.app\.tar\.gz#sbox_${ASSET_VERSION}_macos_arm64.app.tar.gz#g" \
193-
-e "s#sbox_x64\.app\.tar\.gz#sbox_${ASSET_VERSION}_macos_x64.app.tar.gz#g" \
194-
-e "s#sbox_[0-9][0-9.]*_x64-setup\.exe#sbox_${ASSET_VERSION}_windows_x64.exe#g" \
195-
-e "s#sbox_[0-9][0-9.]*_arm64-setup\.exe#sbox_${ASSET_VERSION}_windows_arm64.exe#g" \
196-
-e "s#sbox_[0-9][0-9.]*_amd64\.AppImage#sbox_${ASSET_VERSION}_linux_x64.AppImage#g" \
197-
-e "s#sbox_[0-9][0-9.]*_arm64\.AppImage#sbox_${ASSET_VERSION}_linux_arm64.AppImage#g" \
198-
latest.json
184+
set -euo pipefail
185+
gh api "/repos/$REPO/releases/tags/$TAG" > release.json
186+
rm -rf updater-signatures
187+
mkdir -p updater-signatures
188+
gh release download "$TAG" -R "$REPO" -p "*.sig" --dir updater-signatures --clobber
189+
node <<'NODE'
190+
const fs = require('node:fs');
191+
const path = require('node:path');
192+
193+
const version = process.env.ASSET_VERSION;
194+
const release = JSON.parse(fs.readFileSync('release.json', 'utf8'));
195+
const assets = new Map(release.assets.map((asset) => [asset.name, asset]));
196+
const platforms = {};
197+
const missing = [];
198+
199+
function changelogNotes() {
200+
const changelog = fs.readFileSync('CHANGELOG.md', 'utf8').split(/\r?\n/);
201+
const lines = [];
202+
let capture = false;
203+
for (const line of changelog) {
204+
const parts = line.trim().split(/\s+/);
205+
if (parts[0] === '##' && parts[1] === version) {
206+
capture = true;
207+
continue;
208+
}
209+
if (capture && parts[0] === '##') break;
210+
if (capture) lines.push(line);
211+
}
212+
const body = lines.join('\n').trim();
213+
return body || `Release ${version}`;
214+
}
215+
216+
function signatureFor(assetName) {
217+
const sigName = `${assetName}.sig`;
218+
if (!assets.has(sigName)) {
219+
throw new Error(`missing signature asset: ${sigName}`);
220+
}
221+
const sigPath = path.join('updater-signatures', sigName);
222+
if (!fs.existsSync(sigPath)) {
223+
throw new Error(`signature asset was not downloaded: ${sigName}`);
224+
}
225+
return fs.readFileSync(sigPath, 'utf8');
226+
}
227+
228+
function add(keys, candidates) {
229+
const asset = candidates.map((name) => assets.get(name)).find(Boolean);
230+
if (!asset) {
231+
missing.push(candidates.join(' or '));
232+
return;
233+
}
234+
const entry = {
235+
signature: signatureFor(asset.name),
236+
url: asset.browser_download_url,
237+
};
238+
for (const key of keys) {
239+
platforms[key] = entry;
240+
}
241+
}
242+
243+
add(['darwin-x86_64', 'darwin-x86_64-app'], [
244+
`sbox_${version}_macos_x64.app.tar.gz`,
245+
]);
246+
add(['darwin-aarch64', 'darwin-aarch64-app'], [
247+
`sbox_${version}_macos_arm64.app.tar.gz`,
248+
]);
249+
add(['windows-x86_64', 'windows-x86_64-nsis'], [
250+
`sbox_${version}_windows_x64.exe`,
251+
`sbox_${version}_windows_x64.exe.zip`,
252+
`sbox_${version}_windows_x64.nsis.zip`,
253+
]);
254+
add(['windows-aarch64', 'windows-aarch64-nsis'], [
255+
`sbox_${version}_windows_arm64.exe`,
256+
`sbox_${version}_windows_arm64.exe.zip`,
257+
`sbox_${version}_windows_arm64.nsis.zip`,
258+
]);
259+
add(['linux-x86_64', 'linux-x86_64-appimage'], [
260+
`sbox_${version}_linux_x64.AppImage.tar.gz`,
261+
`sbox_${version}_linux_x64.AppImage`,
262+
]);
263+
264+
if (missing.length > 0) {
265+
throw new Error(`missing updater payload asset(s): ${missing.join(', ')}`);
266+
}
267+
268+
fs.writeFileSync(
269+
'latest.json',
270+
`${JSON.stringify({
271+
version,
272+
notes: changelogNotes(),
273+
pub_date: new Date().toISOString(),
274+
platforms,
275+
}, null, 2)}\n`,
276+
);
277+
NODE
199278
gh release view updater -R "$REPO" >/dev/null 2>&1 || \
200279
gh release create updater -R "$REPO" \
201280
--title "Updater Manifests" \
202281
--notes "Auto-maintained by CI. Hosts the updater JSON for sbox." \
203282
--latest=false
204283
gh release upload updater latest.json -R "$REPO" --clobber
205-
# latest.json 只是中间产物,自动更新读的是固定 updater release 那份,从版本 release 删掉
206-
gh release delete-asset "$TAG" latest.json -R "$REPO" --yes
284+
# 自动更新读的是固定 updater release 那份;版本 release 若残留旧 latest.json,则删除
285+
gh release delete-asset "$TAG" latest.json -R "$REPO" --yes || true

0 commit comments

Comments
 (0)