diff --git a/.github/scripts/extension-checks.mjs b/.github/scripts/extension-checks.mjs index 4db0f04..e58958d 100755 --- a/.github/scripts/extension-checks.mjs +++ b/.github/scripts/extension-checks.mjs @@ -3,12 +3,15 @@ // // node .github/scripts/extension-checks.mjs package // node .github/scripts/extension-checks.mjs lint +// node .github/scripts/extension-checks.mjs amo-result // // package: the zip has what both browsers need and nothing development-only. // lint: `web-ext lint --output json` has no errors, and every warning is // on the allowlist (each entry says why it is accepted). Allowlist // entries that no longer match are reported, so the list shrinks // when a warning is fixed. +// amo-result: what `web-ext sign --channel listed` achieved (see amoSignOutcome), +// printed as `status=` and `xpi=` lines for $GITHUB_OUTPUT. // // Problems are printed as GitHub annotations (::error / ::warning). import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'; @@ -134,6 +137,27 @@ export function checkLint(report, allowlist) { return { errors: report.errors, unexpected, allowed, unused: allowlist.filter((e) => !used.has(e)) }; } +// web-ext (pinned in extension-lint.sh and the release workflow) rejects with +// this when the version was submitted but AMO hasn't approved and signed it +// within --approval-timeout. Listed versions can wait for review, so that is +// not a failure: the signed file appears on AMO later. +const APPROVAL_TIMEOUT = 'Approval: timeout exceeded.'; + +/** + * The outcome of `web-ext sign --channel listed`. + * @param {{exitCode: number, log: string, files: string[]}} run + * exit code, combined output, and the files web-ext left in --artifacts-dir + * @returns {{status: 'signed', xpi: string} | {status: 'pending'} | {status: 'failed', reason: string}} + */ +export function amoSignOutcome({ exitCode, log, files }) { + const xpi = files.filter((f) => f.endsWith('.xpi')).sort().at(-1); + if (exitCode === 0 && xpi) return { status: 'signed', xpi }; + if (log.includes(APPROVAL_TIMEOUT)) return { status: 'pending' }; + if (exitCode === 0) return { status: 'pending' }; // submitted, nothing downloaded + const reason = log.match(/(?:WebExtError|Error): .*/)?.[0] ?? `web-ext sign exited with ${exitCode}`; + return { status: 'failed', reason }; +} + const describe = (m) => `${m.code}: ${m.message}${m.file ? ` (${m.file})` : ''}`; // Annotation text must stay on one line. const oneLine = (s) => String(s).replace(/\r?\n/g, ' '); @@ -163,7 +187,22 @@ function main([command, ...args]) { console.log(`web-ext lint OK: 0 errors, ${allowed.length} allowed warnings.`); return 0; } - console.error('usage: extension-checks.mjs package | lint '); + if (command === 'amo-result' && args.length === 3) { + const [exitCode, logFile, artifactsDir] = args; + const outcome = amoSignOutcome({ + exitCode: Number(exitCode), + log: existsSync(logFile) ? readFileSync(logFile, 'utf8') : '', + files: existsSync(artifactsDir) ? listFiles(artifactsDir) : [], + }); + console.log(`status=${outcome.status}`); + if (outcome.status === 'signed') console.log(`xpi=${join(artifactsDir, outcome.xpi)}`); + if (outcome.status === 'failed') { + console.error(`::error::addons.mozilla.org submission failed: ${oneLine(outcome.reason)}`); + return 1; + } + return 0; + } + console.error('usage: extension-checks.mjs package | lint | amo-result '); return 2; } diff --git a/.github/scripts/extension-checks.test.mjs b/.github/scripts/extension-checks.test.mjs index ccc7b27..4d8f4b5 100644 --- a/.github/scripts/extension-checks.test.mjs +++ b/.github/scripts/extension-checks.test.mjs @@ -3,7 +3,7 @@ import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'nod import { tmpdir } from 'node:os'; import { dirname, join } from 'node:path'; import { after, test } from 'node:test'; -import { checkLint, checkPackage, listFiles, matches } from './extension-checks.mjs'; +import { amoSignOutcome, checkLint, checkPackage, listFiles, main, matches } from './extension-checks.mjs'; const dirs = []; after(() => dirs.forEach((d) => rmSync(d, { recursive: true, force: true }))); @@ -153,3 +153,65 @@ test('the checked-in allowlist is well formed', () => { assert.ok(entry.reason?.length > 20, `${entry.code} needs a real reason`); } }); + +test('amoSignOutcome: a signed .xpi downloaded within the timeout', () => { + const outcome = amoSignOutcome({ exitCode: 0, log: 'Downloaded:\n./tts_study_assistant-0.3.5.xpi', files: ['tts_study_assistant-0.3.5.xpi'] }); + assert.deepEqual(outcome, { status: 'signed', xpi: 'tts_study_assistant-0.3.5.xpi' }); +}); + +test('amoSignOutcome: submitted but awaiting review is pending, not failed', () => { + const log = 'Waiting for approval...\nWebExtError: Approval: timeout exceeded. When approved the signed XPI file can be downloaded from https://addons.mozilla.org/developers/addon/x/versions/1'; + assert.deepEqual(amoSignOutcome({ exitCode: 1, log, files: [] }), { status: 'pending' }); + // --approval-timeout 0, or a success with nothing downloaded. + assert.deepEqual(amoSignOutcome({ exitCode: 0, log: 'Waiting for approval and download of signed XPI skipped.', files: [] }), { status: 'pending' }); +}); + +test('amoSignOutcome: real errors fail with their message', () => { + // A validation timeout is a different context from approval. + for (const log of ['WebExtError: Validation: timeout exceeded.', 'Error: Upload failed: Unauthorized.\n{"detail": "Incorrect authentication credentials."}']) { + const outcome = amoSignOutcome({ exitCode: 1, log, files: [] }); + assert.equal(outcome.status, 'failed', log); + assert.match(outcome.reason, /timeout exceeded|Unauthorized/); + } + assert.deepEqual(amoSignOutcome({ exitCode: 3, log: '', files: [] }), { status: 'failed', reason: 'web-ext sign exited with 3' }); +}); + +test('amo-result command prints GitHub outputs and fails only on errors', () => { + const dir = mkdtempSync(join(tmpdir(), 'amo-')); + dirs.push(dir); + const artifacts = join(dir, 'artifacts'); + mkdirSync(artifacts); + const log = join(dir, 'sign.log'); + const run = (exitCode, text) => { + writeFileSync(log, text); + const lines = []; + const errors = []; + const [out, err] = [console.log, console.error]; + console.log = (l) => lines.push(l); + console.error = (l) => errors.push(l); + try { + return { code: main(['amo-result', String(exitCode), log, artifacts]), lines, errors }; + } finally { + [console.log, console.error] = [out, err]; + } + }; + + assert.deepEqual(run(1, 'WebExtError: Approval: timeout exceeded.'), { code: 0, lines: ['status=pending'], errors: [] }); + const failed = run(1, 'Error: Upload failed: Forbidden.'); + assert.equal(failed.code, 1); + assert.deepEqual(failed.lines, ['status=failed']); + assert.match(failed.errors[0], /^::error::addons\.mozilla\.org submission failed: Error: Upload failed: Forbidden\.$/); + + writeFileSync(join(artifacts, 'tts_study_assistant-0.3.5.xpi'), 'signed'); + assert.deepEqual(run(0, 'Downloaded'), { code: 0, lines: ['status=signed', `xpi=${join(artifacts, 'tts_study_assistant-0.3.5.xpi')}`], errors: [] }); +}); + +test('the release workflow signs with the web-ext version the lint script pins', () => { + // amoSignOutcome matches web-ext's approval-timeout message, so both must + // move together (and the allowlist is tuned to that version's linter). + const pinned = (path, re) => readFileSync(new URL(path, import.meta.url), 'utf8').match(re)?.[1]; + const lint = pinned('./extension-lint.sh', /WEB_EXT_VERSION="\$\{WEB_EXT_VERSION:-([\d.]+)\}"/); + const release = pinned('../workflows/extension-release.yml', /WEB_EXT_VERSION: ([\d.]+)/); + assert.ok(lint, 'version not found in extension-lint.sh'); + assert.equal(release, lint); +}); diff --git a/.github/scripts/extension-lint.sh b/.github/scripts/extension-lint.sh new file mode 100755 index 0000000..b614a4a --- /dev/null +++ b/.github/scripts/extension-lint.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# Lints an unzipped extension package with Mozilla's web-ext (the linter +# addons.mozilla.org runs on upload) and compares the result with the +# allowlist. Used by Extension CI and the release workflow, so both lint the +# same way with the same pinned version. +# +# .github/scripts/extension-lint.sh +# +# Writes /lint.json (the raw report) and /lint.txt +# (the check's output) and exits non-zero on errors or unexpected warnings. +set -euo pipefail + +# Pinned for reproducible results. To update: bump this, run Extension CI, and +# adjust extension-lint-allowlist.json for new or removed warnings +# (https://github.com/mozilla/web-ext/releases). +WEB_EXT_VERSION="${WEB_EXT_VERSION:-10.8.0}" + +package="$1" +reports="$2" +scripts="$(dirname "$0")" +mkdir -p "$reports" + +echo "web-ext ${WEB_EXT_VERSION}" > "$reports/lint.txt" +# web-ext exits non-zero on lint errors; the check below reports them. +npx --yes "web-ext@${WEB_EXT_VERSION}" lint --source-dir "$package" --output json > "$reports/lint.json" || true +# pipefail (set above): the check's exit code, not tee's. +node "$scripts/extension-checks.mjs" lint "$reports/lint.json" "$scripts/extension-lint-allowlist.json" | tee -a "$reports/lint.txt" diff --git a/.github/scripts/extension-release-notes.sh b/.github/scripts/extension-release-notes.sh index 48a0974..93b0070 100755 --- a/.github/scripts/extension-release-notes.sh +++ b/.github/scripts/extension-release-notes.sh @@ -16,7 +16,10 @@ previous="$(git tag -l 'extension-v*' --sort=v:refname | awk -v t="${tag}" '$0 = range="${previous:+${previous}..}${tag}" { - echo "Chrome extension **v${version}**: install by unzipping the attached file and loading it at \`chrome://extensions\` (Developer mode → Load unpacked), or upload the zip to the Chrome Web Store." + echo "Extension **v${version}** for Chrome and Firefox. The attached \`tts-study-assistant-extension-v${version}.zip\` is the package for both stores: upload it to the Chrome Web Store and to addons.mozilla.org." + echo + echo "- **Chrome:** unzip and load the folder at \`chrome://extensions\` (Developer mode → Load unpacked)." + echo "- **Firefox:** \`about:debugging#/runtime/this-firefox\` → Load Temporary Add-on → pick the zip. A \`tts-study-assistant-firefox-v${version}.xpi\`, when attached, is the version signed by addons.mozilla.org." echo echo "### Changes in \`extension/\`" echo diff --git a/.github/scripts/extension-version-check.sh b/.github/scripts/extension-version-check.sh index 6c4f7de..bca6234 100755 --- a/.github/scripts/extension-version-check.sh +++ b/.github/scripts/extension-version-check.sh @@ -1,8 +1,9 @@ #!/usr/bin/env bash # Fails unless the extension's version is higher than every version it must -# beat: main's manifest.json and the latest extension-v* release tag. The -# Chrome Web Store only accepts uploads with a higher version than the -# published one, so every shipped change needs a bump. +# beat: main's manifest.json and the latest extension-v* release tag. Both +# stores need it: the Chrome Web Store only accepts a higher version than the +# published one, and addons.mozilla.org rejects any version number it has seen +# before (even a rejected or deleted one). So every shipped change needs a bump. # # .github/scripts/extension-version-check.sh [latest-release-version] set -euo pipefail @@ -11,7 +12,8 @@ new="$1" base="$2" released="${3:-}" -# Chrome: 1-4 dot-separated integers, each 0-65535, no leading zeros. +# Chrome: 1-4 dot-separated integers, each 0-65535, no leading zeros. Every +# such version is also a valid Firefox version, so one rule covers both stores. valid() { [[ "$1" =~ ^(0|[1-9][0-9]{0,4})(\.(0|[1-9][0-9]{0,4})){0,3}$ ]] || return 1 local IFS=. part diff --git a/.github/workflows/extension-ci.yml b/.github/workflows/extension-ci.yml index 3618b77..7a832dd 100644 --- a/.github/workflows/extension-ci.yml +++ b/.github/workflows/extension-ci.yml @@ -83,11 +83,6 @@ jobs: runs-on: ubuntu-latest needs: changes if: needs.changes.outputs.extension == 'true' - env: - # Pinned for reproducible lint results. To update: bump this, run the - # job, and adjust extension-lint-allowlist.json for new or removed - # warnings (https://github.com/mozilla/web-ext/releases). - WEB_EXT_VERSION: 10.8.0 steps: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 @@ -103,18 +98,13 @@ jobs: - name: Check the package run: node .github/scripts/extension-checks.mjs package "$RUNNER_TEMP/package" - name: web-ext lint - run: | - set -o pipefail # the check's exit code, not tee's - # web-ext exits non-zero on lint errors; the check below reports them. - npx --yes "web-ext@${WEB_EXT_VERSION}" lint \ - --source-dir "$RUNNER_TEMP/package" --output json > "$RUNNER_TEMP/lint.json" || true - node .github/scripts/extension-checks.mjs lint "$RUNNER_TEMP/lint.json" .github/scripts/extension-lint-allowlist.json \ - | tee "$RUNNER_TEMP/lint.txt" + # The same script as the release workflow; web-ext is pinned in it. + run: .github/scripts/extension-lint.sh "$RUNNER_TEMP/package" "$RUNNER_TEMP" - name: Summary if: always() run: | { - echo "### Extension package and Firefox lint (web-ext ${WEB_EXT_VERSION})" + echo "### Extension package and Firefox lint" echo "" if [ -f "$RUNNER_TEMP/lint.txt" ]; then echo '```' diff --git a/.github/workflows/extension-release.yml b/.github/workflows/extension-release.yml index f519b21..9a36f63 100644 --- a/.github/workflows/extension-release.yml +++ b/.github/workflows/extension-release.yml @@ -1,18 +1,31 @@ name: Extension release -# Publishes the Chrome extension when a maintainer pushes a version tag: +# Publishes the extension (one zip for the Chrome Web Store and +# addons.mozilla.org) when a maintainer pushes a version tag: # # git tag -s extension-v0.2.1 -m "Extension v0.2.1" # git push origin extension-v0.2.1 # # Checks that the tag matches extension/manifest.json at the tagged commit and -# that the commit is on main, then attaches -# tts-study-assistant-extension-v.zip to a GitHub Release whose notes -# list only extension/ changes since the previous extension-v* tag. +# that the commit is on main, lints the package with Mozilla's web-ext, then +# attaches tts-study-assistant-extension-v.zip to a GitHub Release +# whose notes list only extension/ changes since the previous extension-v* tag. +# +# addons.mozilla.org: when the AMO_JWT_ISSUER and AMO_JWT_SECRET repository +# secrets are set, the same files are submitted as a listed version, and the +# signed .xpi is attached to the release if AMO signs it within 10 minutes. +# Without the secrets, that job is skipped. The first version must be submitted +# by hand (see extension/README.md). +# +# Run it manually (Actions → Extension release → Run workflow) for a dry run: +# it builds, checks and lints the zip and uploads it as a workflow artifact, +# without a release or an AMO submission. +# # Merging to main releases nothing. on: push: tags: ["extension-v*"] + workflow_dispatch: # Write access applies only to this workflow's token: it creates the release # for the pushed tag. Other workflows stay read-only. @@ -27,50 +40,61 @@ jobs: release: name: Package and release runs-on: ubuntu-latest + outputs: + version: ${{ steps.meta.outputs.version }} + publish: ${{ steps.meta.outputs.publish }} + amo: ${{ steps.amo.outputs.enabled }} env: GH_TOKEN: ${{ github.token }} TAG: ${{ github.ref_name }} + DRY_RUN: ${{ github.event_name != 'push' }} steps: - uses: actions/checkout@v5 with: fetch-depth: 0 # main and all tags, for the checks and the notes + - uses: actions/setup-node@v5 + with: + node-version: 24 - name: Check tag, version and branch id: meta run: | - version="${TAG#extension-v}" - # Chrome's version rules (1-4 integers, 0-65535, no leading zeros). - if ! .github/scripts/extension-version-check.sh "$version" 0 > /dev/null; then - echo "::error::Tag $TAG does not contain a valid Chrome version" && exit 1 - fi manifest=$(jq -er '.version' extension/manifest.json) - if [[ "$manifest" != "$version" ]]; then - echo "::error file=extension/manifest.json::Tag $TAG does not match manifest.json version $manifest at this commit. Delete the tag, bump the manifest (or fix the tag) and tag again." - exit 1 + if [[ "$DRY_RUN" == "true" ]]; then + # Manual run: package whatever manifest.json says on this ref. + version="$manifest" + echo "::notice::Dry run of v${version} from ${GITHUB_REF_NAME}: no release, no AMO submission." + else + version="${TAG#extension-v}" fi - if ! git merge-base --is-ancestor "$GITHUB_SHA" origin/main; then - echo "::error::Tag $TAG points to ${GITHUB_SHA::7}, which is not on main. Tag a commit that has been merged to main." - exit 1 + # Chrome's version rules (1-4 integers, 0-65535, no leading zeros); + # every such version is also valid on addons.mozilla.org. + if ! .github/scripts/extension-version-check.sh "$version" 0 > /dev/null; then + echo "::error::$version is not a valid extension version" && exit 1 fi - exists=false - if gh release view "$TAG" > /dev/null 2>&1; then - exists=true - echo "::notice::Release $TAG already exists; nothing to do." + publish=false + if [[ "$DRY_RUN" != "true" ]]; then + if [[ "$manifest" != "$version" ]]; then + echo "::error file=extension/manifest.json::Tag $TAG does not match manifest.json version $manifest at this commit. Delete the tag, bump the manifest (or fix the tag) and tag again." + exit 1 + fi + if ! git merge-base --is-ancestor "$GITHUB_SHA" origin/main; then + echo "::error::Tag $TAG points to ${GITHUB_SHA::7}, which is not on main. Tag a commit that has been merged to main." + exit 1 + fi + if gh release view "$TAG" > /dev/null 2>&1; then + echo "::notice::Release $TAG already exists; nothing to do." + else + publish=true + fi fi { echo "version=$version" echo "archive=tts-study-assistant-extension-v${version}.zip" - echo "exists=$exists" + echo "publish=$publish" } >> "$GITHUB_OUTPUT" - - name: Write release notes - if: steps.meta.outputs.exists == 'false' - run: | - .github/scripts/extension-release-notes.sh "$TAG" release-notes.md - cat release-notes.md - - name: Create zip - if: steps.meta.outputs.exists == 'false' env: ARCHIVE: ${{ steps.meta.outputs.archive }} run: | @@ -81,8 +105,26 @@ jobs: unzip -q "$ARCHIVE" -d "$RUNNER_TEMP/package" node .github/scripts/extension-checks.mjs package "$RUNNER_TEMP/package" + - name: web-ext lint + # The linter addons.mozilla.org runs on upload; the same script as CI. + run: .github/scripts/extension-lint.sh "$RUNNER_TEMP/package" "$RUNNER_TEMP" + + - name: Upload the zip + uses: actions/upload-artifact@v4 + with: + name: extension-package + path: ${{ steps.meta.outputs.archive }} + if-no-files-found: error + retention-days: 7 + + - name: Write release notes + if: steps.meta.outputs.publish == 'true' + run: | + .github/scripts/extension-release-notes.sh "$TAG" release-notes.md + cat release-notes.md + - name: Create release - if: steps.meta.outputs.exists == 'false' + if: steps.meta.outputs.publish == 'true' env: VERSION: ${{ steps.meta.outputs.version }} ARCHIVE: ${{ steps.meta.outputs.archive }} @@ -92,19 +134,117 @@ jobs: --title "Extension v${VERSION}" \ --notes-file release-notes.md + - name: AMO secrets set? + id: amo + if: steps.meta.outputs.publish == 'true' + env: + # Empty on forks and when the secrets aren't configured. + AMO_JWT_ISSUER: ${{ secrets.AMO_JWT_ISSUER }} + AMO_JWT_SECRET: ${{ secrets.AMO_JWT_SECRET }} + run: | + if [[ -n "$AMO_JWT_ISSUER" && -n "$AMO_JWT_SECRET" ]]; then + echo "enabled=true" >> "$GITHUB_OUTPUT" + else + echo "enabled=false" >> "$GITHUB_OUTPUT" + echo "::notice::AMO_JWT_ISSUER/AMO_JWT_SECRET not set: submit the zip to addons.mozilla.org by hand." + fi + - name: Summary + if: always() env: - EXISTS: ${{ steps.meta.outputs.exists }} + PUBLISH: ${{ steps.meta.outputs.publish }} ARCHIVE: ${{ steps.meta.outputs.archive }} + AMO: ${{ steps.amo.outputs.enabled }} run: | { echo "### Extension release ${TAG}" echo "" - if [[ "$EXISTS" == "true" ]]; then - echo "The release already existed; nothing was changed." + if [[ "$DRY_RUN" == "true" ]]; then + echo "Dry run: \`${ARCHIVE}\` built, checked and linted; download it from this run's artifacts. Nothing was released." + elif [[ "$PUBLISH" == "true" ]]; then + echo "Created release \`${TAG}\` with \`${ARCHIVE}\` from \`${GITHUB_SHA::7}\`, for the Chrome Web Store and addons.mozilla.org." + if [[ "$AMO" == "true" ]]; then + echo "addons.mozilla.org: submitting (see the next job)." + else + echo "addons.mozilla.org: secrets not set; upload the zip by hand." + fi else - echo "Created release \`${TAG}\` with \`${ARCHIVE}\` from \`${GITHUB_SHA::7}\`." + echo "The release already existed or a check failed; nothing was changed." fi echo "" + if [ -f "$RUNNER_TEMP/lint.txt" ]; then + echo '```' + sed 's/^::[a-z]*:://' "$RUNNER_TEMP/lint.txt" + echo '```' + fi echo "[Releases](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/releases)" } >> "$GITHUB_STEP_SUMMARY" + + amo: + name: Submit to addons.mozilla.org + needs: release + # Only for a new release from a tag push, and only when the secrets exist + # (never on forks, pull requests or dry runs). + if: needs.release.outputs.publish == 'true' && needs.release.outputs.amo == 'true' + runs-on: ubuntu-latest + env: + GH_TOKEN: ${{ github.token }} + TAG: ${{ github.ref_name }} + WEB_EXT_VERSION: 10.8.0 # the same as extension-lint.sh + steps: + - uses: actions/checkout@v5 + - uses: actions/setup-node@v5 + with: + node-version: 24 + - name: Download the released zip + uses: actions/download-artifact@v4 + with: + name: extension-package + path: ${{ runner.temp }}/zip + - name: Unzip + # Submit exactly the files in the released zip. + run: | + mkdir "$RUNNER_TEMP/package" + unzip -q "$RUNNER_TEMP"/zip/*.zip -d "$RUNNER_TEMP/package" + - name: web-ext sign (listed) + id: sign + env: + AMO_JWT_ISSUER: ${{ secrets.AMO_JWT_ISSUER }} + AMO_JWT_SECRET: ${{ secrets.AMO_JWT_SECRET }} + run: | + # A listed version may wait for Mozilla's review; give automatic + # signing 10 minutes, then leave the signed file to AMO. + set +e + npx --yes "web-ext@${WEB_EXT_VERSION}" sign \ + --source-dir "$RUNNER_TEMP/package" \ + --artifacts-dir "$RUNNER_TEMP/signed" \ + --channel listed \ + --approval-timeout 600000 \ + --api-key "$AMO_JWT_ISSUER" \ + --api-secret "$AMO_JWT_SECRET" 2>&1 | tee "$RUNNER_TEMP/sign.log" + code=${PIPESTATUS[0]} + set -e + node .github/scripts/extension-checks.mjs amo-result "$code" "$RUNNER_TEMP/sign.log" "$RUNNER_TEMP/signed" >> "$GITHUB_OUTPUT" + - name: Attach the signed .xpi + if: steps.sign.outputs.status == 'signed' + env: + XPI: ${{ steps.sign.outputs.xpi }} + VERSION: ${{ needs.release.outputs.version }} + run: | + signed="$RUNNER_TEMP/tts-study-assistant-firefox-v${VERSION}.xpi" + cp "$XPI" "$signed" + gh release upload "$TAG" "$signed" + - name: Summary + if: always() + env: + STATUS: ${{ steps.sign.outputs.status }} + run: | + { + echo "### addons.mozilla.org" + echo "" + case "$STATUS" in + signed) echo "Submitted and signed; the .xpi is attached to the release." ;; + pending) echo "Submitted; waiting for Mozilla's review. The signed file will be on addons.mozilla.org once approved." ;; + *) echo "Submission failed; see the log. Fix it, then upload the release zip by hand (AMO rejects a version number it has already seen)." ;; + esac + } >> "$GITHUB_STEP_SUMMARY" diff --git a/extension/README.md b/extension/README.md index 5fc7e2b..6f51417 100644 --- a/extension/README.md +++ b/extension/README.md @@ -102,7 +102,9 @@ The engine lives in the background: Chrome's service worker, or Firefox's event Releases are manual: merging to `main` publishes nothing. -1. **Bump the version** in `manifest.json` (and `package.json`) in your PR: patch for fixes, minor for features. The **Extension version bumped** check fails a PR that changes shipped files without raising the version above `main` and the latest release. The Chrome Web Store rejects same-version uploads. +One zip serves both stores (one `manifest.json`; each browser ignores the other's keys). + +1. **Bump the version** in `manifest.json` (and `package.json`) in your PR: patch for fixes, minor for features. The **Extension version bumped** check fails a PR that changes shipped files without raising the version above `main` and the latest release. The Chrome Web Store rejects same-version uploads, and addons.mozilla.org (AMO) rejects any version number it has seen before, even a rejected or deleted one. 2. **Merge the PR.** 3. **Tag the merge commit on `main` and push the tag:** ```sh @@ -112,9 +114,32 @@ Releases are manual: merging to `main` publishes nothing. ``` 4. **The *Extension release* workflow** then: - checks that the tag matches `manifest.json` at that commit and that the commit is on `main`; - - builds `tts-study-assistant-extension-v0.2.1.zip` with `.github/scripts/extension-package.sh` (runtime files only, `manifest.json` at the root) and runs the same package check as Extension CI; - - creates the GitHub Release "Extension v0.2.1", with notes listing the `extension/` commits since the previous tag. -5. **Upload the zip** to the Chrome Web Store, or install it unpacked. + - builds `tts-study-assistant-extension-v0.2.1.zip` with `.github/scripts/extension-package.sh` (runtime files only, `manifest.json` at the root), runs the same package check as Extension CI, and lints it with `web-ext` (AMO's linter) via `.github/scripts/extension-lint.sh`; + - creates the GitHub Release "Extension v0.2.1", with notes listing the `extension/` commits since the previous tag; + - if the AMO secrets are set, submits the same files to AMO as a listed version (see below). +5. **Chrome Web Store:** upload the zip in the [developer dashboard](https://chrome.google.com/webstore/devconsole). +6. **addons.mozilla.org:** done by the workflow when the secrets are set; otherwise upload the zip by hand (below). + +**Dry run:** *Actions → Extension release → Run workflow* builds, checks and lints the zip from any branch and keeps it as a workflow artifact for 7 days. No tag, no release, no AMO submission. + +### addons.mozilla.org + +**First version (by hand, once):** the listing needs details only the web form takes. +1. Sign in at the [AMO Developer Hub](https://addons.mozilla.org/developers/) → *Submit a New Add-on* → *On this site* (listed). +2. Upload the release zip. The add-on ID comes from `browser_specific_settings.gecko.id` and can't change afterwards. +3. Fill in the listing: name, summary, description, categories, the privacy policy URL (`https://tts-study-assistant.vercel.app/privacy-policy`), screenshots and support email. +4. In *Notes to Reviewer*, explain each permission (the table under [Website access](#website-access)) and that `js/config.js` and `js/tts-webspeech.js` are plain source, not minified, so no source upload is needed. +5. Submit. Mozilla signs it after automatic checks and may review it by hand later. + +**Later versions:** upload each release zip as a new version in the Developer Hub, or let the workflow do it: +1. Create API credentials at [Manage API Keys](https://addons.mozilla.org/developers/addon/api/key/). +2. Add them as repository secrets **`AMO_JWT_ISSUER`** (the JWT issuer) and **`AMO_JWT_SECRET`** (the JWT secret): *Settings → Secrets and variables → Actions*. +3. On each tag, the **Submit to addons.mozilla.org** job runs `web-ext sign --channel listed` on the released files. Its summary says one of: + - **Signed:** AMO signed it within 10 minutes; `tts-study-assistant-firefox-v.xpi` is attached to the release. + - **Waiting for review:** submitted, and the signed file appears on AMO once approved. Not a failure. + - **Failed:** for example bad credentials or validation errors. The job fails; fix it and upload by hand. + +Without the secrets, and on forks, the job is skipped, not failed. **Wrong tag?** If the workflow fails because the tag doesn't match the manifest, delete the tag and push a corrected one: ```sh @@ -133,8 +158,7 @@ The **Extension package and Firefox lint** CI job checks what actually ships. Ru ```sh .github/scripts/extension-package.sh /tmp/ext.zip && rm -rf /tmp/ext && unzip -q /tmp/ext.zip -d /tmp/ext node .github/scripts/extension-checks.mjs package /tmp/ext # manifest at the root, both browsers' keys, no dev files, every referenced file present -npx web-ext@10.8.0 lint --source-dir /tmp/ext --output json > /tmp/lint.json -node .github/scripts/extension-checks.mjs lint /tmp/lint.json .github/scripts/extension-lint-allowlist.json +.github/scripts/extension-lint.sh /tmp/ext /tmp/ext-lint # web-ext lint (version pinned in the script) against the allowlist node --test .github/scripts/*.test.mjs # tests for the checks themselves ```