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
-
Select Topic AreaQuestion BodyHow can I use GitHub Actions to automatically revert a PR if a later job fails? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
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:
Automatically create a new PR that reverts the changes made by the original PR.
name: PR with Auto-Revert on: jobs:
revert_on_failure:
|
Beta Was this translation helpful? Give feedback.
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:
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.
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…