diff --git a/.github/actions/standalone-release/action.yml b/.github/actions/standalone-release/action.yml index 9785904..390a0ea 100644 --- a/.github/actions/standalone-release/action.yml +++ b/.github/actions/standalone-release/action.yml @@ -62,6 +62,8 @@ runs: if: inputs.verify-only != 'true' || hashFiles('released-source/scripts/build-sdk.mjs') != '' shell: bash working-directory: released-source + env: + RELEASE_TAG: ${{ inputs.tag }} run: | npm clean-install # Vite embeds the current time. Use the tagged commit time for repeatable HTML. @@ -75,6 +77,10 @@ runs: NODE_OPTIONS="--require=$RUNNER_TEMP/release-clock.cjs" npm run build if [[ -f scripts/build-sdk.mjs ]]; then npm run check:sdk-dist + if [[ -f scripts/sdk-paths.mjs ]] && node -e "import('./scripts/sdk-paths.mjs').then(m => process.exit(typeof m.isArchiveReleaseVersion === 'function' && m.isArchiveReleaseVersion(process.argv[1]) ? 0 : 1))" "$RELEASE_TAG"; then + npm run build:sdk -- --release "$RELEASE_TAG" + npm run check:sdk-dist -- --release "$RELEASE_TAG" + fi fi - name: Verify and publish the standalone HTML @@ -131,6 +137,12 @@ runs: run: | manifest="dist/sdk/v1/${RELEASE_TAG#v}/SHA256SUMS" asset="DecodeBox-SDK-$RELEASE_TAG-SHA256SUMS" + if [[ -f scripts/sdk-paths.mjs ]] && grep -q 'isArchiveReleaseVersion' scripts/sdk-paths.mjs; then + if ! node -e "import('./scripts/sdk-paths.mjs').then(m => process.exit(m.isArchiveReleaseVersion(process.argv[1]) ? 0 : 1))" "$RELEASE_TAG"; then + test ! -e "$manifest" + exit 0 + fi + fi test -s "$manifest" names=$(gh release view "$RELEASE_TAG" --json assets --jq '.assets[].name') if grep -Fxq "$asset" <<< "$names"; then diff --git a/.github/scripts/verify-release-cli.cjs b/.github/scripts/verify-release-cli.cjs index 11edfcb..d1b1b89 100644 --- a/.github/scripts/verify-release-cli.cjs +++ b/.github/scripts/verify-release-cli.cjs @@ -285,6 +285,7 @@ test('the release uploads only HTML and still verifies local and legacy SDK mani const node = action.find(s => s.uses?.startsWith('actions/setup-node@')); assert.equal(node.with['node-version'], "$" + "{{ hashFiles('released-source/scripts/build-sdk.mjs') != '' && '24.18.0' || '22.23.5' }}"); assert.match(action.find(s => s.id === 'build').run, /npm run check:sdk-dist/); + assert.match(action.find(s => s.id === 'build').run, /--release "\$RELEASE_TAG"/); const directory = path.join(f.dir, 'dist/sdk/v1/0.1.2'); fs.mkdirSync(directory, { recursive: true }); const manifest = 'checksums\n'; @@ -299,6 +300,14 @@ test('the release uploads only HTML and still verifies local and legacy SDK mani f.change(s => { s.manifest = 'different bytes'; }); f.shell(step, false); assert.equal(f.read().manifest, 'different bytes'); + // Patch releases under the PATCH=0 policy do not require or expect a versioned archive manifest. + fs.mkdirSync(path.join(f.dir, 'scripts'), { recursive: true }); + fs.copyFileSync(path.resolve(__dirname, '../../scripts/sdk-paths.mjs'), path.join(f.dir, 'scripts/sdk-paths.mjs')); + fs.rmSync(directory, { recursive: true, force: true }); + f.shell(step); + fs.mkdirSync(directory, { recursive: true }); + fs.writeFileSync(path.join(directory, 'SHA256SUMS'), manifest); + f.shell(step, false); }); test('workflow routes are exclusive and formatting requires the baseline and verified upload', t => { @@ -307,13 +316,15 @@ test('workflow routes are exclusive and formatting requires the baseline and ver assert.equal(normal.if, "github.ref == 'refs/heads/main' && inputs.release_tag == '' && inputs.repair_release_notes_tag == ''"); assert.equal(manual.if, "github.ref == 'refs/heads/main' && (inputs.release_tag != '' || inputs.repair_release_notes_tag != '')"); assert.deepEqual(manual.permissions, { contents: 'write', 'pull-requests': 'read' }); - const [conflict, checkout, rebuild, verify, repair] = manual.steps; - assert.equal(manual.steps.length, 5); + const [conflict, checkout, rebuild, rebuildArchive, verify, repair] = manual.steps; + assert.equal(manual.steps.length, 6); assert.equal(conflict.if, "inputs.release_tag != '' && inputs.repair_release_notes_tag != ''"); f.shell(conflict, false); assert(checkout.uses.startsWith('actions/checkout@')); assert.equal(rebuild.if, "inputs.release_tag != '' && inputs.repair_release_notes_tag == ''"); assert.equal(rebuild.uses, './.github/actions/standalone-release'); + assert.equal(rebuildArchive.if, rebuild.if); + assert.match(rebuildArchive.run, /publish-gh-pages\.mjs/); assert.equal(repair.if, "inputs.repair_release_notes_tag != '' && inputs.release_tag == ''"); assert.equal(rebuild.with['replace-standalone'], 'true'); assert.equal(verify.if, repair.if); @@ -322,10 +333,13 @@ test('workflow routes are exclusive and formatting requires the baseline and ver assert.equal(repair.run, 'node .github/scripts/publish-release-notes.cjs repair'); const tail = normal.steps.slice(normal.steps.findIndex(step => step.id === 'release')); assert.deepEqual(tail.map(s => s.id || s.run), ['release', 'baseline', 'standalone', - 'node .github/scripts/publish-release-notes.cjs format', 'node .github/scripts/release-notes.cjs']); + 'node .github/scripts/publish-release-notes.cjs format', 'sdk-archive', 'node .github/scripts/release-notes.cjs']); assert.equal(tail[1].if, "steps.release.outputs.release_created == 'true'"); assert.equal(tail[2].if, "success() && steps.baseline.outcome == 'success'"); assert.equal(tail[3].if, "success() && steps.release.outputs.release_created == 'true' && steps.baseline.outcome == 'success' && steps.standalone.outcome == 'success'"); + assert.equal(tail[4].if, tail[3].if); + assert.match(tail[4].run, /isArchiveReleaseVersion/); + assert.match(tail[4].run, /publish-gh-pages\.mjs/); assert.equal(upload.if, "success() && inputs.verify-only != 'true' && steps.build.outcome == 'success'"); assert.equal(tail[3].env.VERIFIED_DIGEST, '$' + '{{ steps.standalone.outputs.digest }}'); f.standalone(); diff --git a/.github/workflows/deploy-pages.yml b/.github/workflows/deploy-pages.yml index 8e3b5f0..3fa57b3 100644 --- a/.github/workflows/deploy-pages.yml +++ b/.github/workflows/deploy-pages.yml @@ -15,8 +15,9 @@ name: Deploy to GitHub Pages # only warned, and a warning inside a green run is indistinguishable from # nothing at all — the site was blank for an afternoon while every check passed. # -# The branch is force-pushed as a single orphan commit each time. The output is -# generated from source. Each tree carries its immutable SDK release directories forward. +# The branch is updated atomically via compare-and-swap (--force-with-lease) so +# ordinary site + latest SDK deployments and milestone official archive releases +# never overwrite each other's updates. on: push: @@ -27,7 +28,8 @@ on: permissions: contents: read -# One publish at a time, and never cancel one part-way through a force-push. +# Serialize overlapping site deployments; cross-workflow races with milestone +# archive publication are resolved atomically via --force-with-lease retries. concurrency: group: github-pages cancel-in-progress: false @@ -39,8 +41,7 @@ jobs: timeout-minutes: 15 permissions: - # The only privilege in this workflow, and it exists for one command: the - # push to gh-pages at the end. + # The only privilege in this workflow, and it exists for publishing to gh-pages. contents: write pages: read @@ -64,47 +65,19 @@ jobs: - name: Build run: npm run build - - name: Check new SDK artifacts and retain published versions - env: - GH_TOKEN: ${{ github.token }} - run: | - npm run check:sdk-dist - settings=$(gh api "repos/$GITHUB_REPOSITORY/pages") - jq -e '.source.branch == "gh-pages" and .source.path == "/"' <<< "$settings" >/dev/null - domain=$(jq -r '.cname // empty' <<< "$settings") - previous_ref=$(git ls-remote --heads origin refs/heads/gh-pages) - if [[ -n "$previous_ref" ]]; then - git fetch --no-tags --depth=1 origin refs/heads/gh-pages - if [[ -z "$domain" ]] && git cat-file -e FETCH_HEAD:CNAME 2>/dev/null; then - domain=$(git show FETCH_HEAD:CNAME) - fi - if git cat-file -e FETCH_HEAD:sdk 2>/dev/null; then - previous=$(mktemp -d) - git archive FETCH_HEAD sdk | tar -x -C "$previous" - for series in "$previous"/sdk/v*; do - [[ -d "$series" ]] || continue - name=$(basename "$series") - [[ "$name" =~ ^v[0-9]+$ ]] || continue - for release in "$series"/*/; do - target="dist/sdk/$name/$(basename "$release")" - if [[ -d "$release" && -d "$target" ]]; then - diff -qr "$release" "$target" - fi - done - mkdir -p "dist/sdk/$name" - cp -an "$series/." "dist/sdk/$name/" - done - fi - fi - rm -f dist/CNAME - if [[ -n "$domain" ]]; then - printf '%s\n' "$domain" > dist/CNAME - fi - - name: Verify the build is static and complete run: | + npm run check:sdk-dist test -s dist/index.html || { echo "::error::dist/index.html is missing"; exit 1; } test -s dist/decodebox.html || { echo "::error::dist/decodebox.html is missing - the download button would 404"; exit 1; } + node --experimental-vm-modules -e ' + const fs = require("node:fs"); + const vm = require("node:vm"); + const html = fs.readFileSync("dist/decodebox.html", "utf8"); + const match = /