Releases were built and signed in CI, which meant AMO credentials had to live on the runner. Move the whole flow local: builds and Firefox signing happen on the maintainer's machine and only the finished artifacts are published. Add `ext:pack:firefox` and `ext:pack:chrome` (production builds; the Firefox one is signed via `web-ext sign` unlisted with credentials read from the GNOME Keyring through `secret-tool`, the Chrome one is zipped) and wire them to the `version` lifecycle: - `preversion` runs lint and tests. - `version` builds and signs into `web-ext-artifacts/`. - `postversion` pushes the bump commit and tag, then uploads both artifacts to the Gitea release and publishes it if still a draft. Switch the plain `ext:build:*` scripts to production and add `ext:build:dev:*` for development builds; `ext:dev` is unchanged. The build manifest now takes its version from package.json and drops the "(dev)" name suffix when `DASHTAB_RELEASE=1`. Because packaging needs a production build, relax the AGENTS.md production-build restriction to allow it for packaging and releasing.
94 lines
2.9 KiB
JavaScript
94 lines
2.9 KiB
JavaScript
#!/usr/bin/env node
|
|
// Runs after `pnpm version` has bumped package.json and created the commit and
|
|
// tag (via the `postversion` lifecycle). It pushes the commit and tag, then
|
|
// attaches the signed Firefox `.xpi` and the Chrome `.zip` to the Gitea release
|
|
// for the new tag. The release text is never touched: if a draft already exists
|
|
// (prepared by hand, with notes) it is reused; if none exists, a bare draft is
|
|
// created so the upload still succeeds.
|
|
import { readFileSync, readdirSync, existsSync } from 'node:fs';
|
|
import { spawnSync } from 'node:child_process';
|
|
import { dirname, join } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');
|
|
const artifactsDir = join(repoRoot, 'web-ext-artifacts');
|
|
|
|
const pkg = JSON.parse(readFileSync(join(repoRoot, 'package.json'), 'utf8'));
|
|
const tag = `v${pkg.version}`;
|
|
|
|
function run(cmd, args) {
|
|
return spawnSync(cmd, args, { stdio: 'inherit', cwd: repoRoot });
|
|
}
|
|
|
|
function gtJson(args) {
|
|
const result = spawnSync('gt', args, { encoding: 'utf8', cwd: repoRoot });
|
|
if (result.status !== 0) {
|
|
return null;
|
|
}
|
|
try {
|
|
return JSON.parse(result.stdout);
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function artifact(extension) {
|
|
if (!existsSync(artifactsDir)) {
|
|
return null;
|
|
}
|
|
const match = readdirSync(artifactsDir).find(
|
|
(name) => name.includes(pkg.version) && name.endsWith(extension),
|
|
);
|
|
return match ? join(artifactsDir, match) : null;
|
|
}
|
|
|
|
const xpi = artifact('.xpi');
|
|
const zip = artifact('.zip');
|
|
const assets = [xpi, zip].filter(Boolean);
|
|
|
|
if (assets.length === 0) {
|
|
console.error(
|
|
`No release artifacts for ${pkg.version} in web-ext-artifacts/. ` +
|
|
`Run "pnpm ext:pack" first.`,
|
|
);
|
|
process.exit(1);
|
|
}
|
|
|
|
// Push the bump commit and its tag.
|
|
if (run('git', ['push', '--follow-tags']).status !== 0) {
|
|
console.error('git push failed; not touching the release.');
|
|
process.exit(1);
|
|
}
|
|
|
|
// The release may already exist (prepared as a draft) or not at all.
|
|
let release = gtJson(['release', 'view', tag, '--json', 'id,draft']);
|
|
if (!release) {
|
|
console.log(`No release found for ${tag}; creating a draft.`);
|
|
if (
|
|
run('gt', ['release', 'create', tag, '--draft', '--title', tag]).status !==
|
|
0
|
|
) {
|
|
console.error(`Could not create a release for ${tag}.`);
|
|
process.exit(1);
|
|
}
|
|
release = gtJson(['release', 'view', tag, '--json', 'id,draft']);
|
|
}
|
|
|
|
console.log(`Uploading to ${tag}: ${assets.join(', ')}`);
|
|
if (
|
|
run('gt', ['release', 'upload', tag, ...assets, '--clobber']).status !== 0
|
|
) {
|
|
console.error('Asset upload failed.');
|
|
process.exit(1);
|
|
}
|
|
|
|
// Gitea publishes a draft automatically when the tag is pushed; only publish
|
|
// here if that did not happen, so a prepared draft never stays hidden.
|
|
release = gtJson(['release', 'view', tag, '--json', 'draft']);
|
|
if (release?.draft) {
|
|
console.log(`Publishing ${tag}.`);
|
|
run('gt', ['release', 'publish', tag]);
|
|
}
|
|
|
|
console.log(`Done: ${tag}`);
|