-
-
Notifications
You must be signed in to change notification settings - Fork 25
81 lines (68 loc) · 2.7 KB
/
staging.yml
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
72
73
74
75
76
77
78
79
80
81
name: Deploy to Staging Environment
on:
workflow_call:
push:
branches:
- dev
permissions:
deployments: write
jobs:
deploy:
runs-on: ubuntu-latest
if: github.repository_owner == 'onesoft-sudo'
steps:
- name: Create Deployment
id: create_deployment
run: |
# Create a deployment
out=$(curl -fSsL -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/deployments \
-d '{"ref": "${{ github.sha }}", "environment": "Staging", "auto_merge": false, "required_contexts": [], "description": "Deploying new release"}');
if [ -z "$out" ]; then
echo "Invalid output"
exit 1;
fi;
id=$(echo $out | jq -r .id);
if [ -z "$id" ]; then
echo "Invalid ID"
exit 1;
fi;
echo "id=$id" >> $GITHUB_OUTPUT;
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set Deployment Status to Pending
run: |
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/deployments/${{ steps.create_deployment.outputs.id }}/statuses \
-d '{"state": "pending", "environment": "Staging"}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy
run: |
curl -fSsL -X POST \
-H 'Authorization: Bearer ${{ secrets.UPDATE_KEY }}' \
https://ci.sudobot.online/deploy-staging.php
- name: Set Deployment Status to Success
if: success()
run: |
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/deployments/${{ steps.create_deployment.outputs.id }}/statuses \
-d '{"state": "success", "environment": "Staging"}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set Deployment Status to Failure
if: failure()
run: |
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/deployments/${{ steps.create_deployment.outputs.id }}/statuses \
-d '{"state": "failure", "environment": "Staging"}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}