diff --git a/.github/workflows/ci-node.yml b/.github/workflows/ci-node.yml index cc463ef..f37c63d 100644 --- a/.github/workflows/ci-node.yml +++ b/.github/workflows/ci-node.yml @@ -52,7 +52,7 @@ on: default: false type: boolean windows: - description: Also run the node jobs on windows-latest, in parallel with ubuntu-latest, in the nightly tier, and in the merge queue and manual runs with windows-merge-queue; callers that cannot run on Windows pass false and say why. Run steps and package scripts use Git Bash there, git checks out with core.autocrlf false and core.symlinks true, and the docker compose services and skill evals are skipped, so tests that need the services must not run on Windows + description: Also run the node jobs on windows-latest, in parallel with ubuntu-latest, in the nightly tier, and in the merge queue and manual runs with windows-merge-queue, only when the calling repository is public; private and internal repositories skip Windows, since we have no Windows runner of our own and GitHub bills their hosted minutes. Callers that cannot run on Windows pass false and say why. Run steps and package scripts use Git Bash there, git checks out with core.autocrlf false and core.symlinks true, and the docker compose services and skill evals are skipped, so tests that need the services must not run on Windows default: true type: boolean windows-merge-queue: @@ -80,8 +80,9 @@ jobs: node: name: ${{ matrix.part == 'test' && 'Test' || matrix.part == 'extra' && 'Extra' || 'Node' }} ${{ matrix.node-version || '.nvmrc' }}${{ matrix.os == 'windows-latest' && ' on Windows' || '' }} # Linux legs on our runners when the CALLING repository's variable RUNNER_CI names a scale set (the - # private repositories: antelope-ci); Windows legs, and every leg when RUNNER_CI is empty or unset - # (every public repository), on GitHub's runners. Set RUNNER_CI per repository, never at organisation + # private repositories: antelope-ci), and on GitHub's runners when RUNNER_CI is empty or unset (every + # public repository). Windows legs run only for a public calling repository, on GitHub's runners: no + # private or internal repository gets one. Set RUNNER_CI per repository, never at organisation # level: the runner group refuses public repositories, and their jobs would wait forever. runs-on: ${{ matrix.os == 'ubuntu-latest' && vars.RUNNER_CI || matrix.os }} permissions: @@ -89,7 +90,7 @@ jobs: strategy: fail-fast: false matrix: - os: ${{ fromJSON(inputs.windows && (github.event_name == 'schedule' || ((github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') && (inputs.windows-merge-queue || inputs.windows-pull-requests))) && '["ubuntu-latest","windows-latest"]' || '["ubuntu-latest"]') }} + os: ${{ fromJSON(inputs.windows && github.event.repository.visibility == 'public' && (github.event_name == 'schedule' || ((github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') && (inputs.windows-merge-queue || inputs.windows-pull-requests))) && '["ubuntu-latest","windows-latest"]' || '["ubuntu-latest"]') }} node-version: ${{ fromJSON(inputs.node-versions || '[""]') }} part: ${{ fromJSON(format('[{0}{1}]', inputs.single-job && inputs.services-compose-file == '' && '"all"' || '"checks","test"', inputs.extra-commands-job && inputs.extra-commands != '' && ',"extra"' || '')) }} defaults: diff --git a/.github/workflows/release-npm.yml b/.github/workflows/release-npm.yml index 64fe08a..d8f563c 100644 --- a/.github/workflows/release-npm.yml +++ b/.github/workflows/release-npm.yml @@ -41,7 +41,7 @@ on: jobs: release: if: (github.event_name != 'push' || github.ref_name == github.event.repository.default_branch) && (github.event_name != 'pull_request' || (contains(github.event.pull_request.labels.*.name, 'preview') && (github.event.action != 'labeled' || github.event.label.name == 'preview'))) - runs-on: ubuntu-latest + runs-on: ${{ github.event.repository.visibility != 'public' && vars.RUNNER_CI || 'ubuntu-latest' }} environment: ${{ github.event_name != 'pull_request' && 'npm-publish' || '' }} concurrency: group: npm-release-${{ github.repository }}-${{ github.event_name }}-${{ github.event.pull_request.number }}-${{ inputs.package-directory }} diff --git a/README.md b/README.md index 8e4a16a..1d5e2ec 100644 --- a/README.md +++ b/README.md @@ -557,7 +557,7 @@ The `node` job runs one job per runner, Node.js version and part: On Windows, the job name ends with ` on Windows`. The jobs run on Linux, also on Windows in the `nightly` tier when `windows` is set, and with `windows-merge-queue` also in the `queue` tier and on manual runs. A pull request -never runs on Windows. +never runs on Windows, and neither does a private or internal repository. Each job picks the tier, then its own work. It runs `pnpm run checks` with `test` in `ANTELOPEJS_CHECKS_SKIP`, since the tests run in a step of their own. @@ -667,7 +667,7 @@ It accepts these optional inputs: | `single-job` | `true` | Run the checks and the tests in one job per runner. Pass `false` to run the tests in a job of their own, in parallel with the checks, when they take minutes. A caller with `services-compose-file` always gets separate jobs. | | `test-job` | `false` | Accepted and ignored. The tests run as a step of the single job, or in a job of their own with `single-job: false`. | | `extra-commands-job` | `false` | Run `extra-commands` in their own job, in parallel with the other checks. Use it only when the commands do not read files that `pnpm run checks` writes, such as a build. | -| `windows` | `true` | Also run the jobs on `windows-latest`, in parallel with `ubuntu-latest`, in the `nightly` tier, and with `windows-merge-queue` in the `queue` tier and on manual runs. Steps and package scripts run in Git Bash, and git checks out with `core.autocrlf false` and `core.symlinks true`. The Windows jobs skip services and the skill evals, so tests that need the services must not run there. A caller that cannot run on Windows passes `false` and states the reason in its workflow. | +| `windows` | `true` | Also run the jobs on `windows-latest`, in parallel with `ubuntu-latest`, in the `nightly` tier, and with `windows-merge-queue` in the `queue` tier and on manual runs. Windows runs only when the calling repository is public. Private and internal repositories skip it: we have no Windows runner of our own, and GitHub bills their hosted minutes. Steps and package scripts run in Git Bash, and git checks out with `core.autocrlf false` and `core.symlinks true`. The Windows jobs skip services and the skill evals, so tests that need the services must not run there. A caller that cannot run on Windows passes `false` and states the reason in its workflow. | | `windows-merge-queue` | `false` | With `windows`, also run the Windows jobs in the `queue` tier and on manual runs. | | `windows-pull-requests` | `false` | Accepted. The former name of `windows-merge-queue`, with the same effect. | | `module-locks` | `false` | After the install, tests and `extra-commands` of each job, run the [module locks committed](#module-locks-committed) action: the job fails when it wrote an `antelope-lock/` file that is not committed, and on a Renovate pull request it uploads what it wrote. Pass `true` in a repository that commits an `antelope-lock/` folder. | @@ -689,9 +689,11 @@ reusable workflow reads the caller's variables, so each private repository sets `RUNNER_CI` to its self-hosted runner scale set, and a public repository sets nothing. Set it per repository, never at the organisation level: a runner group limited to the private repositories would leave a public repository's jobs -waiting. The Windows legs stay on `windows-latest`, and the release workflows stay -on GitHub's runners, because npm provenance needs a GitHub-hosted runner. The -renovate-sync, next-sync and tier-checks jobs follow the same variable. +waiting. The Windows legs run only for a public repository, on `windows-latest`. +The npm release workflows follow `RUNNER_CI` for a private or internal +repository, and a public repository's release stays on `ubuntu-latest`, because +npm provenance needs a GitHub-hosted runner. The renovate-sync, next-sync and +tier-checks jobs follow the same variable. Services start with `docker compose up -d --wait` in the `Test` and `Extra` jobs, and in a `Node ` job only when it runs `extra-commands`. After a @@ -905,9 +907,10 @@ The preset: - runs daily before 4:00 in Europe/Brussels, and rebases a branch only when it conflicts, since the merge queue tests the merged result; - enables GitHub's auto-merge on pin, digest, patch and minor updates, so a - green one enters the merge queue. Majors stay manual, and so does every update - in `cloud`, `antelope-web`, `k8s-gitops-infra`, `antelope-hardening` and - `antelope-compliance`, which have no merge queue. A third-party release waits + green one enters the merge queue. Majors stay manual, and so do 0.x minors, + which can break; a minor from 1.x on keeps auto-merge. Every update in + `cloud`, `antelope-web`, `k8s-gitops-infra`, `antelope-hardening` and + `antelope-compliance` stays manual, since they have no merge queue. A third-party release waits three days before such an update opens; an `@antelopejs` one does not; - reads the module versions that `antelope.config.ts`, `antelope.test.ts`, `src/test/antelope-modules.ts` and `src/test/stack-modules.json` pin, and diff --git a/renovate.json5 b/renovate.json5 index 0802ba6..b5ac3f9 100644 --- a/renovate.json5 +++ b/renovate.json5 @@ -54,6 +54,12 @@ matchRepositories: ['!AntelopeJS/cloud', '!AntelopeJS/antelope-web', '!AntelopeJS/k8s-gitops-infra', '!AntelopeJS/antelope-hardening', '!AntelopeJS/antelope-compliance'], automerge: true, }, + { + description: 'A 0.x minor can break, so it stays manual; 1.x and later keep auto-merge', + matchUpdateTypes: ['minor'], + matchCurrentVersion: '/^v?0\\./', + automerge: false, + }, { description: 'A third-party release waits three days before it can auto-merge, so a compromised version is found and pulled first; a pin has no release date, so it does not wait', matchUpdateTypes: ['pinDigest', 'digest', 'patch', 'minor'], diff --git a/scripts/module-locks/renovate-preset.test.ts b/scripts/module-locks/renovate-preset.test.ts index bd56d2d..67935f3 100644 --- a/scripts/module-locks/renovate-preset.test.ts +++ b/scripts/module-locks/renovate-preset.test.ts @@ -17,6 +17,7 @@ interface Upgrade { repository: string; manager: string; depName: string; + currentVersion: string; updateType: string; packageFile: string; } @@ -42,7 +43,7 @@ async function rules(upgrade: Upgrade): Promise<{ enabled: boolean; groupName?: }; } -const testStack = { repository: "AntelopeJS/dms-mailing", manager: "custom.regex", depName: "@antelopejs/dms", packageFile: "packages/dms-mailing/src/test/antelope-modules.ts" }; +const testStack = { repository: "AntelopeJS/dms-mailing", manager: "custom.regex", depName: "@antelopejs/dms", currentVersion: "1.2.0", packageFile: "packages/dms-mailing/src/test/antelope-modules.ts" }; test("Renovate runs daily in the Brussels night and rebases a branch only on a conflict", () => { assert.deepEqual(config.schedule, ["* 0-3 * * *"]); @@ -62,18 +63,29 @@ test("a patch or minor bump of a test stack module merges through the queue in o test("a major bump stays manual", async () => { assert.equal((await rules({ ...testStack, updateType: "major" })).automerge, false); - assert.equal((await rules({ repository: "AntelopeJS/dms-media", manager: "npm", depName: "vue", updateType: "major", packageFile: "package.json" })).automerge, false); + assert.equal((await rules({ repository: "AntelopeJS/dms-media", manager: "npm", depName: "vue", currentVersion: "3.4.0", updateType: "major", packageFile: "package.json" })).automerge, false); +}); + +test("a 0.x minor stays manual, while a 0.x patch and a minor from 1.x on merge on their own", async () => { + const action = { repository: "AntelopeJS/dms-media", manager: "github-actions", depName: "pnpm/action-setup", packageFile: ".github/workflows/ci.yml" }; + for (const currentVersion of ["0.4.0", "0.0.3"]) { + assert.equal((await rules({ ...testStack, currentVersion, updateType: "minor" })).automerge, false, currentVersion); + assert.equal((await rules({ ...testStack, currentVersion, updateType: "patch" })).automerge, true, currentVersion); + } + assert.equal((await rules({ ...action, currentVersion: "v0.4.0", updateType: "minor" })).automerge, false); + for (const currentVersion of ["1.0.0", "10.2.0"]) assert.equal((await rules({ ...testStack, currentVersion, updateType: "minor" })).automerge, true, currentVersion); + assert.equal((await rules({ ...action, currentVersion: "v4.1.0", updateType: "minor" })).automerge, true); }); test("a repository without a merge queue never merges on its own", async () => { for (const repository of ["AntelopeJS/cloud", "AntelopeJS/antelope-web", "AntelopeJS/k8s-gitops-infra", "AntelopeJS/antelope-hardening", "AntelopeJS/antelope-compliance"]) { assert.equal((await rules({ ...testStack, repository, updateType: "patch", packageFile: "antelope.config.ts" })).automerge, false, repository); - assert.equal((await rules({ repository, manager: "npm", depName: "vue", updateType: "minor", packageFile: "package.json" })).automerge, false, repository); + assert.equal((await rules({ repository, manager: "npm", depName: "vue", currentVersion: "3.4.0", updateType: "minor", packageFile: "package.json" })).automerge, false, repository); } }); test("a third-party release waits three days before it can merge on its own", async () => { - const vue = { repository: "AntelopeJS/dms-media", manager: "npm", depName: "vue", packageFile: "package.json" }; + const vue = { repository: "AntelopeJS/dms-media", manager: "npm", depName: "vue", currentVersion: "3.4.0", packageFile: "package.json" }; assert.deepEqual(await rules({ ...vue, updateType: "minor" }), { enabled: true, groupName: undefined, automerge: true, minimumReleaseAge: "3 days" }); assert.equal((await rules({ ...vue, updateType: "major" })).minimumReleaseAge, undefined); assert.equal((await rules({ ...vue, updateType: "pin" })).minimumReleaseAge, undefined); @@ -82,7 +94,7 @@ test("a third-party release waits three days before it can merge on its own", as test("only the module managers read **/test/**", async () => { assert.equal((await rules({ ...testStack, updateType: "patch" })).enabled, true); - assert.equal((await rules({ repository: "AntelopeJS/dms-media", manager: "npm", depName: "vue", updateType: "minor", packageFile: "packages/dms-media/src/test/fixture/package.json" })).enabled, false); + assert.equal((await rules({ repository: "AntelopeJS/dms-media", manager: "npm", depName: "vue", currentVersion: "3.4.0", updateType: "minor", packageFile: "packages/dms-media/src/test/fixture/package.json" })).enabled, false); }); test("the custom managers read every shape a project or a test stack pins a module in", () => { diff --git a/scripts/release-train/workflows.test.ts b/scripts/release-train/workflows.test.ts index fe3dedd..b961a2a 100644 --- a/scripts/release-train/workflows.test.ts +++ b/scripts/release-train/workflows.test.ts @@ -52,6 +52,7 @@ interface Scope { steps?: object; inputs?: object; github?: object; + vars?: object; } function evaluate(expression: string, scope: Scope): unknown { @@ -63,7 +64,7 @@ function evaluate(expression: string, scope: Scope): unknown { .replace(/!=/g, "!=="); assert.doesNotMatch(source, /\*/, `the test cannot evaluate ${expression}`); const contains = (list: string[], item: string): boolean => list.includes(item); - return new Function("steps", "inputs", "github", "contains", `return (${source})`)(scope.steps, scope.inputs, scope.github, contains); + return new Function("steps", "inputs", "github", "vars", "contains", "fromJSON", `return (${source})`)(scope.steps, scope.inputs, scope.github, scope.vars, contains, JSON.parse); } function interpolate(template: string, scope: Scope): string { @@ -1271,6 +1272,17 @@ describe("release-npm.yml", () => { for (const mode of ["preview", "pull-request", "stable"]) assert.equal(runs("Push the stable ranges", mode), false, mode); }); + test("the job runs on the caller's RUNNER_CI runner for a private or internal repository when it is set, and on ubuntu-latest otherwise, and always for a public one", () => { + const runsOn = /^ {4}runs-on: (.*)$/m.exec(text)?.[1] ?? ""; + const runner = (visibility: string, vars: object) => evaluate(runsOn, { github: { event: { repository: { visibility } } }, vars }); + assert.equal(runner("private", { RUNNER_CI: "antelope-ci" }), "antelope-ci"); + assert.equal(runner("internal", { RUNNER_CI: "antelope-ci" }), "antelope-ci"); + assert.equal(runner("private", {}), "ubuntu-latest"); + assert.equal(runner("private", { RUNNER_CI: "" }), "ubuntu-latest"); + assert.equal(runner("public", { RUNNER_CI: "antelope-ci" }), "ubuntu-latest"); + assert.equal(runner("public", {}), "ubuntu-latest"); + }); + test("the job runs a push only of the default branch, and a pull request only when it carries the preview label, a labeled event only for that label", () => { const job = /^ {4}if: (.*)$/m.exec(text)?.[1] ?? ""; const gate = (event: string, action: string, labels: string[], label = "", branch = "main") => @@ -1346,6 +1358,26 @@ describe("release-npm.yml", () => { }); }); +describe("ci-node.yml", () => { + test("Windows legs join the matrix only for a public repository, and only in the tiers that ran them before", () => { + const matrix = /^ {8}os: (.*)$/m.exec(workflowText("ci-node.yml"))?.[1] ?? ""; + const os = (visibility: string, event: string, inputs: object): unknown => + evaluate(matrix, { github: { event_name: event, event: { repository: { visibility } } }, inputs }); + const events = ["schedule", "merge_group", "workflow_dispatch", "pull_request", "push"]; + for (const visibility of ["public", "private", "internal"]) { + for (const event of events) { + for (const [windows, queue, pullRequests] of [[true, false, false], [true, true, false], [true, false, true], [true, true, true], [false, true, false], [false, false, false]]) { + const inputs = { windows, "windows-merge-queue": queue, "windows-pull-requests": pullRequests }; + const manual = event === "merge_group" || event === "workflow_dispatch"; + const before = windows && (event === "schedule" || (manual && (queue || pullRequests))); + const expected = visibility === "public" && before ? ["ubuntu-latest", "windows-latest"] : ["ubuntu-latest"]; + assert.deepEqual(os(visibility, event, inputs), expected, `${visibility} ${event} ${JSON.stringify(inputs)}`); + } + } + } + }); +}); + test("the starter workflow is the frozen caller that antelopejs-sync writes", () => { const template = readFileSync(new URL("../../workflow-templates/npm-release.yml", import.meta.url), "utf8"); assert.equal(template, readFileSync(new URL("./frozen-caller.yml", import.meta.url), "utf8"));