Cut and publish extension releases from the version lifecycle
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.
This commit is contained in:
7 files changed
+253
-17
No files matched your search
@@ -31,16 +31,20 @@
|
||||
- `pnpm test`: Build and run the test suite via Testem.
|
||||
- `pnpm lint`: Run all linters (ESLint, Prettier, stylelint, template-lint).
|
||||
- `pnpm lint:fix`: Auto-fix linting and formatting issues.
|
||||
- `pnpm ext:dev`: Watch-build the Firefox extension and launch it via `web-ext`.
|
||||
- `pnpm ext:build:chrome` / `pnpm ext:build:firefox`: Package the extension.
|
||||
- `pnpm ext:lint`: Lint the packaged extension with `web-ext`.
|
||||
- `pnpm ext:dev`: Watch-build the Firefox extension (development) and launch it via `web-ext`.
|
||||
- `pnpm ext:build:chrome` / `pnpm ext:build:firefox`: Build the extension (production).
|
||||
- `pnpm ext:build:dev:chrome` / `pnpm ext:build:dev:firefox`: Build the extension (development).
|
||||
- `pnpm ext:pack`: Build, sign (Firefox, via AMO) and package both targets into `web-ext-artifacts/`.
|
||||
- `pnpm version <patch|minor|major>`: Cut a release — lints/tests, bumps the version, builds and signs, commits and tags, pushes, and uploads to the Gitea release.
|
||||
- `pnpm ext:lint`: Lint the packaged Firefox extension with `web-ext`.
|
||||
|
||||
## Browser Extension
|
||||
|
||||
Dashtab is a Manifest V3 browser extension that overrides the new tab. It can also run as a plain web app via `pnpm start`, but that path exists only for development convenience. `vite.config.mjs` switches to relative asset paths and copies the target manifest into `extension/build/<target>/` when `DASHTAB_EXT=1`, with `DASHTAB_EXT_TARGET` selecting `chrome` or `firefox`. Never edit `extension/build/` by hand.
|
||||
Dashtab is a Manifest V3 browser extension that overrides the new tab. It can also run as a plain web app via `pnpm start`, but that path exists only for development convenience. `vite.config.mjs` switches to relative asset paths and writes the target manifest into `extension/build/<target>/` when `DASHTAB_EXT=1`, with `DASHTAB_EXT_TARGET` selecting `chrome` or `firefox`. The written manifest takes its `version` from `package.json` and drops the `(dev)` name suffix when `DASHTAB_RELEASE=1`. Never edit `extension/build/` by hand.
|
||||
|
||||
- **Manifests**: `extension/manifest.chrome.json` and `extension/manifest.firefox.json`. Extension ids are pinned (Chrome `key`, Firefox `browser_specific_settings.gecko.id`) so `identity.getRedirectURL()` stays stable.
|
||||
- **Auth transport**: `app/auth/transport.js` feature-detects the identity API (`app/utils/extension.js`). The extension uses `identity.launchWebAuthFlow` + `getRedirectURL`; the dev-server build (no identity API) falls back to a full-page redirect to the provider callback. See `doc/extension_auth.md`.
|
||||
- **Releasing**: `pnpm version <bump>` builds and signs locally (the Firefox XPI is signed via AMO, with credentials read from the GNOME Keyring) and publishes a Gitea release with the signed `.xpi` and a Chrome `.zip`. See `scripts/release/`.
|
||||
|
||||
## Key Conventions
|
||||
|
||||
@@ -53,4 +57,4 @@ Dashtab is a Manifest V3 browser extension that overrides the new tab. It can al
|
||||
## Agent Restrictions
|
||||
|
||||
- **No Git Write Operations**: Do not run Git commands that mutate state or commit changes (e.g., `git commit`, `git add`, `git push`, etc.) without being asked to do so, or without asking for approval first.
|
||||
- **No Production Builds**: Do not run `pnpm build` or production build commands. Use `pnpm test` or `pnpm start` for testing and development.
|
||||
- **Production Builds**: Run `pnpm build` or production builds only when packaging or releasing an extension (`pnpm ext:build:*`, `pnpm ext:pack`, `pnpm version`). For day-to-day development use `pnpm start` (or `pnpm ext:dev`) and `pnpm test`.
|
||||
@@ -46,8 +46,10 @@ production: requests go out with the extension's host permissions and
|
||||
authorizations use the browser's `identity.launchWebAuthFlow`.
|
||||
|
||||
- `pnpm ext:build:firefox` / `pnpm ext:build:chrome` build the app into
|
||||
`extension/build/firefox/` and `extension/build/chrome/` respectively, with
|
||||
the matching `extension/manifest.<browser>.json`.
|
||||
`extension/build/firefox/` and `extension/build/chrome/` respectively
|
||||
(production), with the matching `extension/manifest.<browser>.json`.
|
||||
- `pnpm ext:build:dev:firefox` / `pnpm ext:build:dev:chrome` do the same as a
|
||||
development build.
|
||||
- `pnpm ext:dev` rebuilds on change and launches Firefox via `web-ext`
|
||||
(dedicated temporary profile). Changes reload the add-on rather than using HMR.
|
||||
- `pnpm ext:serve` runs `web-ext` against an existing `extension/build/firefox/`.
|
||||
@@ -56,6 +58,23 @@ authorizations use the browser's `identity.launchWebAuthFlow`.
|
||||
`chrome://extensions` → **Load unpacked** → `extension/build/chrome/` (Chrome).
|
||||
- `pnpm ext:lint` validates the packaged Firefox extension.
|
||||
|
||||
### Releasing
|
||||
|
||||
Cutting a release is local: builds and the Firefox signing happen on your
|
||||
machine, and only the resulting artifacts are published.
|
||||
|
||||
- `pnpm ext:pack` builds both targets and produces a signed Firefox `.xpi` and a
|
||||
Chrome `.zip` in `web-ext-artifacts/`. Firefox signing uses
|
||||
[`web-ext sign`](https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#web-ext-sign)
|
||||
(unlisted); the AMO API credentials are read from the GNOME Keyring with
|
||||
`secret-tool` (see `scripts/release/sign-firefox.mjs` for the entry names).
|
||||
- `pnpm version <patch|minor|major>` runs the linters and tests, bumps the
|
||||
version, builds and signs (`pnpm ext:pack`), commits and tags, then pushes and
|
||||
uploads both artifacts to the Gitea release for the new tag.
|
||||
|
||||
The version in the built manifest comes from `package.json`; release builds also
|
||||
drop the `(dev)` name suffix.
|
||||
|
||||
The extension IDs are pinned (`key` in the Chrome manifest, `browser_specific_settings.gecko.id`
|
||||
in the Firefox manifest) so the OAuth redirect URL is stable. See
|
||||
[`doc/extension_auth.md`](doc/extension_auth.md) for the redirect URLs forum
|
||||
|
||||
+11
-3
@@ -12,11 +12,19 @@
|
||||
},
|
||||
"scripts": {
|
||||
"build": "vite build",
|
||||
"ext:build": "DASHTAB_EXT=1 DASHTAB_EXT_TARGET=firefox vite build --mode development",
|
||||
"ext:build:chrome": "DASHTAB_EXT=1 DASHTAB_EXT_TARGET=chrome vite build --mode development",
|
||||
"ext:build:firefox": "DASHTAB_EXT=1 DASHTAB_EXT_TARGET=firefox vite build --mode development",
|
||||
"preversion": "pnpm lint && pnpm test",
|
||||
"version": "pnpm ext:pack",
|
||||
"postversion": "node scripts/release/publish.mjs",
|
||||
"ext:build": "pnpm ext:build:firefox",
|
||||
"ext:build:chrome": "DASHTAB_EXT=1 DASHTAB_EXT_TARGET=chrome vite build",
|
||||
"ext:build:firefox": "DASHTAB_EXT=1 DASHTAB_EXT_TARGET=firefox vite build",
|
||||
"ext:build:dev:chrome": "DASHTAB_EXT=1 DASHTAB_EXT_TARGET=chrome vite build --mode development",
|
||||
"ext:build:dev:firefox": "DASHTAB_EXT=1 DASHTAB_EXT_TARGET=firefox vite build --mode development",
|
||||
"ext:dev": "concurrently -k \"DASHTAB_EXT=1 DASHTAB_EXT_TARGET=firefox vite build --mode development --watch\" \"wait-on extension/build/firefox/manifest.json && pnpm ext:serve\"",
|
||||
"ext:lint": "web-ext lint --source-dir=extension/build/firefox",
|
||||
"ext:pack": "pnpm ext:pack:firefox && pnpm ext:pack:chrome",
|
||||
"ext:pack:chrome": "DASHTAB_RELEASE=1 pnpm ext:build:chrome && node scripts/release/pack-chrome.mjs",
|
||||
"ext:pack:firefox": "DASHTAB_RELEASE=1 pnpm ext:build:firefox && node scripts/release/sign-firefox.mjs",
|
||||
"ext:serve": "web-ext run --source-dir=extension/build/firefox --start-url about:newtab",
|
||||
"format": "prettier . --cache --write",
|
||||
"lint": "concurrently \"pnpm:lint:*(!fix)\" --names \"lint:\" --prefixColors auto",
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env node
|
||||
// Packages the built Chrome/Brave extension into a zip for the release page.
|
||||
// The Chrome build has no signing step (it is loaded unpacked), so this just
|
||||
// archives the built directory.
|
||||
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 sourceDir = join(repoRoot, 'extension', 'build', 'chrome');
|
||||
const artifactsDir = join(repoRoot, 'web-ext-artifacts');
|
||||
const webExt = join(repoRoot, 'node_modules', '.bin', 'web-ext');
|
||||
|
||||
// The test suite is a dev-only artifact; keep it out of the packaged extension.
|
||||
const ignoreFiles = ['tests/**', 'testem.js', 'assets/tests-*'];
|
||||
|
||||
const result = spawnSync(
|
||||
webExt,
|
||||
[
|
||||
'build',
|
||||
'--source-dir',
|
||||
sourceDir,
|
||||
'--artifacts-dir',
|
||||
artifactsDir,
|
||||
'--overwrite-dest',
|
||||
'--ignore-files',
|
||||
...ignoreFiles,
|
||||
],
|
||||
{ stdio: 'inherit' },
|
||||
);
|
||||
|
||||
process.exit(result.status ?? 1);
|
||||
@@ -0,0 +1,93 @@
|
||||
#!/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}`);
|
||||
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env node
|
||||
// Signs the built Firefox extension with addons.mozilla.org (unlisted, so it
|
||||
// can be self-distributed). The AMO API credentials are read from the GNOME
|
||||
// Keyring via `secret-tool`, so no secret ever lands in a file, an argument
|
||||
// list, or the repository.
|
||||
//
|
||||
// Store the credentials once (Arch + GNOME):
|
||||
// secret-tool store --label="Dashtab AMO API key" service dashtab kind amo-api-key
|
||||
// secret-tool store --label="Dashtab AMO API secret" service dashtab kind amo-api-secret
|
||||
import { execFileSync, 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 sourceDir = join(repoRoot, 'extension', 'build', 'firefox');
|
||||
const artifactsDir = join(repoRoot, 'web-ext-artifacts');
|
||||
const webExt = join(repoRoot, 'node_modules', '.bin', 'web-ext');
|
||||
|
||||
// The test suite is a dev-only artifact; keep it out of the packaged extension.
|
||||
const ignoreFiles = ['tests/**', 'testem.js', 'assets/tests-*'];
|
||||
|
||||
function keyringSecret(kind, label) {
|
||||
try {
|
||||
return execFileSync(
|
||||
'secret-tool',
|
||||
['lookup', 'service', 'dashtab', 'kind', kind],
|
||||
{ encoding: 'utf8' },
|
||||
).replace(/\n+$/, '');
|
||||
} catch {
|
||||
console.error(
|
||||
`Could not read the AMO credential from the keyring (${kind}).\n` +
|
||||
`Store it with:\n` +
|
||||
` secret-tool store --label="${label}" service dashtab kind ${kind}`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
const apiKey = keyringSecret('amo-api-key', 'Dashtab AMO API key');
|
||||
const apiSecret = keyringSecret('amo-api-secret', 'Dashtab AMO API secret');
|
||||
|
||||
const result = spawnSync(
|
||||
webExt,
|
||||
[
|
||||
'sign',
|
||||
'--channel',
|
||||
'unlisted',
|
||||
'--source-dir',
|
||||
sourceDir,
|
||||
'--artifacts-dir',
|
||||
artifactsDir,
|
||||
'--overwrite-dest',
|
||||
'--ignore-files',
|
||||
...ignoreFiles,
|
||||
],
|
||||
{
|
||||
stdio: 'inherit',
|
||||
env: {
|
||||
...process.env,
|
||||
WEB_EXT_API_KEY: apiKey,
|
||||
WEB_EXT_API_SECRET: apiSecret,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
process.exit(result.status ?? 1);
|
||||
+21
-7
@@ -3,9 +3,8 @@ import { extensions, classicEmberSupport, ember } from '@embroider/vite';
|
||||
import { babel } from '@rollup/plugin-babel';
|
||||
import tailwindcss from '@tailwindcss/vite';
|
||||
import corsAnywhere from 'cors-anywhere';
|
||||
import { copyFileSync, mkdirSync } from 'node:fs';
|
||||
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const CORS_PROXY_HOST = '127.0.0.1';
|
||||
const CORS_PROXY_PORT = Number(process.env.DASHTAB_CORS_PROXY_PORT || 8081);
|
||||
@@ -40,8 +39,9 @@ function corsProxyPlugin() {
|
||||
|
||||
// Emits the target browser's manifest into the extension build output so the
|
||||
// packaged app can be loaded as an unpacked extension or linted with web-ext.
|
||||
// The manifest is written into Vite's resolved output directory so the two
|
||||
// cannot drift apart.
|
||||
// The manifest is written into Vite's resolved output directory, its version is
|
||||
// kept in sync with package.json (the single source of truth), and release
|
||||
// builds (DASHTAB_RELEASE=1) drop the "(dev)" name suffix.
|
||||
function extensionManifestPlugin(target) {
|
||||
let outDir;
|
||||
return {
|
||||
@@ -51,12 +51,26 @@ function extensionManifestPlugin(target) {
|
||||
outDir = config.build.outDir;
|
||||
},
|
||||
closeBundle() {
|
||||
mkdirSync(outDir, { recursive: true });
|
||||
copyFileSync(
|
||||
fileURLToPath(
|
||||
const pkg = JSON.parse(
|
||||
readFileSync(new URL('./package.json', import.meta.url), 'utf8'),
|
||||
);
|
||||
const manifest = JSON.parse(
|
||||
readFileSync(
|
||||
new URL(`./extension/manifest.${target}.json`, import.meta.url),
|
||||
'utf8',
|
||||
),
|
||||
);
|
||||
|
||||
manifest.version = pkg.version;
|
||||
|
||||
if (process.env.DASHTAB_RELEASE) {
|
||||
manifest.name = 'Dashtab';
|
||||
}
|
||||
|
||||
mkdirSync(outDir, { recursive: true });
|
||||
writeFileSync(
|
||||
join(outDir, 'manifest.json'),
|
||||
`${JSON.stringify(manifest, null, 2)}\n`,
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user