Skip to content

Roll back from CI

A rollback makes an earlier successful deployment current again, without a build: it takes effect in seconds. It needs a developer key.

Find the deployment

List the environment's deployments, newest first, and pick the last success before the current one:

Terminal
curl "https://api.hiraiship.com/api/v1/environments/$ENVIRONMENT_ID/deployments" \
  -H "Authorization: Bearer $HIRAISHIP_TOKEN" \
| jq -r --arg current "$(curl -s "https://api.hiraiship.com/api/v1/environments/$ENVIRONMENT_ID" -H "Authorization: Bearer $HIRAISHIP_TOKEN" | jq -r .activeDeploymentId)" \
  '[.[] | select(.status == "success" and .id != $current)][0].id'

Roll back

Terminal
curl -X PATCH "https://api.hiraiship.com/api/v1/environments/$ENVIRONMENT_ID/active-deployment" \
  -H "Authorization: Bearer $HIRAISHIP_TOKEN" \
  -H "Content-Type: application/json" \
  -d "{ \"deploymentId\": \"$DEPLOYMENT_ID\" }"

The response is the environment, with the new activeDeploymentId.

  • Only a deployment of this environment that succeeded can be restored. Your plan keeps a limited number of recent successful deployments for rollback: an older one is a 409.
  • The next deployment that succeeds becomes current again, as usual. Roll back again, or fix forward.

As a GitHub Actions job

.github/workflows/rollback.yml
name: Roll back production
 
on:
  workflow_dispatch:
    inputs:
      deployment:
        description: Deployment id to restore
        required: true
 
jobs:
  rollback:
    runs-on: ubuntu-latest
    steps:
      - run: |
          curl --fail-with-body -X PATCH \
            "https://api.hiraiship.com/api/v1/environments/${{ vars.PRODUCTION_ENVIRONMENT_ID }}/active-deployment" \
            -H "Authorization: Bearer $HIRAISHIP_TOKEN" \
            -H "Content-Type: application/json" \
            -d '{ "deploymentId": "${{ inputs.deployment }}" }'
        env:
          HIRAISHIP_TOKEN: ${{ secrets.HIRAISHIP_TOKEN }}