-
Notifications
You must be signed in to change notification settings - Fork 0
246 lines (235 loc) · 8.36 KB
/
build_test_deploy.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
name: 'Build, Test, Deploy'
permissions:
id-token: write
contents: read
on:
workflow_dispatch:
push:
branches:
- 'main'
- 'beta'
- 'feature/*'
paths-ignore:
- '.github/**'
- 'featuresets.js'
env:
WORKSPACE_ARTIFACT_UI: 'gw2auth_ui_artifact'
WORKSPACE_ARTIFACT_API: 'gw2auth_api_artifact'
WORKSPACE_ARTIFACT_OAUTH2_SERVER: 'gw2auth_oauth2_server_artifact'
WORKSPACE_ARTIFACT_OTEL_COLLECTOR: 'otel_collector_artifact'
WORKSPACE_ARTIFACT_CDK: 'gw2auth_cdk_artifact'
jobs:
build_ui:
name: 'Build UI'
runs-on: ubuntu-latest
steps:
- name: 'Checkout'
uses: actions/checkout@v4
with:
ssh-key: ${{ secrets.CDK_SSH_KEY }}
submodules: true
- name: 'Build UI'
id: build_ui
uses: './gw2auth.com-ui/.github/actions/build_and_test'
with:
working-directory: 'gw2auth.com-ui'
base-url: ${{ (github.ref == 'refs/heads/beta' && 'https://beta.gw2auth.com') || (github.ref == 'refs/heads/main' && 'https://gw2auth.com') || 'https://feature.gw2auth.com' }}
- name: 'Prepare UI resources bundle'
working-directory: 'gw2auth.com-ui/${{ steps.build_ui.outputs.output_dir }}'
run: 'zip -r ../${{ env.WORKSPACE_ARTIFACT_UI }}.zip .'
- name: 'Store UI artifact'
uses: actions/upload-artifact@v4
with:
name: ${{ env.WORKSPACE_ARTIFACT_UI }}
path: 'gw2auth.com-ui/${{ env.WORKSPACE_ARTIFACT_UI }}.zip'
retention-days: 1
build_api:
name: 'Build API'
runs-on: ubuntu-latest
steps:
- name: 'Checkout'
uses: actions/checkout@v4
with:
ssh-key: ${{ secrets.CDK_SSH_KEY }}
submodules: true
- name: 'Build API'
uses: './gw2auth.com-api/.github/actions/build_and_test'
with:
working-directory: 'gw2auth.com-api'
output: 'bootstrap'
- name: 'Prepare lambda bundle'
working-directory: 'gw2auth.com-api'
run: '(chmod +x bootstrap && zip -q ${{ env.WORKSPACE_ARTIFACT_API }}.zip bootstrap && rm bootstrap)'
- name: 'Store API artifact'
uses: actions/upload-artifact@v4
with:
name: ${{ env.WORKSPACE_ARTIFACT_API }}
path: 'gw2auth.com-api/${{ env.WORKSPACE_ARTIFACT_API }}.zip'
retention-days: 1
build_oauth2_server:
name: 'Build oauth2-server'
runs-on: ubuntu-latest
steps:
- name: 'Checkout'
uses: actions/checkout@v4
with:
ssh-key: ${{ secrets.CDK_SSH_KEY }}
submodules: true
- name: 'Setup java'
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
cache: 'maven'
- name: 'Build'
working-directory: 'oauth2-server'
run: './mvnw clean package -Dmaven.test.skip'
- name: 'Prepare lambda bundle'
working-directory: 'oauth2-server'
run: '(mv target/oauth2-server.jar oauth2-server.jar && chmod +x lambda-run.sh && zip -q ${{ env.WORKSPACE_ARTIFACT_OAUTH2_SERVER }}.zip lambda-run.sh oauth2-server.jar)'
- name: 'Store oauth2-server artifact'
uses: actions/upload-artifact@v4
with:
name: ${{ env.WORKSPACE_ARTIFACT_OAUTH2_SERVER }}
path: 'oauth2-server/${{ env.WORKSPACE_ARTIFACT_OAUTH2_SERVER }}.zip'
retention-days: 1
build_otel_collector:
name: 'Build otel collector'
runs-on: ubuntu-latest
steps:
- name: 'Checkout'
uses: actions/checkout@v4
with:
ssh-key: ${{ secrets.CDK_SSH_KEY }}
submodules: true
- name: 'Setup go'
uses: actions/setup-go@v5
with:
go-version-file: 'opentelemetry-lambda/collector/go.mod'
cache-dependency-path: 'opentelemetry-lambda/collector/go.sum'
- name: 'Build otel collector'
working-directory: 'opentelemetry-lambda/collector'
env:
GOOS: 'linux'
GOARCH: 'amd64' # keep this in sync with the arch configured in CDK!
CGO_ENABLED: '0'
run: 'go build -o otel_collector'
- name: 'Prepare lambda extension bundle'
working-directory: 'opentelemetry-lambda/collector'
run: |
mkdir lambda_layer_bundle
mkdir lambda_layer_bundle/extensions
cp otel_collector lambda_layer_bundle/extensions/layer
cp ../../collector.yaml lambda_layer_bundle/
chmod +x lambda_layer_bundle/extensions/layer
(cd lambda_layer_bundle && zip -r ../${{ env.WORKSPACE_ARTIFACT_OTEL_COLLECTOR }}.zip .)
- name: 'Store otel collector artifact'
uses: actions/upload-artifact@v4
with:
name: ${{ env.WORKSPACE_ARTIFACT_OTEL_COLLECTOR }}
path: 'opentelemetry-lambda/collector/${{ env.WORKSPACE_ARTIFACT_OTEL_COLLECTOR }}.zip'
retention-days: 1
build_and_synth_cdk:
name: 'Build and synth cdk'
runs-on: ubuntu-latest
needs:
- build_ui
- build_api
- build_oauth2_server
- build_otel_collector
steps:
- name: 'Checkout'
uses: actions/checkout@v4
with:
ssh-key: ${{ secrets.CDK_SSH_KEY }}
submodules: true
- name: 'Download artifacts'
uses: actions/download-artifact@v4
with:
path: './gw2auth.com-cdk/resources'
- name: 'Build and synth cdk'
uses: './gw2auth.com-cdk/.github/actions/build_and_synth'
with:
working-directory: 'gw2auth.com-cdk'
- name: 'Store cdk synth artifact'
uses: actions/upload-artifact@v4
with:
name: ${{ env.WORKSPACE_ARTIFACT_CDK }}
path: |
gw2auth.com-cdk/cdk.out/
gw2auth.com-cdk/cdk.json
retention-days: 1
deploy:
name: 'Deploy'
if: github.ref == 'refs/heads/beta' || github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/feature/')
runs-on: ubuntu-latest
environment:
name: ${{ (github.ref == 'refs/heads/beta' && 'beta') || (github.ref == 'refs/heads/main' && 'prod') || 'feature' }}
url: ${{ (github.ref == 'refs/heads/beta' && 'https://beta.gw2auth.com') || (github.ref == 'refs/heads/main' && 'https://gw2auth.com') || 'https://feature.gw2auth.com' }}
needs:
- build_and_synth_cdk
steps:
- name: 'Checkout'
uses: actions/checkout@v4
with:
ssh-key: ${{ secrets.CDK_SSH_KEY }}
submodules: true
- name: 'Download cdk synth artifact'
uses: actions/download-artifact@v4
with:
name: ${{ env.WORKSPACE_ARTIFACT_CDK }}
path: .
- name: 'Deploy'
uses: './gw2auth.com-cdk/.github/actions/deploy'
with:
role-to-assume: ${{ secrets.AWS_CDK_ROLE }}
aws-region: ${{ secrets.AWS_CDK_REGION }}
cdk-out-path: './cdk.out'
stack: ${{ vars.CDK_STACK }}
grafana-cloud-auth: ${{ secrets.GRAFANA_CLOUD_AUTH }}
secrets-bucket: ${{ secrets.SECRETS_BUCKET }}
secrets-key-prefix: ${{ secrets.SECRETS_KEY_PREFIX }}
create_pull_request:
name: 'Create PR'
if: github.ref == 'refs/heads/beta'
runs-on: ubuntu-latest
needs:
- deploy
permissions:
pull-requests: write
steps:
- name: 'Create PR'
uses: actions/github-script@v7
with:
script: |
const { repo, owner } = context.repo;
const pulls = await github.rest.pulls.list({
owner: owner,
repo: repo,
head: context.ref,
base: 'main',
state: 'open',
});
if (pulls.data.length < 1) {
await github.rest.pulls.create({
title: '[CI] Merge beta into main',
owner: owner,
repo: repo,
head: context.ref,
base: 'main',
body: [
'This PR is auto-generated by',
'[actions/github-script](https://github.com/actions/github-script)',
].join('\n'),
});
} else {
const existingPR = pulls.data[0];
await github.rest.issues.createComment({
owner: owner,
repo: repo,
issue_number: existingPR.number,
body: [
`Updated by Job ${context.job}`,
].join('\n'),
});
}