|
22 | 22 | deploy: |
23 | 23 | runs-on: ubuntu-latest |
24 | 24 | needs: build |
| 25 | + outputs: |
| 26 | + deployment_id: ${{ steps.create_deployment.outputs.deployment_id }} |
25 | 27 | if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' |
26 | 28 | steps: |
| 29 | + - name: Create Deployment |
| 30 | + id: create_deployment |
| 31 | + run: | |
| 32 | + deployment_response=$(curl -fsS -X POST \ |
| 33 | + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ |
| 34 | + -H "Accept: application/vnd.github+json" \ |
| 35 | + https://api.github.com/repos/${{ github.repository }}/deployments \ |
| 36 | + -d '{ |
| 37 | + "ref": "${{ github.sha }}", |
| 38 | + "environment": "staging", |
| 39 | + "auto_merge": false, |
| 40 | + "required_contexts": [], |
| 41 | + "description": "Deploying to staging" |
| 42 | + }') |
| 43 | + deployment_id=$(echo "$deployment_response" | jq -r '.id') |
| 44 | + echo "deployment_id=$id" >> "$GITHUB_OUTPUT" |
| 45 | +
|
| 46 | + curl -fsS -X POST \ |
| 47 | + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ |
| 48 | + -H "Accept: application/vnd.github+json" \ |
| 49 | + https://api.github.com/repos/${{ github.repository }}/deployments/${deployment_id}/statuses \ |
| 50 | + -d '{"state": "in_progress"}' |
| 51 | +
|
27 | 52 | - name: Download artifact |
28 | 53 | uses: actions/download-artifact@v4 |
29 | 54 | with: |
|
37 | 62 | ssh_host: ${{ secrets.deploy_target }} |
38 | 63 | ssh_port: ${{ secrets.deploy_port }} |
39 | 64 | image: questionablextensions |
| 65 | + |
| 66 | + - name: Update Deployment Status |
| 67 | + run: | |
| 68 | + curl -X POST \ |
| 69 | + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ |
| 70 | + -H "Accept: application/vnd.github+json" \ |
| 71 | + https://api.github.com/repos/${{ github.repository }}/deployments/${{ steps.create_deployment.outputs.deployment_id }}/statuses \ |
| 72 | + -d '{ |
| 73 | + "state": "success", |
| 74 | + "description": "Deployment succeeded", |
| 75 | + }' |
| 76 | + |
| 77 | + report-failure: |
| 78 | + runs-on: ubuntu-latest |
| 79 | + needs: deploy |
| 80 | + if: failure() |
| 81 | + steps: |
| 82 | + - name: Report failure to GitHub Deployment |
| 83 | + run: | |
| 84 | + curl -sSL -X POST \ |
| 85 | + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ |
| 86 | + -H "Accept: application/vnd.github+json" \ |
| 87 | + https://api.github.com/repos/${{ github.repository }}/deployments/${{ needs.deploy.outputs.deployment_id }}/statuses \ |
| 88 | + -d '{ |
| 89 | + "state": "failure", |
| 90 | + "description": "Deployment failed", |
| 91 | + }' |
0 commit comments