Publish the 0.1.0-beta.1 update feed and release script
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c303b88f9e
commit
835cdad98b
3 changed files with 75 additions and 2 deletions
60
scripts/publish-release.mjs
Normal file
60
scripts/publish-release.mjs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
// Creates (or reuses) a Forgejo release for a tag and uploads the Windows installer and
|
||||
// its updater signature. Reads FORGEJO_TOKEN from the environment or the ignored .env.
|
||||
// Usage: node scripts/publish-release.mjs <version> [--prerelease]
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
const API = 'https://git.elijahkuntz.com/api/v1/repos/Elijah/Kaleido-Desktop';
|
||||
const root = path.resolve(import.meta.dirname, '..');
|
||||
const version = process.argv[2];
|
||||
const prerelease = process.argv.includes('--prerelease');
|
||||
if (!version) {
|
||||
console.error('usage: node scripts/publish-release.mjs <version> [--prerelease]');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
let token = process.env.FORGEJO_TOKEN;
|
||||
if (!token && fs.existsSync(path.join(root, '.env'))) {
|
||||
token = fs.readFileSync(path.join(root, '.env'), 'utf8').match(/^FORGEJO_TOKEN=(.*)$/m)?.[1]?.trim().replace(/^"|"$/g, '');
|
||||
}
|
||||
if (!token) {
|
||||
console.error('FORGEJO_TOKEN is not set.');
|
||||
process.exit(1);
|
||||
}
|
||||
const headers = { Authorization: `token ${token}`, Accept: 'application/json' };
|
||||
|
||||
async function api(method, url, body) {
|
||||
const r = await fetch(url.startsWith('http') ? url : API + url, {
|
||||
method,
|
||||
headers: body instanceof FormData ? headers : { ...headers, 'Content-Type': 'application/json' },
|
||||
body: body === undefined ? undefined : body instanceof FormData ? body : JSON.stringify(body),
|
||||
});
|
||||
const text = await r.text();
|
||||
if (!r.ok) throw new Error(`${method} ${url} → ${r.status} ${text.slice(0, 300)}`);
|
||||
return text ? JSON.parse(text) : null;
|
||||
}
|
||||
|
||||
const tag = `v${version}`;
|
||||
const changelog = fs.readFileSync(path.join(root, 'CHANGELOG.md'), 'utf8');
|
||||
const section = changelog.split(/^## /m).find((s) => s.startsWith(version));
|
||||
const notes = section ? section.slice(version.length).trim() : '';
|
||||
|
||||
let release = await api('GET', `/releases/tags/${tag}`).catch(() => null);
|
||||
if (!release) {
|
||||
release = await api('POST', '/releases', { tag_name: tag, name: `Kaleido Desktop ${version}`, body: notes, prerelease, draft: false });
|
||||
console.log(`Created release ${release.name}`);
|
||||
} else console.log(`Using existing release ${release.name}`);
|
||||
|
||||
const dir = path.join(root, 'src-tauri/target/release/bundle/nsis');
|
||||
const files = [`Kaleido_${version}_x64-setup.exe`, `Kaleido_${version}_x64-setup.exe.sig`];
|
||||
for (const name of files) {
|
||||
const file = path.join(dir, name);
|
||||
if (!fs.existsSync(file)) throw new Error(`Missing ${file}; run scripts/build.ps1 first.`);
|
||||
const existing = release.assets?.find((a) => a.name === name);
|
||||
if (existing) await api('DELETE', `/releases/${release.id}/assets/${existing.id}`);
|
||||
const form = new FormData();
|
||||
form.append('attachment', new Blob([fs.readFileSync(file)]), name);
|
||||
const asset = await api('POST', `/releases/${release.id}/assets?name=${encodeURIComponent(name)}`, form);
|
||||
console.log(`Uploaded ${asset.name} (${asset.size} bytes): ${asset.browser_download_url}`);
|
||||
}
|
||||
console.log(release.html_url);
|
||||
Loading…
Add table
Add a link
Reference in a new issue