Why your auto-rollback job can't push the revert to main

GitHub Actions has no built-in automatic rollback, so teams add a job that runs when a deploy fails and reverts the change. Many of these jobs fail in the same few ways, usually at the worst time. Here is the checklist.

1. The token is read-only

The default GITHUB_TOKEN may only be allowed to read repository contents, depending on the repository or organization setting. Pushing a revert then fails with a 403. Give the job the permissions it needs, for example contents: write and pull-requests: write, in the workflow file. A token that was passed in from another workflow can only have its permissions lowered, never raised.

2. There is no checkout, or no git identity

A job that runs git revert needs the code checked out, with enough history to find the commit, and a configured user name and email. Without them the script stops before it reverts anything.

3. Branch protection blocks the push

If your main branch requires pull requests, reviews or status checks, a direct push of the revert is refused. You either allow a bypass for the automation, or open the revert as a pull request and let it go through the same rules. The second is safer, and slower if a human review is required.

4. The revert does not start the redeploy

GitHub does not start new workflow runs for events caused by the GITHUB_TOKEN, to prevent loops. The exceptions are workflow_dispatch and repository_dispatch. So a revert pushed or merged with that token may not trigger your deploy workflow, and production stays on the broken version. Use a GitHub App token or a personal access token for the revert, or call the deploy with workflow_dispatch.

5. The rollback step never runs

A failing earlier step ends the job unless the rollback step is set to run on failure. Use if: failure() on it, and check that the script does not exit early because of a failed command before the revert.

6. The failure does not turn anything red

Some breakages, such as a service that starts and then misbehaves, never fail the workflow. A rollback that only watches the workflow result will miss them. A health check on the live service after the deploy catches more.

7. The revert itself breaks

The revert can conflict with newer commits, or the redeployed old version can fail too. Decide in advance what happens then. Stopping and alerting a person is usually better than retrying in a loop.

What Merge Scheduler does differently

Merge Scheduler works from outside your repository as a GitHub App, so it does not depend on your workflow's token. It merges and reverts with its own installation token, so the push events that start your deploy are fired. It follows your deploy runs, opens the revert as a pull request that respects your branch rules, and stops with a clear message if the redeploy also fails.

Do this in Merge Scheduler: Set up automatic revert for a failed deploy

Related: How to automatically revert a failed deploy (and when not to) · Why a merged pull request didn't start your deploy workflow · How to revert a merge in git (git revert -m 1) and why re-merging does nothing