Skip to content

Commit 6b67797

Browse files
committed
Avoid duplicate runs per PR. Only rerun the last PR run.
1 parent 4809a88 commit 6b67797

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

src/index.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,25 @@ async function runAction() {
3535
});
3636

3737
const workflowRunsForAffectedPrs = workflowRuns.data.workflow_runs.filter(run => run.pull_requests?.some(pr => prMap[pr.number]));
38-
await Promise.all(workflowRunsForAffectedPrs.map(async run => {
38+
39+
const latestRunPerPullRequestMap = {};
40+
workflowRunsForAffectedPrs.map(workflowRun => {
41+
workflowRun.pull_requests?.map(pr => {
42+
latestRunPerPullRequestMap[pr.number] = Math.max(workflowRun.id, latestRunPerPullRequestMap[pr.number] || 0);
43+
});
44+
});
45+
46+
const latestWorkflowRuns = Object.values(latestRunPerPullRequestMap);
47+
48+
await Promise.all(latestWorkflowRuns.map(async runId => {
3949
try {
40-
await core.info(`Attempting to rerun: ${run.id}`);
50+
await core.info(`Attempting to rerun: ${runId}`);
4151
await octokit.rest.actions.reRunWorkflow({
42-
owner, repo, run_id: run.id
52+
owner, repo, run_id: runId
4353
});
4454
} catch (error) {
45-
core.error(`Failed to automatically retrigger pull request: ${run.pull_requests?.map(pr => pr.number).join(',')}: ${error.status} - ${error.message}`);
55+
const workflowRun = workflowRunsForAffectedPrs.find(run => run.id === runId);
56+
core.error(`Failed to automatically retrigger pull request: ${workflowRun.pull_requests?.map(pr => pr.number).join(',')}: ${error.status} - ${error.message}`);
4657
}
4758
}));
4859
}

0 commit comments

Comments
 (0)