Skip to content

Commit c74e93c

Browse files
committed
ci: play around with deployments
1 parent f521a36 commit c74e93c

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

.github/workflows/workflow.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,33 @@ jobs:
2222
deploy:
2323
runs-on: ubuntu-latest
2424
needs: build
25+
outputs:
26+
deployment_id: ${{ steps.create_deployment.outputs.deployment_id }}
2527
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
2628
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+
2752
- name: Download artifact
2853
uses: actions/download-artifact@v4
2954
with:
@@ -37,3 +62,30 @@ jobs:
3762
ssh_host: ${{ secrets.deploy_target }}
3863
ssh_port: ${{ secrets.deploy_port }}
3964
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

Comments
 (0)