Skip to content

How can I use GitHub Actions to automatically revert a PR if a later job fails? I want to automatically revert a pull request if a particular job in my GitHub Actions pipeline fails, even if previous jobs succeeded. What’s the best way to automate this rollback process? #140805

Closed Answered by AdarshBP
zeto-bit asked this question in General
Discussion options

You must be logged in to vote

To automatically revert a pull request (PR) in GitHub Actions if a later job fails, even if previous jobs succeeded, you can follow these steps:

  1. Setup a Failing Job Check
    You'll need to capture when a specific job fails. This can be done by checking the exit status or using GitHub's failure() function in your workflow.

  2. Trigger a Revert
    To revert the PR, you can use the GitHub API to:

Automatically create a new PR that reverts the changes made by the original PR.
Close or mark the original PR as reverted.
3. Configure a Personal Access Token
To perform the revert programmatically, GitHub Actions needs the correct permissions. You can create a Personal Access Token (PAT) with the nece…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by zeto-bit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants