Skip to content

Commit 0af1cfd

Browse files
authored
ci: handle rewritten publish baseline refs (#257)
This verifies that the previous successful workflow SHA is still an ancestor of the current commit and falls back to a full challenge selection when branch history was rewritten.
1 parent 44213d9 commit 0af1cfd

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

  • .github/actions/determine-modified-challenges

.github/actions/determine-modified-challenges/action.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ runs:
2020
with:
2121
script: |
2222
let ref = "";
23+
const { owner, repo } = context.repo;
24+
const branch = context.ref.replace("refs/heads/", "");
2325
if (context.eventName === "pull_request") {
2426
ref = context.payload.pull_request.base.sha;
2527
} else if (context.eventName === "push") {
2628
const workflowFile = process.env.GITHUB_WORKFLOW_REF.split("@")[0].split("/").pop();
27-
const branch = context.ref.replace("refs/heads/", "");
28-
const { owner, repo } = context.repo;
2929
const runs = await github.rest.actions.listWorkflowRuns({
3030
owner,
3131
repo,
@@ -37,6 +37,22 @@ runs:
3737
const [latest] = runs.data.workflow_runs;
3838
ref = latest ? latest.head_sha : "";
3939
}
40+
if (ref) {
41+
try {
42+
const comparison = await github.rest.repos.compareCommitsWithBasehead({
43+
owner,
44+
repo,
45+
basehead: `${ref}...${context.sha}`,
46+
});
47+
if (!["ahead", "identical"].includes(comparison.data.status)) {
48+
core.warning(`${ref} is not an ancestor of the current commit; branch history may have changed`);
49+
ref = "";
50+
}
51+
} catch {
52+
core.warning(`${ref} could not be compared with the current commit`);
53+
ref = "";
54+
}
55+
}
4056
core.setOutput("ref", ref);
4157
4258
- uses: actions/checkout@v6

0 commit comments

Comments
 (0)