-
Notifications
You must be signed in to change notification settings - Fork 31
210 lines (176 loc) · 6.82 KB
/
remove-deploy-previews.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
name: remove-deploy-previews
on:
pull_request:
branches:
- staging
types:
- closed
jobs:
branch-name:
name: Format branch name string
runs-on: ubuntu-latest
outputs:
lowercase: ${{ steps.string.outputs.lowercase }} # lowercase version
steps:
- id: string
uses: ASzc/change-string-case-action@v2
with:
string: ${{ github.head_ref || github.ref_name }}
check:
name: check for available deploy previews
outputs:
remove_netmanager_preview: ${{ steps.check_files.outputs.remove_netmanager_preview }} # remove netmanager preview
remove_calibrate_app_preview: ${{ steps.check_files.outputs.remove_calibrate_app_preview }} # remove calibrate app preview
remove_analytics_platform: ${{ steps.check_files.outputs.remove_analytics_platform }} # analytics platform
remove_docs: ${{ steps.check_files.outputs.remove_docs }} # docs
remove_inventory: ${{ steps.check_files.outputs.remove_inventory }} # inventory
remove_reports: ${{ steps.check_files.outputs.remove_reports }} # reports
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: check modified frontends
id: check_files
run: |
echo "=============== list modified files ==============="
git diff --name-only HEAD^ HEAD
echo "========== check paths of modified files =========="
git diff --name-only HEAD^ HEAD > files.txt
echo "remove_netmanager_preview=false" >>$GITHUB_OUTPUT
echo "remove_calibrate_app_preview=false" >>$GITHUB_OUTPUT
echo "remove_analytics_platform=false" >>$GITHUB_OUTPUT
echo "remove_docs=false" >>$GITHUB_OUTPUT
echo "remove_inventory=false" >>$GITHUB_OUTPUT
echo "remove_reports=false" >>$GITHUB_OUTPUT
while IFS= read -r file
do
echo $file
if [[ $file == netmanager/* ]]; then
echo "remove_netmanager_preview=true" >>$GITHUB_OUTPUT
fi
if [[ $file == calibrate/* ]]; then
echo "remove_calibrate_app_preview=true" >>$GITHUB_OUTPUT
fi
if [[ $file == platform/* ]]; then
echo "remove_analytics_platform=true" >>$GITHUB_OUTPUT
fi
if [[ $file == docs/* ]]; then
echo "remove_docs=true" >>$GITHUB_OUTPUT
fi
if [[ $file == inventory/* ]]; then
echo "remove_inventory=true" >>$GITHUB_OUTPUT
fi
if [[ $file == reports/* ]]; then
echo "remove_reports=true" >>$GITHUB_OUTPUT
fi
done < files.txt
### remove netmanager deploy preview ###
remove-netmanager-preview:
name: remove-netmanager-preview
needs: [check, branch-name]
if: needs.check.outputs.remove_netmanager_preview == 'true'
runs-on: ubuntu-latest
steps:
- name: Google login
uses: google-github-actions/auth@v1
with:
credentials_json: "${{ secrets.GCP_SA_CREDENTIALS }}"
- name: Setup Cloud SDK
uses: "google-github-actions/setup-gcloud@v1"
- name: Delete PR deploy preview
run: |-
gcloud run services delete ${{ needs.branch-name.outputs.lowercase }}-netmanager-preview \
--region=${{ secrets.REGION }} \
--quiet
### remove calibrate-app deploy preview ###
remove-calibrate-app-preview:
name: remove-calibrate-app-preview
needs: [check, branch-name]
if: needs.check.outputs.remove_calibrate_app_preview == 'true'
runs-on: ubuntu-latest
steps:
- name: Google login
uses: google-github-actions/auth@v1
with:
credentials_json: "${{ secrets.GCP_SA_CREDENTIALS }}"
- name: Setup Cloud SDK
uses: "google-github-actions/setup-gcloud@v1"
- name: Delete PR deploy preview
run: |-
gcloud run services delete ${{ needs.branch-name.outputs.lowercase }}-calibrate-app-preview \
--region=${{ secrets.REGION }} \
--quiet
### remove analytics platform deploy preview ###
remove-analytics-platform-preview:
name: remove-analytics-platform-preview
needs: [check, branch-name]
if: needs.check.outputs.remove_analytics_platform == 'true'
runs-on: ubuntu-latest
steps:
- name: Google login
uses: google-github-actions/auth@v1
with:
credentials_json: "${{ secrets.GCP_SA_CREDENTIALS }}"
- name: Setup Cloud SDK
uses: "google-github-actions/setup-gcloud@v1"
- name: Delete PR deploy preview
run: |-
gcloud run services delete ${{ needs.branch-name.outputs.lowercase }}-analytics-platform-preview \
--region=${{ secrets.REGION }} \
--quiet
### remove docs deploy preview ###
remove-docs-preview:
name: remove-docs-preview
needs: [check, branch-name]
if: needs.check.outputs.remove_docs == 'true'
runs-on: ubuntu-latest
steps:
- name: Google login
uses: google-github-actions/auth@v1
with:
credentials_json: "${{ secrets.GCP_SA_CREDENTIALS }}"
- name: Setup Cloud SDK
uses: "google-github-actions/setup-gcloud@v1"
- name: Delete PR deploy preview
run: |-
gcloud run services delete ${{ needs.branch-name.outputs.lowercase }}-docs-preview \
--region=${{ secrets.REGION }} \
--quiet
### remove inventory deploy preview ###
remove-inventory-preview:
name: remove-inventory-preview
needs: [check, branch-name]
if: needs.check.outputs.remove_inventory == 'true'
runs-on: ubuntu-latest
steps:
- name: Google login
uses: google-github-actions/auth@v1
with:
credentials_json: "${{ secrets.GCP_SA_CREDENTIALS }}"
- name: Setup Cloud SDK
uses: "google-github-actions/setup-gcloud@v1"
- name: Delete PR deploy preview
run: |-
gcloud run services delete ${{ needs.branch-name.outputs.lowercase }}-inventory-preview \
--region=${{ secrets.REGION }} \
--quiet
### remove reports deploy preview ###
remove-reports-preview:
name: remove-reports-preview
needs: [check, branch-name]
if: needs.check.outputs.remove_reports == 'true'
runs-on: ubuntu-latest
steps:
- name: Google login
uses: google-github-actions/auth@v1
with:
credentials_json: "${{ secrets.GCP_SA_CREDENTIALS }}"
- name: Setup Cloud SDK
uses: "google-github-actions/setup-gcloud@v1"
- name: Delete PR deploy preview
run: |-
gcloud run services delete ${{ needs.branch-name.outputs.lowercase }}-reports-preview \
--region=${{ secrets.REGION }} \
--quiet