name: 3 | Push staging -> prod

# This CI job is responsible for force pushing the content of releases/staging to releases/prod. It
# is restricted to web-reviewers through virtue of the GitHub environment protection rules for the
# prod environment.

on:
  workflow_dispatch:

jobs:
  push-prod:
    name: 'Push to prod branch'
    runs-on: ubuntu-latest
    environment:
      name: push/prod
    steps:
      - name: Check test status
        uses: actions/github-script@v6.4.1
        with:
          script: |
            const statuses = await github.rest.repos.listCommitStatusesForRef({
              owner: context.repo.owner,
              repo: context.repo.repo,
              ref: context.sha
            })
            const status = statuses.data.find(status => status.context === 'Test / promotion')?.state || 'missing'
            core.info('Status: ' + status)
            if (status !== 'success') {
              core.setFailed('"Test / promotion" must be successful before pushing')
            }

      - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab
        with:
          token: ${{ secrets.RELEASE_SERVICE_ACCESS_TOKEN }}
          ref: releases/staging
      - name: Git config
        run: |
          git config user.name "UL Service Account"
          git config user.email "hello-happy-puppy@users.noreply.github.com"
      - name: Git push
        run: |
          git push origin releases/staging:releases/prod --force
