GitHub Actions: Rollback — When a Deploy Goes Wrong
A rollback is a return to the last good version of an app after a bad deploy. It restores the working version while the bad change is fixed.
Re-run the last good run
Open the Actions tab. Pick the last green run. Press Re-run jobs to run it again.
Actions tab > last green run > Re-run jobsUndo the bad commit
A revert is a new commit that undoes an old one. History stays complete.
git revert <bad-commit-sha>
git pushFetch the last good artifact
An artifact is a file a workflow saved, like the built site folder. Download it by name.
- uses: actions/download-artifact@v8
with:
name: dist
path: distExample
name: Rollback Deploy
on:
workflow_dispatch:
inputs:
run-id:
description: 'Run id of the last good run'
required: true
permissions:
contents: read
pages: write
id-token: write
jobs:
redeploy:
runs-on: ubuntu-latest
environment: github-pages
steps:
- uses: actions/checkout@v7
- uses: actions/download-artifact@v8
with:
name: dist
path: dist
run-id: ${{ inputs.run-id }}
- uses: actions/configure-pages@v6
- uses: actions/deploy-pages@v5Key points
- Rollback: a return to a version that worked before the bad deploy.
- Use the last good run to find the version that worked.
- Use git revert to undo a bad commit without erasing history.
- Use download-artifact to fetch the built files from the last good run.
- Redeploy the last good artifact to put the working version live again.
- Fix the bad change on a branch after the rollback, not before it.
- A rollback is a fix for the live site first, and the code second.
In this example, the workflow starts by hand, because a rollback is a human decision. The run-id input names the last good run. The job checks out the repo. It downloads the dist artifact from that run. It sets up Pages. It deploys the old built files. The live site then shows the last good version again.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Rust Playground
Exercise
A deploy has broken the live site. What is the first safe step?