Skip to content

Commit d6d6683

Browse files
dschogitster
authored andcommitted
ci: make the "skip-if-redundant" check more defensive
In 7d78d5f (ci: skip GitHub workflow runs for already-tested commits/trees, 2020-10-08), we added a check that determines whether there is already a workflow run for the given commit (or at least tree), and if found, skips the current run. We just worked around an issue with this check where older runs might unexpectedly miss the `head_commit` attribute. Let's be even more defensive by catching all kinds of exceptions, logging them as warnings, and continue the run without skipping it (after all, if the check fails, we _want_ to continue with the run). This commit is best viewed with the diff option `-w` because it increases the indentation level of the GitHub Action script by two spaces, surrounding it by a `try ... catch` construct. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d0ff1a3 commit d6d6683

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

.github/workflows/main.yml

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -41,35 +41,39 @@ jobs:
4141
with:
4242
github-token: ${{secrets.GITHUB_TOKEN}}
4343
script: |
44-
// Figure out workflow ID, commit and tree
45-
const { data: run } = await github.actions.getWorkflowRun({
46-
owner: context.repo.owner,
47-
repo: context.repo.repo,
48-
run_id: context.runId,
49-
});
50-
const workflow_id = run.workflow_id;
51-
const head_sha = run.head_sha;
52-
const tree_id = run.head_commit.tree_id;
44+
try {
45+
// Figure out workflow ID, commit and tree
46+
const { data: run } = await github.actions.getWorkflowRun({
47+
owner: context.repo.owner,
48+
repo: context.repo.repo,
49+
run_id: context.runId,
50+
});
51+
const workflow_id = run.workflow_id;
52+
const head_sha = run.head_sha;
53+
const tree_id = run.head_commit.tree_id;
5354
54-
// See whether there is a successful run for that commit or tree
55-
const { data: runs } = await github.actions.listWorkflowRuns({
56-
owner: context.repo.owner,
57-
repo: context.repo.repo,
58-
per_page: 500,
59-
status: 'success',
60-
workflow_id,
61-
});
62-
for (const run of runs.workflow_runs) {
63-
if (head_sha === run.head_sha) {
64-
core.warning(`Successful run for the commit ${head_sha}: ${run.html_url}`);
65-
core.setOutput('enabled', ' but skip');
66-
break;
67-
}
68-
if (run.head_commit && tree_id === run.head_commit.tree_id) {
69-
core.warning(`Successful run for the tree ${tree_id}: ${run.html_url}`);
70-
core.setOutput('enabled', ' but skip');
71-
break;
55+
// See whether there is a successful run for that commit or tree
56+
const { data: runs } = await github.actions.listWorkflowRuns({
57+
owner: context.repo.owner,
58+
repo: context.repo.repo,
59+
per_page: 500,
60+
status: 'success',
61+
workflow_id,
62+
});
63+
for (const run of runs.workflow_runs) {
64+
if (head_sha === run.head_sha) {
65+
core.warning(`Successful run for the commit ${head_sha}: ${run.html_url}`);
66+
core.setOutput('enabled', ' but skip');
67+
break;
68+
}
69+
if (run.head_commit && tree_id === run.head_commit.tree_id) {
70+
core.warning(`Successful run for the tree ${tree_id}: ${run.html_url}`);
71+
core.setOutput('enabled', ' but skip');
72+
break;
73+
}
7274
}
75+
} catch (e) {
76+
core.warning(e);
7377
}
7478
7579
windows-build:

0 commit comments

Comments
 (0)