mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-24 11:01:17 -08:00
ci(tauri): add nightly auto updating
This commit is contained in:
1 parent
0742666c75
commit
2b2d0d1681
6 files changed
+130
-52
No files matched your search
@@ -1,6 +1,6 @@
|
||||
// Composes the Tauri updater manifest (latest.json) from the per-platform .sig
|
||||
// assets already attached to the release.
|
||||
// Required env: TAG, REPO, GH_TOKEN.
|
||||
// Required env: TAG, VERSION, REPO, GH_TOKEN.
|
||||
|
||||
import { execSync } from 'node:child_process';
|
||||
import { readFileSync, readdirSync, writeFileSync, mkdtempSync } from 'node:fs';
|
||||
@@ -8,12 +8,17 @@ import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
|
||||
const TAG = process.env.TAG;
|
||||
const VERSION = process.env.VERSION;
|
||||
const REPO = process.env.REPO;
|
||||
if (!TAG || !REPO) {
|
||||
console.error('TAG and REPO env vars are required');
|
||||
if (!TAG || !VERSION || !REPO) {
|
||||
console.error('TAG, VERSION, and REPO env vars are required');
|
||||
process.exit(1);
|
||||
}
|
||||
const version = TAG.replace(/^v/, '');
|
||||
if (!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(VERSION)) {
|
||||
console.error(`VERSION must be valid SemVer (got: ${VERSION})`);
|
||||
process.exit(1);
|
||||
}
|
||||
const version = VERSION;
|
||||
|
||||
const dir = mkdtempSync(join(tmpdir(), 'sable-sigs-'));
|
||||
execSync(`gh release download "${TAG}" --repo "${REPO}" --pattern '*.sig' --dir "${dir}"`, {
|
||||
@@ -50,13 +55,15 @@ if (Object.keys(platforms).length === 0) {
|
||||
}
|
||||
|
||||
let notes = `Sable ${version}`;
|
||||
try {
|
||||
notes =
|
||||
execSync(`gh release view "${TAG}" --repo "${REPO}" --json body -q .body`, {
|
||||
encoding: 'utf8',
|
||||
}).trim() || notes;
|
||||
} catch {
|
||||
// keep the default note
|
||||
if (TAG !== 'nightly') {
|
||||
try {
|
||||
notes =
|
||||
execSync(`gh release view "${TAG}" --repo "${REPO}" --json body -q .body`, {
|
||||
encoding: 'utf8',
|
||||
}).trim() || notes;
|
||||
} catch {
|
||||
// keep the default note
|
||||
}
|
||||
}
|
||||
|
||||
const manifest = { version, notes, pub_date: new Date().toISOString(), platforms };
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env node
|
||||
/* oxlint-disable no-console */
|
||||
|
||||
import { readFileSync } from 'node:fs';
|
||||
|
||||
const runNumber = process.argv[2];
|
||||
const runAttempt = process.argv[3];
|
||||
const packageJson = JSON.parse(readFileSync('package.json', 'utf8'));
|
||||
const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(packageJson.version);
|
||||
|
||||
if (!match) {
|
||||
console.error(`package.json version must be stable SemVer (got: ${packageJson.version})`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (!/^\d+$/.test(runNumber ?? '') || !/^\d+$/.test(runAttempt ?? '')) {
|
||||
console.error('Usage: nightly-version.mjs <run-number> <run-attempt>');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const [, major, minor, patch] = match;
|
||||
console.log(`${major}.${minor}.${Number(patch) + 1}-nightly.${runNumber}.${runAttempt}`);
|
||||
@@ -1,20 +1,32 @@
|
||||
#!/usr/bin/env node
|
||||
/* oxlint-disable no-console */
|
||||
|
||||
// Stamps a version into src-tauri/tauri.conf.json, which can drift from the
|
||||
// package.json version Knope tags on. Used by tauri-build.yml.
|
||||
// Stamps release-specific settings into src-tauri/tauri.conf.json, which can
|
||||
// drift from the package.json version Knope tags on. Used by tauri-build.yml.
|
||||
|
||||
import { readFileSync, writeFileSync } from 'node:fs';
|
||||
import process from 'node:process';
|
||||
|
||||
const version = process.argv[2];
|
||||
const updaterEndpoint = process.argv[3];
|
||||
if (!version || !/^\d+\.\d+\.\d+/.test(version)) {
|
||||
console.error(`Usage: set-tauri-version.mjs <version> (got: ${version ?? '<none>'})`);
|
||||
console.error(
|
||||
`Usage: set-tauri-version.mjs <version> [updater-endpoint] (got: ${version ?? '<none>'})`
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (updaterEndpoint && !/^https:\/\//.test(updaterEndpoint)) {
|
||||
console.error(`Updater endpoint must use HTTPS (got: ${updaterEndpoint})`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const file = 'src-tauri/tauri.conf.json';
|
||||
const config = JSON.parse(readFileSync(file, 'utf8'));
|
||||
config.version = version;
|
||||
if (updaterEndpoint) {
|
||||
config.plugins.updater.endpoints = [updaterEndpoint];
|
||||
}
|
||||
writeFileSync(file, `${JSON.stringify(config, null, 2)}\n`);
|
||||
console.log(`Set ${file} version to ${version}`);
|
||||
if (updaterEndpoint) console.log(`Set ${file} updater endpoint to ${updaterEndpoint}`);
|
||||
Reference in new issue
Block a user