diff --git a/components/pr-convention-policy/lockstep-drift.mjs b/components/pr-convention-policy/lockstep-drift.mjs index 3792dabe..eeeac061 100755 --- a/components/pr-convention-policy/lockstep-drift.mjs +++ b/components/pr-convention-policy/lockstep-drift.mjs @@ -599,8 +599,14 @@ export function parseCompositeNegation(runShText, location) { // otherwise select an artifact the repository does not run and suppress the // one it does. const USES_PREFIX = String.raw`^[^#\n]*\buses:\s*`; -const COMPOSITE_DIRECTORY_PATTERN = COMPOSITE_DIRECTORY.replaceAll(".", "\\."); -// A `uses:` of the composite at `main` or a 40-hex ci-workflows SHA. +// A caller runs `check-contract` directly or through `report-ci-status`, which +// calls it through `$/` at the same commit, so either call site names the +// commit whose `check-contract` gates. +export const REPORT_DIRECTORY = ".github/actions/pr-require-checks/report-ci-status"; +const COMPOSITE_DIRECTORY_PATTERN = `(?:${[COMPOSITE_DIRECTORY, REPORT_DIRECTORY] + .map((directory) => directory.replaceAll(".", "\\.")) + .join("|")})`; +// A `uses:` of either composite at `main` or a 40-hex ci-workflows SHA. const COMPOSITE_PIN_PATTERN = new RegExp( `${USES_PREFIX}melodic-software/ci-workflows/${COMPOSITE_DIRECTORY_PATTERN}@([0-9a-f]{40}|main)(?=[\\s"']|$)`, "m", diff --git a/components/pr-convention-policy/lockstep-drift.test.mjs b/components/pr-convention-policy/lockstep-drift.test.mjs index 9c45abbb..c5df5226 100644 --- a/components/pr-convention-policy/lockstep-drift.test.mjs +++ b/components/pr-convention-policy/lockstep-drift.test.mjs @@ -40,6 +40,7 @@ import { parseValidatorNonClosing, parseValidatorPatterns, parseValidatorSections, + REPORT_DIRECTORY, readGateComposite, requirePinScanToken, resolveConsumerArtifact, @@ -1502,6 +1503,25 @@ test("a reusable consumer is detected at its pin", () => { }); }); +// `report-ci-status` runs `check-contract` through `$/` at the commit the caller +// pins, so its pin names the `check-contract` to check. +test("a consumer on report-ci-status is detected at its pin", () => { + const step = ` - uses: melodic-software/ci-workflows/${REPORT_DIRECTORY}@ebd0e3bed99ae1365fcb4ef47ce97cfa745fcf2f # v0.76.0`; + assert.deepEqual(detectArtifactPin(`jobs:\n ci-status:\n${step}\n`), { + kind: "composite", + sha: "ebd0e3bed99ae1365fcb4ef47ce97cfa745fcf2f", + }); +}); + +test("a self-repository `$/` reference to report-ci-status resolves to main", () => { + assert.deepEqual(detectArtifactPin(` uses: $/${REPORT_DIRECTORY}\n`), { + kind: "composite", + sha: "main", + local: true, + }); + assert.equal(detectArtifactPin(` # - uses: $/${REPORT_DIRECTORY}\n`), null); +}); + test("the composite wins when a repository carries both mid-transition", () => { const both = `jobs:\n linkage:\n${REUSABLE_CALL}\n ci-status:\n${COMPOSITE_STEP}\n`; assert.equal(detectArtifactPin(both).kind, "composite");