-
Notifications
You must be signed in to change notification settings - Fork 4
71 lines (62 loc) · 2.51 KB
/
workflow-dispatch.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
name: Repository Dispatch
on:
repository_dispatch:
types:
- PreSync
- PostSync
- SyncFail
permissions:
deployments: write
jobs:
update-status:
runs-on: ubuntu-latest
steps:
- name: Find deployment ID
id: find-deployment
run: |
# Use GitHub API to find the deployment ID
DEPLOYMENT_ID=$(curl -s -H "Authorization: Bearer ${{ github.token }}" "https://api.github.com/repos/${{ github.repository }}/deployments" | jq -r '.[] | select(.ref == ${{ github.event.client_payload.ref }}) | .id' | head -n 1)
# Output the deployment ID as an output variable
echo "::set-output name=DEPLOYMENT_ID::$DEPLOYMENT_ID"
- name: Check if deployment ID was found
id: check-deployment
run: |
if [ -z "${{ steps.find-deployment.outputs.DEPLOYMENT_ID }}" ]; then
echo "No deployment found for ref: ${{ github.event.client_payload.ref }}"
echo "::set-output name=DEPLOYMENT_FOUND::false"
else
echo "::set-output name=DEPLOYMENT_FOUND::true"
fi
- name: Update deployment status
if: ${{ steps.check-deployment.outputs.DEPLOYMENT_FOUND == 'true' }}
run: |
DEPLOYMENT_ID=${{ steps.find-deployment.outputs.DEPLOYMENT_ID }}
case "${{ github.event.action }}" in
PreSync)
STATUS="in_progress"
DESCRIPTION="Deployment is in progress (PreSync)"
;;
PostSync)
STATUS="success"
DESCRIPTION="Deployment succeeded (PostSync)"
;;
SyncFail)
STATUS="failure"
DESCRIPTION="Deployment failed (SyncFail)"
;;
*)
echo "Unsupported event type: ${{ github.event.action }}"
exit 1
;;
esac
# Use the DEPLOYMENT_ID to update the deployment status
curl -X POST "https://api.github.com/repos/${{ github.repository }}/deployments/$DEPLOYMENT_ID/statuses" \
-H "Authorization: Bearer ${{ github.token }}" \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-d '{
"state": "'"$STATUS"'",
"description": "'"$DESCRIPTION"'",
"log_url": "${{ github.event.client_payload.log_url }}",
"environment_url": "${{ github.event.client_payload.environment_url }}"
}'