diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..537eca3 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,159 @@ +name: Release + +on: + push: + tags: + - "v*" + +permissions: {} + +concurrency: + group: release-${{ github.ref_name }} + cancel-in-progress: false + +jobs: + build: + name: Verify and build release + runs-on: ubuntu-latest + timeout-minutes: 15 + permissions: + contents: read + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Verify release tag + env: + RELEASE_TAG: ${{ github.ref_name }} + run: | + [[ "$RELEASE_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-rc\.[1-9][0-9]*)?$ ]] + test "$(git rev-parse HEAD)" = "$(git rev-parse "refs/tags/$RELEASE_TAG^{commit}")" + + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version-file: .nvmrc + check-latest: true + cache: npm + + - name: Install dependencies without lifecycle scripts + run: npm ci --ignore-scripts + + - name: Audit dependencies + run: npm audit --audit-level=moderate + + - name: Type-check + run: npm run typecheck + + - name: Check formatting + run: npm run lint + + - name: Run unit tests + run: npm test + + - name: Test release validation and packaging + run: npm run test:release + + - name: Build extension + run: npm run build + + - name: Prepare release metadata + env: + RELEASE_TAG: ${{ github.ref_name }} + run: bash scripts/prepare-release.sh "$RELEASE_TAG" + + - name: Install test browser + run: npm exec --no -- playwright install --with-deps chromium + + - name: Run Chromium extension tests + run: npm run test:e2e + + - name: Package extension + run: bash scripts/package.sh + + - name: Upload verified release assets + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: github-status-extension + path: artifacts/* + if-no-files-found: error + retention-days: 14 + + - name: Upload browser failure diagnostics + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + if: failure() + with: + name: browser-test-results + path: test-results/ + if-no-files-found: ignore + retention-days: 7 + + publish: + name: Publish GitHub release + needs: build + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + contents: write + steps: + - name: Download verified release assets + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: github-status-extension + path: artifacts + + - name: Verify package checksum + working-directory: artifacts + run: shasum -a 256 -c ./*.sha256 + + - name: Create draft release + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + RELEASE_TAG: ${{ github.ref_name }} + run: | + [[ "$RELEASE_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-rc\.[1-9][0-9]*)?$ ]] + release_flags=(--latest=false) + if [[ "$RELEASE_TAG" == *-rc.* ]]; then + release_flags+=(--prerelease) + else + release_flags=(--latest) + fi + cat > "$RUNNER_TEMP/release-notes.md" <<'NOTES' + Download the ZIP and its SHA-256 checksum below. Extract the ZIP to a folder, open chrome://extensions, enable Developer mode, and choose Load unpacked to select that folder. + + This release is for manual installation. It is not published to the Chrome Web Store. GitHub is the only supported provider in this version. + NOTES + gh release create "$RELEASE_TAG" --draft \ + --verify-tag --title "$RELEASE_TAG" \ + --notes-file "$RUNNER_TEMP/release-notes.md" \ + --generate-notes "${release_flags[@]}" + + - name: Upload all release assets before publication + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + RELEASE_TAG: ${{ github.ref_name }} + run: gh release upload "$RELEASE_TAG" artifacts/* + + - name: Verify uploaded assets + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + RELEASE_TAG: ${{ github.ref_name }} + run: | + gh release download "$RELEASE_TAG" --pattern '*.zip' --pattern '*.sha256' --dir "$RUNNER_TEMP/release-verification" + cd "$RUNNER_TEMP/release-verification" + shasum -a 256 -c ./*.sha256 + + - name: Publish immutable release + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + RELEASE_TAG: ${{ github.ref_name }} + run: | + latest=true + if [[ "$RELEASE_TAG" == *-rc.* ]]; then + latest=false + fi + gh release edit "$RELEASE_TAG" --draft=false --latest="$latest" diff --git a/README.md b/README.md index 778f8c2..baada4f 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ The first version includes the overall status, affected-first service list, acti ## Build and install -Requires Node.js 26 LTS or newer and npm. The `.nvmrc` file selects Node 26 for local development and CI; run `nvm install && nvm use` if you use nvm. Bash and zip are used for packaging. +Requires Node.js 26 LTS or newer and npm. The `.nvmrc` file selects Node 26 for local development and CI; run `nvm install && nvm use` if you use nvm. Bash, jq, zip, and shasum are used for packaging. ```bash npm ci --ignore-scripts @@ -19,7 +19,25 @@ Open `chrome://extensions`, enable **Developer mode**, choose **Load unpacked**, npm run package ``` -The distributable is `artifacts/github-status-extension-0.1.0.zip`. It contains compiled extension code and assets only. It is not automatically published to the Chrome Web Store. +The distributable is `artifacts/github-status-extension-0.1.0.zip`, accompanied by a `.zip.sha256` checksum. It contains compiled extension code and assets only. It is not automatically published to the Chrome Web Store. + +## Releases and release candidates + +Push a tag matching the version in both `package.json` and `public/manifest.json`: `v0.1.0` for a stable release, or `v0.1.0-rc.1` for a release candidate. The dedicated Release workflow runs its own validation, tests, and build without calling CI, stamps `version_name` into the built manifest, and publishes the ZIP and SHA-256 checksum to GitHub Releases. RC tags are marked as prereleases and do not become the latest stable release. Chrome's numeric `version` remains `0.1.0` for this release series. + +The dedicated Release workflow runs only when a version tag is pushed; it has no manual trigger. It verifies the tag points at the checked-out source and refuses version mismatches. Only the publishing job has repository write permissions; it downloads the tested artifact and verifies the checksum without checking out or executing project code. + +The repository enables release immutability. Publication creates a draft, uploads every asset, downloads and verifies the uploaded package, and only then publishes the draft. Published assets and tags are never replaced. If publication fails, the release stays unpublished; fix the issue and cut a new RC instead of overwriting assets. Future cosign signatures must be included before publication. + +To test a published RC, download and extract its ZIP, open `chrome://extensions`, enable **Developer mode**, and choose **Load unpacked** with the extracted directory. To verify the download, put the ZIP and checksum in the same directory and run `shasum -a 256 -c github-status-extension-0.1.0-rc.1.zip.sha256`. + +To prepare an RC locally without publishing: + +```bash +npm run build +bash scripts/prepare-release.sh v0.1.0-rc.1 +bash scripts/package.sh +``` ## Validation @@ -27,6 +45,7 @@ The distributable is `artifacts/github-status-extension-0.1.0.zip`. It contains npm run typecheck npm run lint npm test +npm run test:release npm run build npx playwright install chromium npm run test:e2e diff --git a/package-lock.json b/package-lock.json index efa09e5..853b384 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,7 @@ "name": "github-status-extension", "version": "0.1.0", "devDependencies": { - "@playwright/test": "1.56.1", + "@playwright/test": "1.65.0", "@types/chrome": "0.1.24", "@types/node": "24.10.0", "prettier": "3.6.2", @@ -19,19 +19,19 @@ } }, "node_modules/@playwright/test": { - "version": "1.56.1", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.56.1.tgz", - "integrity": "sha512-vSMYtL/zOcFpvJCW71Q/OEGQb7KYBPAdKh35WNSkaZA75JlAO8ED8UN6GUNTm3drWomcbcqRPFqQbLae8yBTdg==", + "version": "1.65.0", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.65.0.tgz", + "integrity": "sha512-iGURLGuKDLakSEl7Pgfv8h7f+XLT+V861Wfhz0zlEl5nyFuKUopdkFBPKqTllTUp06aOwPuH8iuUEb3yp3MpbQ==", "dev": true, "license": "Apache-2.0", "dependencies": { - "playwright": "1.56.1" + "playwright": "1.65.0" }, "bin": { "playwright": "cli.js" }, "engines": { - "node": ">=18" + "node": ">=20" } }, "node_modules/@types/chrome": { @@ -79,51 +79,33 @@ "undici-types": "~7.16.0" } }, - "node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, - "hasInstallScript": true, - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, "node_modules/playwright": { - "version": "1.56.1", - "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.56.1.tgz", - "integrity": "sha512-aFi5B0WovBHTEvpM3DzXTUaeN6eN0qWnTkKx4NQaH4Wvcmc153PdaY2UBdSYKaGYw+UyWXSVyxDUg5DoPEttjw==", + "version": "1.65.0", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.65.0.tgz", + "integrity": "sha512-F3AMWcR44qMBt4kq+6Kb6mX7bjGXshktKFOPULd7reED6ZJWevjbNRqysP7q+AATE9kdPEZBibex1BYsvpVoeA==", "dev": true, "license": "Apache-2.0", "dependencies": { - "playwright-core": "1.56.1" + "playwright-core": "1.65.0" }, "bin": { "playwright": "cli.js" }, "engines": { - "node": ">=18" - }, - "optionalDependencies": { - "fsevents": "2.3.2" + "node": ">=20" } }, "node_modules/playwright-core": { - "version": "1.56.1", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.56.1.tgz", - "integrity": "sha512-hutraynyn31F+Bifme+Ps9Vq59hKuUCz7H1kDOcBs+2oGguKkWTU50bBWrtz34OUWmIwpBTWDxaRPXrIXkgvmQ==", + "version": "1.65.0", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.65.0.tgz", + "integrity": "sha512-vNSKgH6YqtN7cdT/L334zo0a+YwkrpicyrHJlWWPIm/Q+Nn2SWInil01oT0mbu96U4GgoRtCYQD9CzJQgju+lA==", "dev": true, "license": "Apache-2.0", "bin": { "playwright-core": "cli.js" }, "engines": { - "node": ">=18" + "node": ">=20" } }, "node_modules/prettier": { diff --git a/package.json b/package.json index bd6a264..28f885e 100644 --- a/package.json +++ b/package.json @@ -13,10 +13,11 @@ "build": "bash scripts/build.sh", "test": "tsc -p tsconfig.test.json && node --test .test/tests/*.test.js", "test:e2e": "playwright test", + "test:release": "bash tests/release.test.sh", "package": "npm run build && bash scripts/package.sh" }, "devDependencies": { - "@playwright/test": "1.56.1", + "@playwright/test": "1.65.0", "@types/chrome": "0.1.24", "@types/node": "24.10.0", "prettier": "3.6.2", diff --git a/scripts/package.sh b/scripts/package.sh index 7efe9fa..7a81e4f 100644 --- a/scripts/package.sh +++ b/scripts/package.sh @@ -1,6 +1,13 @@ #!/usr/bin/env bash set -euo pipefail cd "$(dirname "$0")/.." +package_version=$(jq -er '.version_name // .version' dist/manifest.json) +if [[ ! "$package_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-rc\.[1-9][0-9]*)?$ ]]; then + echo 'Invalid package version' >&2 + exit 1 +fi mkdir -p artifacts -rm -f artifacts/github-status-extension-0.1.0.zip -(cd dist && zip -qr ../artifacts/github-status-extension-0.1.0.zip .) +archive="github-status-extension-$package_version.zip" +rm -f "artifacts/$archive" +(cd dist && zip -qr "../artifacts/$archive" .) +(cd artifacts && shasum -a 256 "$archive" > "$archive.sha256") diff --git a/scripts/prepare-release.sh b/scripts/prepare-release.sh new file mode 100644 index 0000000..a3a89e6 --- /dev/null +++ b/scripts/prepare-release.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +set -euo pipefail +cd "$(dirname "$0")/.." +release_tag=${1:?Usage: prepare-release.sh vX.Y.Z[-rc.N]} +if [[ ! "$release_tag" =~ ^v([0-9]+\.[0-9]+\.[0-9]+)(-rc\.[1-9][0-9]*)?$ ]]; then + echo 'Expected a tag in the form vX.Y.Z or vX.Y.Z-rc.N' >&2 + exit 1 +fi +base_version=${BASH_REMATCH[1]} +package_version=$(jq -er .version package.json) +manifest_version=$(jq -er .version dist/manifest.json) +if [[ "$package_version" != "$base_version" || "$manifest_version" != "$base_version" ]]; then + echo 'Tag, package.json, and manifest.json versions must match' >&2 + exit 1 +fi +# Chrome requires a numeric version; version_name carries the RC suffix. +jq --arg version "${release_tag#v}" '.version_name = $version' dist/manifest.json > dist/manifest.release.json +mv dist/manifest.release.json dist/manifest.json diff --git a/tests/release.test.sh b/tests/release.test.sh new file mode 100644 index 0000000..8257bfb --- /dev/null +++ b/tests/release.test.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +set -euo pipefail +project_dir=$(cd "$(dirname "$0")/.." && pwd) +test_dir=$(mktemp -d) +trap 'rm -rf "$test_dir"' EXIT +mkdir -p "$test_dir/scripts" "$test_dir/dist" +cp "$project_dir/scripts/prepare-release.sh" "$project_dir/scripts/package.sh" "$test_dir/scripts/" +printf '{"version":"0.1.0"}\n' > "$test_dir/package.json" +printf '{"version":"0.1.0","manifest_version":3}\n' > "$test_dir/dist/manifest.json" +cd "$test_dir" +for invalid in 'v0.1.0-rc.0' 'v0.1.0-beta.1' '0.1.0' 'v0.2.0' 'v0.1.0/../../x' 'v0.1.0;echo bad'; do + if bash scripts/prepare-release.sh "$invalid" >/dev/null 2>&1; then + echo "Unexpectedly accepted invalid release tag: $invalid" >&2 + exit 1 + fi +done +test "$(jq -r '.version_name // "missing"' dist/manifest.json)" = missing +bash scripts/prepare-release.sh v0.1.0-rc.1 +test "$(jq -r .version dist/manifest.json)" = 0.1.0 +test "$(jq -r .version_name dist/manifest.json)" = 0.1.0-rc.1 +bash scripts/package.sh +(cd artifacts && shasum -a 256 -c github-status-extension-0.1.0-rc.1.zip.sha256) +test "$(unzip -p artifacts/github-status-extension-0.1.0-rc.1.zip manifest.json | jq -r .version_name)" = 0.1.0-rc.1 +bash scripts/prepare-release.sh v0.1.0 +bash scripts/package.sh +test -f artifacts/github-status-extension-0.1.0.zip +jq '.version = "0.2.0"' dist/manifest.json > dist/mismatch.json +mv dist/mismatch.json dist/manifest.json +if bash scripts/prepare-release.sh v0.1.0 >/dev/null 2>&1; then + echo 'Unexpectedly accepted mismatched manifest version' >&2 + exit 1 +fi +jq '.version_name = "../../bad"' dist/manifest.json > dist/invalid.json +mv dist/invalid.json dist/manifest.json +if bash scripts/package.sh >/dev/null 2>&1; then + echo 'Unexpectedly accepted invalid package filename' >&2 + exit 1 +fi +echo 'Release validation and packaging tests passed.'