Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions components/pr-convention-policy/lockstep-drift.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 20 additions & 0 deletions components/pr-convention-policy/lockstep-drift.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
parseValidatorNonClosing,
parseValidatorPatterns,
parseValidatorSections,
REPORT_DIRECTORY,
readGateComposite,
requirePinScanToken,
resolveConsumerArtifact,
Expand Down Expand Up @@ -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");
Expand Down
Loading