|
| 1 | +name: Promote Staging to Production |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | +jobs: |
| 7 | + promote: |
| 8 | + runs-on: ubuntu-latest |
| 9 | + env: |
| 10 | + GH_TOKEN: ${{ github.token }} |
| 11 | + steps: |
| 12 | + - name: Find latest successful staging deployment |
| 13 | + id: staging |
| 14 | + run: | |
| 15 | + DEPLOYMENT_JSON=$(gh api \ |
| 16 | + -H "Accept: application/vnd.github+json" \ |
| 17 | + repos/${{ github.repository }}/deployments \ |
| 18 | + --jq '.[] | select(.environment == "staging")' | head -n1) |
| 19 | +
|
| 20 | + echo "ref=$(echo "$DEPLOYMENT_JSON" | jq -r '.ref')" >> "$GITHUB_OUTPUT" |
| 21 | + echo "sha=$(echo "$DEPLOYMENT_JSON" | jq -r '.sha')" >> "$GITHUB_OUTPUT" |
| 22 | +
|
| 23 | + - name: Create production deployment |
| 24 | + id: prod_deploy |
| 25 | + run: | |
| 26 | + DEPLOY_ID=$(gh api \ |
| 27 | + -X POST \ |
| 28 | + -H "Accept: application/vnd.github+json" \ |
| 29 | + repos/${{ github.repository }}/deployments \ |
| 30 | + --raw-field ref="${{ steps.staging.outputs.ref }}" \ |
| 31 | + --raw-field sha="${{ steps.staging.outputs.sha }}" \ |
| 32 | + --raw-field environment="production" \ |
| 33 | + --raw-field auto_merge=false \ |
| 34 | + --raw-field required_contexts=[] \ |
| 35 | + --jq '.id') |
| 36 | +
|
| 37 | + echo "id=$DEPLOY_ID" >> "$GITHUB_OUTPUT" |
| 38 | +
|
| 39 | + - name: Set up SSH |
| 40 | + run: | |
| 41 | + mkdir -p ~/.ssh |
| 42 | + echo "${{ secrets.deploy_known_hosts }}" > ~/.ssh/known_hosts |
| 43 | + echo "${{ secrets.deploy_key }}" > ~/.ssh/id |
| 44 | + chmod 600 ~/.ssh/id |
| 45 | + chmod 700 ~/.ssh |
| 46 | +
|
| 47 | + - name: Trigger promote script on server |
| 48 | + run: | |
| 49 | + ssh -i ~/.ssh/id -p ${{ secrets.deploy_port }} ${{ secrets.deploy_user }}@${{ secrets.deploy_target }} sudo promote-staging-to-prod.sh questionablextensions |
| 50 | +
|
| 51 | + - name: Mark deployment as success |
| 52 | + if: success() |
| 53 | + run: | |
| 54 | + gh api \ |
| 55 | + -X POST \ |
| 56 | + -H "Accept: application/vnd.github+json" \ |
| 57 | + repos/${{ github.repository }}/deployments/${{ steps.prod_deploy.outputs.id }}/statuses \ |
| 58 | + -f state="success" |
| 59 | +
|
| 60 | + - name: Mark deployment as failure |
| 61 | + if: failure() |
| 62 | + run: | |
| 63 | + gh api \ |
| 64 | + -X POST \ |
| 65 | + -H "Accept: application/vnd.github+json" \ |
| 66 | + repos/${{ github.repository }}/deployments/${{ steps.prod_deploy.outputs.id }}/statuses \ |
| 67 | + -f state="failure" |
0 commit comments