Skip to content
Latchkey

How to Roll Back on a Failed Health Check in GitHub Actions

A deploy that passes CI can still fail in production; a health check plus an automatic rollback limits the blast radius.

Deploy, run a health check, and add an if: failure() step that rolls back to the previous release when the check fails.

Steps

  • Capture the current release id before deploying.
  • Deploy the new release.
  • Run a health check against the live endpoint.
  • Add an if: failure() rollback step that restores the prior release.

Workflow

.github/workflows/deploy.yml
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - id: prev
        run: echo "id=$(./current-release.sh)" >> "${GITHUB_OUTPUT}"
      - run: ./deploy.sh
      - name: Health check
        run: ./healthcheck.sh https://example.com/healthz
      - name: Roll back
        if: failure()
        run: ./rollback.sh "${{ steps.prev.outputs.id }}"

Gotchas

  • Give the health check a retry window; a service may need a moment to warm up.
  • Make rollback idempotent so a re-run does not thrash releases.
  • Latchkey runs deploy-and-verify jobs on cheaper, self-healing runners so a flaky infra step does not trigger a false rollback.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →