diff --git a/.github/workflows/github-pages.yml b/.github/workflows/github-pages.yml index 9fa39673..8b83a7b7 100644 --- a/.github/workflows/github-pages.yml +++ b/.github/workflows/github-pages.yml @@ -3,7 +3,11 @@ on: push: branches: - main - + +concurrency: + group: pages + cancel-in-progress: false + permissions: contents: read id-token: write @@ -31,7 +35,9 @@ jobs: - name : Upload artifact uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0 with: - name: github-pages + name: github-pages-${{ github.run_attempt }} path: site/_site - name: Deploy to GitHub Pages from artifacts uses: actions/deploy-pages@cd2ce8fcbc39b97be8ca5fce6e763baed58fa128 # v5.0.0 + with: + artifact_name: github-pages-${{ github.run_attempt }} diff --git a/OWNER-CHEATSHEET.md b/OWNER-CHEATSHEET.md index fbbdd5db..75067ce5 100644 --- a/OWNER-CHEATSHEET.md +++ b/OWNER-CHEATSHEET.md @@ -211,6 +211,19 @@ delete retained intents or overwrite a partial branch to force recovery. To stop an active run, cancel it or withdraw the command as well as disabling the activation variable. No activation or live coding run was performed here. +## Website deployments + +The [Pages workflow](./.github/workflows/github-pages.yml) deploys `main`. +Deployments share one concurrency group without cancelling an active publish. +Within each workflow run, every attempt uploads and deploys its matching +`github-pages-` artifact, so retained earlier attempts do not make +artifact selection ambiguous. + +Before retrying a failed deployment, check that a newer successful run has not +superseded it. A rerun uses its original workflow version: after a deployment +fix is merged, follow the new default-branch run instead of retrying an older +failure. No artifact deletion or coding-pilot activation is needed. + ## If something stalls | Symptom | Safe next step | diff --git a/tools/tests/pages-workflow.test.mjs b/tools/tests/pages-workflow.test.mjs new file mode 100644 index 00000000..861820fd --- /dev/null +++ b/tools/tests/pages-workflow.test.mjs @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import assert from "node:assert/strict"; +import fs from "node:fs"; +import test from "node:test"; +import { parse } from "yaml"; + +const workflow = parse(fs.readFileSync(new URL("../../.github/workflows/github-pages.yml", import.meta.url), "utf8")); + +test("Pages deployments share a queue without cancelling an active publish", () => { + assert.deepEqual(workflow.concurrency, { group: "pages", "cancel-in-progress": false }); + assert.equal(workflow.jobs.deploy.concurrency, undefined); +}); + +test("Pages reruns select only their own artifact while retaining earlier attempts", () => { + const uploads = workflow.jobs.deploy.steps.filter(step => step.uses?.startsWith("actions/upload-pages-artifact@")); + const deployments = workflow.jobs.deploy.steps.filter(step => step.uses?.startsWith("actions/deploy-pages@")); + assert.equal(uploads.length, 1); + assert.equal(deployments.length, 1); + const upload = uploads[0]; + const deploy = deployments[0]; + assert.equal(upload.with.name, "github-pages-${{ github.run_attempt }}"); + assert.equal(deploy.with.artifact_name, upload.with.name); + assert.equal(upload.with.path, "site/_site"); + + const artifactName = (template, attempt) => template.replace("${{ github.run_attempt }}", String(attempt)); + const artifacts = [1, 2, 3].map(attempt => ({ + id: attempt, name: artifactName(upload.with.name, attempt), + })); + assert.equal(new Set(artifacts.map(artifact => artifact.name)).size, 3); + for (const attempt of [1, 2, 3]) { + const selected = artifacts.filter(artifact => artifact.name === artifactName(deploy.with.artifact_name, attempt)); + assert.deepEqual(selected.map(artifact => artifact.id), [attempt]); + } +}); + +test("Pages deployment keeps its main-only trigger and existing permissions", () => { + assert.deepEqual(workflow.on, { push: { branches: ["main"] } }); + assert.deepEqual(workflow.permissions, { contents: "read", "id-token": "write", pages: "write" }); + assert.equal(workflow.jobs.deploy.permissions, undefined); + for (const step of workflow.jobs.deploy.steps.filter(step => step.uses)) { + assert.match(step.uses, /^[\w-]+\/[\w-]+@[a-f0-9]{40}$/); + } +});