name: Rollback (dev)

# Manually roll the dev deployment back to the previously-good image tag (recorded on the VM by the
# deploy in .deployed_tag_prev). Redeploys that tag using the compose file + .env already on the VM.
# This is the manual/dispatch rollback (M15-3); the e2e-triggered auto-rollback is M12's E2E-7,
# built on top of this same path.

on:
  workflow_dispatch:

concurrency:
  # Share the deploy lock so a rollback can never race a deploy.
  group: deploy-dev
  cancel-in-progress: false

jobs:
  rollback:
    runs-on: bloom-arc
    environment: dev
    # packages: read lets the VM pull the previous image with the workflow token.
    permissions:
      contents: read
      packages: read
    steps:
      - name: Check out source
        uses: actions/checkout@v4
        with:
          ref: main

      - name: Roll back the exe.dev VM to the previous image
        env:
          MODE: rollback
          DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
          DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
          REGISTRY_USER: ${{ github.actor }}
          REGISTRY_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: bash scripts/deploy/exedev.sh
