This repository has been archived by the owner on Apr 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
118 lines (109 loc) · 4.03 KB
/
staging-comment.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
name: Build Staging on /staging PR Comment
on:
issue_comment:
types:
- created
jobs:
build-and-push-to-gcr:
name: Build Staging (/staging)
runs-on: ubuntu-latest
if: ${{ github.event.issue.pull_request && github.event.comment.body == '/staging' }}
steps:
- name: React to Comment
uses: actions/github-script@v6
with:
script: |
const {owner, repo} = context.issue;
github.rest.reactions.createForIssueComment({
owner,
repo,
comment_id: context.payload.comment.id,
content: "rocket",
});
- name: Get PR SHA
id: sha
uses: actions/github-script@v6
with:
result-encoding: string
script: |
const { owner, repo, number } = context.issue;
const pr = await github.rest.pulls.get({
owner,
repo,
pull_number: number,
});
return pr.data.head.sha
- name: Status pending
id: statusCheck
uses: actions/github-script@v6
with:
result-encoding: string
script: |
const { owner, repo, number } = context.issue;
const check = await github.rest.checks.create({
owner,
repo,
name: "Staging Image Check",
head_sha: '${{ steps.sha.outputs.result }}',
status: "in_progress",
output: {
title: "Building Staging Image",
summary: `You can check the github action status [here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).`
}
});
return check.data.id;
- name: Github Checkout
uses: actions/checkout@v3
with:
ref: ${{ steps.sha.outputs.result }}
- name: Generate build ID
id: build_id
run: |
sha=$(echo ${{ steps.sha.outputs.result }} | cut -c -8)
ts=$(date +%s)
echo "BUILD_ID=staging-${sha}-${ts}" >> $GITHUB_OUTPUT
- uses: whoan/docker-build-with-cache-action@v5
with:
username: _json_key
password: '${{ secrets.GCR_JSON_KEY }}'
registry: gcr.io
image_name: oscar
image_tag: latest,${{ steps.build_id.outputs.BUILD_ID }}
- name: Status success
if: ${{ success() }}
uses: actions/github-script@v6
with:
script: |
const { owner, repo, number } = context.issue;
github.rest.checks.update({
owner,
repo,
name: "Staging Image Check",
head_sha: '${{ steps.sha.outputs.result }}',
check_run_id: ${{ steps.statusCheck.outputs.result }},
status: "completed",
conclusion: "success",
output: {
title: "Staging Image Built",
summary: `**Built \`${{ steps.build_id.outputs.BUILD_ID }}\` staging image! ✅** You can check the github action status [here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).`
}
});
- name: Status failure
if: ${{ failure() }}
uses: actions/github-script@v6
with:
script: |
const { owner, repo, number } = context.issue;
github.rest.checks.update({
owner,
repo,
name: "Staging Image Check",
head_sha: '${{ steps.sha.outputs.result }}',
check_run_id: ${{ steps.statusCheck.outputs.result }},
status: "completed",
conclusion: "failure",
output: {
title: "Staging Image Failed to Build",
summary: `**Failed to build \`${{ steps.build_id.outputs.BUILD_ID }}\` staging image! ✅** You can check the github action status [here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).`
}
});