Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix rereun failed jobs in workflow of github actions #1788

Merged
merged 1 commit into from
Nov 10, 2023
Merged
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
24 changes: 13 additions & 11 deletions .github/workflows/rerun-failed-workflows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
steps:
- name: Check for Command and Access Level
id: check
uses: actions/github-script@v5
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
Expand All @@ -24,25 +24,26 @@ jobs:
});

if (regex.test(comment.data.body)) {
try {
await github.rest.repos.checkUserAccessLevel({
const permissionLevel = await github.rest.repos.getCollaboratorPermissionLevel({
owner: issue.owner,
repo: issue.repo,
username: username,
permission: 'read'
});
return true;
} catch (error) {
console.log(`User ${username} does not have access to rerun failed workflows`);
return false;
}

if (['admin', 'write', 'read'].includes(permissionLevel.data.permission)) {
console.log(`User ${username} with permission ${permissionLevel.data.permission} has access to rerun failed workflows`);
return true;
} else {
console.log(`User ${username} with permission ${permissionLevel.data.permission} does not have access to rerun failed workflows`);
return false;
}
} else {
return false;
}
result-encoding: string
- name: Fetch and rerun failed workflows
if: steps.check.outputs.result == 'true'
uses: actions/github-script@v5
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
Expand All @@ -59,9 +60,10 @@ jobs:
status: 'failure',
});
for (const run of workflows.data.workflow_runs) {
await github.rest.actions.reRunWorkflow({
const result = await github.rest.actions.reRunWorkflowFailedJobs({
owner: issue.owner,
repo: issue.repo,
run_id: run.id,
});
console.log(`reRunWorkflowFailedJobs workflow ${JSON.stringify(run)} with response ${JSON.stringify(result)}`);
}
Loading