|
| 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 | + repos/${{ github.repository }}/deployments \ |
| 29 | + -f ref="${{ steps.staging.outputs.ref }}" \ |
| 30 | + -f sha="${{ steps.staging.outputs.sha }}" \ |
| 31 | + -f environment="production" \ |
| 32 | + -f auto_merge="false" \ |
| 33 | + -f required_contexts="[]" \ |
| 34 | + --jq '.id') |
| 35 | +
|
| 36 | + echo "id=$DEPLOY_ID" >> "$GITHUB_OUTPUT" |
| 37 | +
|
| 38 | + - name: Set up SSH |
| 39 | + run: | |
| 40 | + mkdir -p ~/.ssh |
| 41 | + echo "${{ secrets.deploy_known_hosts }}" > ~/.ssh/known_hosts |
| 42 | + echo "${{ secrets.deploy_key }}" > ~/.ssh/id |
| 43 | + chmod 600 ~/.ssh/id |
| 44 | + chmod 700 ~/.ssh |
| 45 | +
|
| 46 | + - name: Trigger promote script on server |
| 47 | + run: | |
| 48 | + ssh -i ~/.ssh/id -p ${{ secrets.deploy_port }} ${{ secrets.deploy_user }}@${{ secrets.deploy_target }} sudo promote-staging-to-prod.sh questionablextensions |
| 49 | +
|
| 50 | + - name: Mark deployment as success |
| 51 | + if: success() |
| 52 | + run: | |
| 53 | + gh api \ |
| 54 | + -X POST \ |
| 55 | + -H "Accept: application/vnd.github+json" \ |
| 56 | + repos/${{ github.repository }}/deployments/${{ steps.prod_deploy.outputs.id }}/statuses \ |
| 57 | + -f state="success" |
| 58 | +
|
| 59 | + - name: Mark deployment as failure |
| 60 | + if: failure() |
| 61 | + run: | |
| 62 | + gh api \ |
| 63 | + -X POST \ |
| 64 | + -H "Accept: application/vnd.github+json" \ |
| 65 | + repos/${{ github.repository }}/deployments/${{ steps.prod_deploy.outputs.id }}/statuses \ |
| 66 | + -f state="failure" |
0 commit comments