-
Notifications
You must be signed in to change notification settings - Fork 331
55 lines (54 loc) · 1.92 KB
/
release-to-prod.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
name: Release to Production
on:
pull_request:
branches:
- production
types: [closed]
jobs:
release:
if: ${{ github.event.pull_request.merged == true }}
runs-on: ubuntu-latest
permissions:
contents: "read"
id-token: "write"
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get Job ID from PR
run: |
cat > BODY <<'EOF'
${{ github.event.pull_request.body}}
EOF
JOB_ID=$(cat BODY | perl -ne 'print "$1\n" and exit if m/Production Job Id:\s(\w+)/;')
echo "JOB_ID=${JOB_ID}" >> $GITHUB_ENV
- name: Push to Production Server
uses: nick-fields/retry@v2
with:
timeout_minutes: 5
max_attempts: 100
retry_wait_seconds: 5
# If the job isn't created yet, will return {"message":"400 Bad request - Unplayable Job"}
command: |
RES=$(curl "https://gitlab.com/api/v4/projects/${{ vars.GITLAB_PROJECT_ID }}/jobs/${{ env.JOB_ID }}/play" \
--request POST \
--header 'PRIVATE-TOKEN: ${{ secrets.GITLAB_DEPLOYMENT_ACCESS_TOKEN }}')
echo $RES
JOB_ID_DONE=$(echo $RES | jq '.id // empty')
[ -z "$JOB_ID_DONE" ] && exit 1 || exit 0
- name: Poll Production Release
uses: artiz/poll-endpoint@1.0.2
with:
url: https://gitlab.com/api/v4/projects/${{ vars.GITLAB_PROJECT_ID }}/jobs/${{ env.JOB_ID }}?access_token=${{ secrets.GITLAB_DEPLOYMENT_ACCESS_TOKEN }}
method: GET
expect-status: 200
expect-response-regex: '"status":"success"'
timeout: 120000
interval: 3000
- name: Report Status
if: failure()
uses: ravsamhq/notify-slack-action@v2
with:
status: ${{ job.status }}
notify_when: "failure"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_GH_ACTIONS_NOTIFICATIONS }}