Skip to content

Rerun Failed Workflow #163

Rerun Failed Workflow

Rerun Failed Workflow #163

name: Rerun Failed Workflow
on:
workflow_run:
workflows:
- "Auto Merge Approved PR"
types:
- completed
jobs:
rerun:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'failure' || github.event.workflow_run.conclusion == 'cancelled' }}
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.MY_PAT }}
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '14'
- name: Install dependencies
run: npm install @octokit/rest
- name: Rerun Workflow
id: rerun_workflow
uses: actions/github-script@v7
env:
GITHUB_TOKEN: ${{ secrets.MY_PAT }}
with:
script: |
const { Octokit } = require("@octokit/rest");
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN
});
const workflowName = 'Auto Merge Approved PR';
const response = await octokit.rest.actions.reRunWorkflow({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
});
if (response.status === 201) {
return `Successfully triggered a rerun of the ${workflowName} workflow.`;
} else {
return `Failed to trigger a rerun of the ${workflowName} workflow.`;
}