-
Notifications
You must be signed in to change notification settings - Fork 0
226 lines (203 loc) · 7.56 KB
/
push.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
name: Push Events
on:
push:
branches:
- main
- dev
pull_request:
branches:
- main
- dev
env:
CLOUD_FUNCTION_MEMORY: 1024M
CLOUD_FUNCTION_RUN_TIMEOUT: 9m
SCHEDULE_NAME: saturday-evening
SCHEDULE_CRON: 0 22 * * 6
SCHEDULE_DESCRIPTION: Trigger the wmrc-skid bot every saturday evening at 10pm
VALIDATOR_SCHEDULE_NAME: wmrc-validator
VALIDATOR_SCHEDULE_CRON: 0 8 1 4-6 *
VALIDATOR_SCHEDULE_DESCRIPTION: Trigger the wmrc validation bot every 1st of April, May, and June at 8am
concurrency:
group: "${{ github.head_ref || github.ref }}"
cancel-in-progress: true
jobs:
test:
name: Setup and Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
show-progress: false
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.11
cache: pip
cache-dependency-path: setup.py
- name: Install libkrb5 for Kerberos on Linux
run: |
sudo apt-get update
sudo apt install -y libkrb5-dev
- name: Install module
run: pip install .[tests]
- name: Test with pytest
run: pytest
deploy-dev:
name: Deploy to GCF - dev
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/dev'
environment:
name: dev
permissions:
id-token: write
contents: read
steps:
- name: ⬇️ Set up code
uses: actions/checkout@v4
with:
show-progress: false
- name: 🗝️ Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v2
with:
create_credentials_file: true
token_format: access_token
workload_identity_provider: ${{ secrets.IDENTITY_PROVIDER }}
service_account: ${{ secrets.SERVICE_ACCOUNT_EMAIL }}
- name: 🚀 Deploy Main Cloud Function
id: deploy
uses: google-github-actions/deploy-cloud-functions@v3
timeout-minutes: 15
with:
name: wmrc-skid
runtime: python311
entry_point: subscribe
source_dir: src/wmrc
service_account: cloud-function-sa@${{ secrets.PROJECT_ID }}.iam.gserviceaccount.com
event_trigger_type: google.cloud.pubsub.topic.v1.messagePublished
event_trigger_pubsub_topic: projects/${{ secrets.PROJECT_ID }}/topics/${{ env.SCHEDULE_NAME }}-topic
memory: ${{ env.CLOUD_FUNCTION_MEMORY }}
service_timeout: ${{ env.CLOUD_FUNCTION_RUN_TIMEOUT }}
environment_variables: STORAGE_BUCKET=${{secrets.STORAGE_BUCKET}}
secrets: |
/secrets/app/secrets.json=${{secrets.PROJECT_ID}}/skid-secrets
max_instance_count: 1
event_trigger_retry: false
- name: 📥 Create Main PubSub topic
run: |
if [ ! "$(gcloud pubsub topics list | grep $SCHEDULE_NAME-topic)" ]; then
gcloud pubsub topics create $SCHEDULE_NAME-topic --quiet
fi
- name: 🕰️ Create Main Cloud Scheduler
run: |
if [ ! "$(gcloud scheduler jobs list --location=us-central1 | grep $SCHEDULE_NAME)" ]; then
gcloud scheduler jobs create pubsub $SCHEDULE_NAME \
--description="$SCHEDULE_DESCRIPTION" \
--schedule="$SCHEDULE_CRON" \
--time-zone=America/Denver \
--location=us-central1 \
--topic=$SCHEDULE_NAME-topic \
--message-body='facility updates' \
--quiet
else
gcloud scheduler jobs update pubsub $SCHEDULE_NAME \
--description="$SCHEDULE_DESCRIPTION" \
--schedule="$SCHEDULE_CRON" \
--time-zone=America/Denver \
--location=us-central1 \
--topic=$SCHEDULE_NAME-topic \
--message-body='facility updates' \
--quiet
fi
- name: 🕰️ Create Validator Cloud Scheduler
run: |
if [ ! "$(gcloud scheduler jobs list --location=us-central1 | grep $VALIDATOR_SCHEDULE_NAME)" ]; then
gcloud scheduler jobs create pubsub $VALIDATOR_SCHEDULE_NAME \
--description="$VALIDATOR_SCHEDULE_DESCRIPTION" \
--schedule="$VALIDATOR_SCHEDULE_CRON" \
--time-zone=America/Denver \
--location=us-central1 \
--topic=$SCHEDULE_NAME-topic \
--message-body='validate' \
--quiet
else
gcloud scheduler jobs update pubsub $VALIDATOR_SCHEDULE_NAME \
--description="$VALIDATOR_SCHEDULE_DESCRIPTION" \
--schedule="$VALIDATOR_SCHEDULE_CRON" \
--time-zone=America/Denver \
--location=us-central1 \
--topic=$SCHEDULE_NAME-topic \
--message-body='validate' \
--quiet
fi
deploy-prod:
name: Deploy to GCF - prod
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
environment:
name: prod
permissions:
id-token: write
contents: read
steps:
- name: ⬇️ Set up code
uses: actions/checkout@v4
with:
show-progress: false
- name: 🗝️ Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v2
with:
create_credentials_file: true
token_format: access_token
workload_identity_provider: ${{ secrets.IDENTITY_PROVIDER }}
service_account: ${{ secrets.SERVICE_ACCOUNT_EMAIL }}
- name: 🚀 Deploy to Cloud Function
id: deploy
uses: google-github-actions/deploy-cloud-functions@v3
timeout-minutes: 15
with:
name: wmrc-skid
runtime: python311
entry_point: main
source_dir: src/wmrc
service_account: cloud-function-sa@${{ secrets.PROJECT_ID }}.iam.gserviceaccount.com
event_trigger_type: google.cloud.pubsub.topic.v1.messagePublished
event_trigger_pubsub_topic: projects/${{ secrets.PROJECT_ID }}/topics/${{ env.SCHEDULE_NAME }}-topic
memory: ${{ env.CLOUD_FUNCTION_MEMORY }}
service_timeout: ${{ env.CLOUD_FUNCTION_RUN_TIMEOUT }}
environment_variables: STORAGE_BUCKET=${{secrets.STORAGE_BUCKET}}
secrets: |
/secrets/app/secrets.json=${{secrets.PROJECT_ID}}/skid-secrets
max_instance_count: 1
event_trigger_retry: false
- name: 📥 Create PubSub topic
run: |
if [ ! "$(gcloud pubsub topics list | grep $SCHEDULE_NAME-topic)" ]; then
gcloud pubsub topics create $SCHEDULE_NAME-topic --quiet
fi
- name: 🕰️ Create Cloud Scheduler
run: |
for i in $(gcloud scheduler jobs list --location=us-central1 --uri); do
gcloud scheduler jobs delete $i --quiet
done
gcloud scheduler jobs create pubsub $SCHEDULE_NAME \
--description="$SCHEDULE_DESCRIPTION" \
--schedule="$SCHEDULE_CRON" \
--time-zone=America/Denver \
--location=us-central1 \
--topic=$SCHEDULE_NAME-topic \
--message-body='{"run": "now"}' \
--quiet
- name: 🔔 Create deployment notification
uses: agrc/service-now-worknote-action@v1
with:
repo-token: ${{ github.token }}
username: ${{ secrets.SN_USERNAME }}
password: ${{ secrets.SN_PASSWORD }}
instance-name: ${{ secrets.SN_INSTANCE }}
table-name: ${{ secrets.SN_TABLE }}
system-id: ${{ secrets.SN_SYS_ID }}