-
Notifications
You must be signed in to change notification settings - Fork 3
286 lines (243 loc) · 10.3 KB
/
index.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
name: index
on:
workflow_dispatch:
push:
branches: [ master ]
pull_request:
branches: [ master ]
schedule:
- cron: '0 */24 * * *'
jobs:
update-revisions:
runs-on: ubuntu-latest
outputs:
update_deps: ${{ env.UPDATE_DEPS }}
do_update: ${{ env.DO_UPDATE }}
if: >-
( github.event_name == 'schedule' ||
github.event_name == 'push' ||
github.event_name == 'workflow_dispatch' ||
github.event.inputs.check-for-updates )
steps:
- name: Checkout this repository
id: checkout
uses: actions/checkout@v3
- name: Check for new commits in tested repositories
id: check
# The script update-deps.py defines the following environment variables:
# DO_UPDATE : boolean
# If set to true, then there is at least one update required
# COMMIT_MSG_FILE : string
# Name of file containing the commit message used by bot
if: github.event_name != 'workflow_dispatch'
run: |
apt -y update && apt -y install python3 python3-pip
pip install -r requirements.txt
python3 update-deps.py
echo "UPDATE_DEPS=$(cat update-deps.json)" >> $GITHUB_ENV
- name: (Workflow dispatch) Configure build commit
id: workflow_dispatch_update
if: github.event_name == 'workflow_dispatch'
run: |
echo "DO_UPDATE=true" | tee -a "$GITHUB_ENV"
echo "UPDATE_DEPS=$(cat deps.json)" | tee -a "$GITHUB_ENV"
echo "Workflow dispatch update" > commit_message.txt
echo "COMMIT_MSG_FILE=commit_message.txt" | tee -a "$GITHUB_ENV"
- name: Print environment variables
id: print
run: |
echo "DO_UPDATE="${{ env.DO_UPDATE }}
echo "UPDATE_DEPS="${{ env.UPDATE_DEPS }}
echo "COMMIT_MSG_FILE="${{ env.COMMIT_MSG_FILE }}
- name: Update revisions
id: update
if: ${{ env.DO_UPDATE != 'False' || github.event_name == 'workflow_dispatch' }}
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
git commit -a --allow-empty -F ${{ env.COMMIT_MSG_FILE }}
git push origin master
index-cores:
needs: update-revisions
if: ${{ needs.update-revisions.outputs.do_update != 'False' }}
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson( needs.update-revisions.outputs.update_deps ) }}
env:
IMAGE: ${{ secrets.IMAGE }}
steps:
- name: Checkout this repository
uses: actions/checkout@v3
- name: Set environment variables
shell: bash
run: |
echo "REPOSITORY_NAME=${{ matrix.cores.repository_name }}" >> $GITHUB_ENV
echo "REPOSITORY_URL=${{ matrix.cores.repository_url }}" >> $GITHUB_ENV
echo "REPOSITORY_BRANCH=${{ matrix.cores.repository_branch }}" >> $GITHUB_ENV
echo "REPOSITORY_REV=${{ matrix.cores.repository_revision }}" >> $GITHUB_ENV
- name: Update commit status (pending)
# Status is set automatically for all commits except those created with GH Action
if: ${{ needs.update-revisions.outputs.do_update }}
run: ./set-status ${{ secrets.GITHUB_TOKEN }} $(git rev-parse HEAD) pending
- name: index-core
uses: antmicro/[email protected]
with:
repository_name: ${{ env.REPOSITORY_NAME }}
repository_url: ${{ env.REPOSITORY_URL }}
repository_branch: ${{ env.REPOSITORY_BRANCH }}
repository_revision: ${{ env.REPOSITORY_REV }}
- uses: actions/download-artifact@v3
id: download-artifact
with:
name: server-files
- name: Extract artifacts .tar archive
run: |
ls -al
mkdir artifacts
tar -xf server-files-${{ env.REPOSITORY_NAME }}.tar -C artifacts
- name: Build container image
run: docker build --tag $IMAGE:${{ env.REPOSITORY_NAME }} .
- name: Login to GitHub Container Registry (GHCR)
if: github.event_name != 'pull_request' && github.repository == 'antmicro/verible-indexer'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: gha
password: ${{ github.token }}
- name: Push container image to GitHub Container Registry (GHCR)
if: github.event_name != 'pull_request' && github.repository == 'antmicro/verible-indexer'
run: docker push $IMAGE:${{ env.REPOSITORY_NAME }}
- name: Update commit status to build result
if: always() && ${{ needs.update-revisions.outputs.do_update }}
run: ./set-status ${{ secrets.GITHUB_TOKEN }} $(git rev-parse HEAD) ${{ job.status }}
setup-default-service:
needs: update-revisions
if: >-
( needs.update-revisions.outputs.do_update != 'False' &&
github.event_name != 'pull_request' &&
github.repository == 'antmicro/verible-indexer' )
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
env:
GCR: ${{ secrets.GCR }}
APP_ENGINE_PROJECT: ${{ secrets.APP_ENGINE_PROJECT }}
DEFAULT_SERVICE_IMAGE_NAME: ${{ secrets.DEFAULT_SERVICE_IMAGE_NAME }}
steps:
- name: Checkout this repository
uses: actions/checkout@v3
- id: gcp-auth
name: GCP Authentcation
uses: google-github-actions/auth@v1
with:
service_account: ${{ secrets.GCP_SA }}
workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }}
cleanup_credentials: true
create_credentials_file: true
export_environment_variables: false
- name: Setup gcloud
uses: google-github-actions/setup-gcloud@v1
env:
GOOGLE_GHA_CREDS_PATH: ${{ steps.gcp-auth.outputs.credentials_file_path }}
with:
project_id: ${{ secrets.APP_ENGINE_PROJECT }}
version: '>= 363.0.0'
- name: Check default service
id: check-default
run: echo "service-exists=$(gcloud app services list | grep default | wc -l)" >> "$GITHUB_OUTPUT"
- name: Authenticate docker
if: ${{ steps.check-default.outputs.service-exists == 0 }}
run: |
gcloud auth configure-docker
- name: Build default service
if: ${{ steps.check-default.outputs.service-exists == 0 }}
run: docker build -t $GCR/$DEFAULT_SERVICE_IMAGE_NAME service
- name: Push image to Google Container Registry (GCR)
if: ${{ steps.check-default.outputs.service-exists == 0 }}
run: docker push $GCR/$DEFAULT_SERVICE_IMAGE_NAME
- name: Create default service
if: ${{ steps.check-default.outputs.service-exists == 0 }}
run: gcloud app deploy service/app.yaml --quiet --project $APP_ENGINE_PROJECT --image-url=$GCR/$DEFAULT_SERVICE_IMAGE_NAME --version=v1
- name: Stop deafult service
if: ${{ steps.check-default.outputs.service-exists == 0 }}
run: gcloud app versions stop v1 --quiet --project $APP_ENGINE_PROJECT --service=default
deploy-to-gcp:
needs: [ index-cores, setup-default-service, update-revisions ]
permissions:
contents: read
id-token: write
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson( needs.update-revisions.outputs.update_deps ) }}
env:
REPOSITORY_NAME: ${{ matrix.cores.repository_name }}
APP_ENGINE_PROJECT: ${{ secrets.APP_ENGINE_PROJECT }}
GCR: ${{ secrets.GCR }}
IMAGE: ${{ secrets.IMAGE }}
IMAGE_NAME: ${{ secrets.IMAGE_NAME }}
steps:
- name: Checkout this repository
uses: actions/checkout@v3
- id: gcp-auth
name: GCP Authentcation
uses: google-github-actions/auth@v1
with:
service_account: ${{ secrets.GCP_SA }}
workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }}
cleanup_credentials: true
create_credentials_file: true
export_environment_variables: false
- name: Setup gcloud
uses: google-github-actions/setup-gcloud@v1
env:
GOOGLE_GHA_CREDS_PATH: ${{ steps.gcp-auth.outputs.credentials_file_path }}
with:
project_id: ${{ secrets.APP_ENGINE_PROJECT }}
version: '>= 363.0.0'
- name: Authenticate docker
run: |
gcloud auth configure-docker
- name: Push container image to Google Container Registry (GCR)
run: |
docker pull $IMAGE:$REPOSITORY_NAME
docker tag $IMAGE:$REPOSITORY_NAME $GCR/$IMAGE_NAME:$REPOSITORY_NAME
docker push $GCR/$IMAGE_NAME:$REPOSITORY_NAME
- name: Set service name
run: |
echo "service: $(echo ${REPOSITORY_NAME//_/-} | tr '[:upper:]' '[:lower:]')" >> service/app.yaml
- name: Deploy App Engine's service
run: gcloud app deploy service/app.yaml --quiet --project $APP_ENGINE_PROJECT --image-url $GCR/$IMAGE_NAME:$REPOSITORY_NAME --version v1 --promote
gcr-cleaner:
needs: [ deploy-to-gcp ]
permissions:
contents: read
id-token: write
runs-on: ubuntu-latest
env:
GCR: ${{ secrets.GCR }}
IMAGE_NAME: ${{ secrets.IMAGE_NAME }}
KEEP_IMAGES: 10
steps:
- name: Checkout this repository
uses: actions/checkout@v3
- id: gcp-auth
name: GCP Authentcation
uses: google-github-actions/auth@v1
with:
service_account: ${{ secrets.GCP_SA }}
workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }}
cleanup_credentials: true
create_credentials_file: true
export_environment_variables: false
- name: Setup gcloud
uses: google-github-actions/setup-gcloud@v1
env:
GOOGLE_GHA_CREDS_PATH: ${{ steps.gcp-auth.outputs.credentials_file_path }}
with:
project_id: ${{ secrets.APP_ENGINE_PROJECT }}
version: '>= 363.0.0'
- name: Remove old images from GCR
run: |
TAGGED_IMAGES=$(gcloud container images list-tags $GCR/$IMAGE_NAME --filter="tags:*" --format="get(digest)" | wc -l)
gcloud container images list-tags $GCR/$IMAGE_NAME --filter="NOT tags:*" --format="get(digest)" --sort-by="~timestamp" | tail -n +$(($KEEP_IMAGES * $TAGGED_IMAGES + 1)) | xargs -I _ gcloud container images delete --quiet $GCR/$IMAGE_NAME@_