-
Notifications
You must be signed in to change notification settings - Fork 13
236 lines (209 loc) · 8.83 KB
/
ci.yaml
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
name: CI
on:
push:
branches:
- 'main'
tags:
- 'v*'
pull_request:
branches:
- 'main'
permissions:
id-token: write
contents: read
# Ensure we only have one such workflow running per branch, to avoid
# conflicts in the test env
concurrency:
group: ${{ github.ref }}
jobs:
otelbin-verify:
name: OTelBin tests
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
- name: Install dependencies
shell: bash
working-directory: packages/otelbin
run: npm ci
- name: Lint
shell: bash
working-directory: packages/otelbin
run: npm run lint
- name: Test
shell: bash
working-directory: packages/otelbin
run: npm run test
otelbin-validation-image-verify:
name: OTelBin Validation Image Tests
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
- name: Install dependencies
shell: bash
working-directory: packages/otelbin-validation-image
run: npm ci
- name: Test
shell: bash
working-directory: packages/otelbin-validation-image
run: npm run test
prep-itests:
name: Deploy validation backend
needs: ['otelbin-verify', 'otelbin-validation-image-verify']
runs-on: 8core_32gb
timeout-minutes: 30
outputs:
test_matrix: ${{ steps.prepare_test_matrix.outputs.test_matrix }}
validation_api_apigateway_name: ${{ steps.parse_cdk_output.outputs.api_gateway_name }}
validation_api_apigateway_url: ${{ steps.parse_cdk_output.outputs.api_gateway_url }}\
validation_api_apigateway_key_id: ${{ steps.parse_cdk_output.outputs.api_gateway_key_id }}
test_env_name: ${{ steps.get_test_env_name.outputs.test_env_name }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
- name: Install CDK dependencies
shell: bash
working-directory: packages/otelbin-validation
run: |
npm ci
npm i -g aws-cli
- name: Get test environment name
id: get_test_env_name
shell: bash
env:
REF_NAME: ${{ github.head_ref || github.ref_name }}
# When the trigger is a pull event, use the PR's branch name (`github.head_ref`), which
# is available only for pull trigger. Otherwise, use the branch on which the commit was pushed.
# (Ref names in pull requests are in the shape of `<pr_id>/merge` and those will break CDK.)
run: |
echo "test_env_name=$(./.github/workflows/scripts/test_env_name.sh)" >> $GITHUB_OUTPUT || exit 1
- name: Select credentials
id: select_credentials
shell: bash
env:
TEST_ENVIRONMENT_NAME: ${{ steps.get_test_env_name.outputs.test_env_name }}
run: |
if [ "${TEST_ENVIRONMENT_NAME}" == 'main' ]; then
echo 'aws_account=${{secrets.OTELBIN_AUTOMATION_ACCOUNT_PROD}}' >> ${GITHUB_OUTPUT}
echo 'aws_access_key=${{secrets.OTELBIN_AUTOMATION_ACCESS_KEY_ID_PROD}}' >> ${GITHUB_OUTPUT}
echo 'aws_secret_access_key=${{secrets.OTELBIN_AUTOMATION_SECRET_ACCESS_KEY_PROD}}' >> ${GITHUB_OUTPUT}
echo 'role_arn=${{secrets.OTELBIN_AUTOMATION_ROLE_ARN_PROD}}' >> ${GITHUB_OUTPUT}
else
echo 'aws_account=${{secrets.OTELBIN_AUTOMATION_ACCOUNT_DEV}}' >> ${GITHUB_OUTPUT}
echo 'aws_access_key=${{secrets.OTELBIN_AUTOMATION_ACCESS_KEY_ID_DEV}}' >> ${GITHUB_OUTPUT}
echo 'aws_secret_access_key=${{secrets.OTELBIN_AUTOMATION_SECRET_ACCESS_KEY_DEV}}' >> ${GITHUB_OUTPUT}
echo 'role_arn=${{secrets.OTELBIN_AUTOMATION_ROLE_ARN_DEV}}' >> ${GITHUB_OUTPUT}
fi
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ steps.select_credentials.outputs.aws_access_key }}
aws-secret-access-key: ${{ steps.select_credentials.outputs.aws_secret_access_key }}
aws-region: 'us-east-2'
mask-aws-account-id: true
role-to-assume: ${{ steps.select_credentials.outputs.role_arn }}
- name: Deploy validation backend
shell: bash
working-directory: packages/otelbin-validation
env:
AWS_DEFAULT_REGION: 'us-east-2'
CDK_DEPLOY_ACCOUNT: ${{ steps.select_credentials.outputs.aws_account }}
CDK_DEPLOY_REGION: 'us-east-2'
GH_TOKEN: ${{ github.token }}
TEST_ENVIRONMENT_NAME: ${{ steps.get_test_env_name.outputs.test_env_name }}
DASH0_AUTHORIZATION_TOKEN: ${{ secrets.DASH0_AUTHORIZATION_TOKEN }}
run: |
npx projen deploy --require-approval never --outputs-file ./cdk-outputs.json
- name: Read API Gateway URL
id: parse_cdk_output
shell: bash
working-directory: packages/otelbin-validation
env:
TEST_ENVIRONMENT_NAME: ${{ steps.get_test_env_name.outputs.test_env_name }}
run: |
echo api_gateway_name=$(jq -r ".[\"otelbin-validation-${TEST_ENVIRONMENT_NAME}\"] | .apiname" < ./cdk-outputs.json) >> ${GITHUB_OUTPUT}
echo api_gateway_url=$(jq -r ".[\"otelbin-validation-${TEST_ENVIRONMENT_NAME}\"] | .apiurl" < ./cdk-outputs.json) >> ${GITHUB_OUTPUT}
echo api_gateway_key_id=$(jq -r ".[\"otelbin-validation-${TEST_ENVIRONMENT_NAME}\"] | .apikeyid" < ./cdk-outputs.json) >> ${GITHUB_OUTPUT}
- name: Prepare test matrix
id: prepare_test_matrix
shell: bash
working-directory: packages/otelbin-validation
run: |
echo test_matrix=$(jq -r '. | [to_entries[] | {distribution: .key, release: .value.releases[].version} | "\(.distribution)/\(.release)"]' < ./src/assets/supported-distributions.json) >> ${GITHUB_OUTPUT}
run-itests:
name: Validation tests
needs: ['prep-itests']
strategy:
matrix:
test_matrix: ${{ fromJson(needs.prep-itests.outputs.test_matrix )}}
fail-fast: false # We want to run all the tests, to prevent one failure from hiding another
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
- name: Install CDK dependencies
shell: bash
working-directory: packages/otelbin-validation
run: |
npm ci
- name: Select credentials
id: select_credentials
shell: bash
env:
TEST_ENVIRONMENT_NAME: ${{ needs.prep-itests.outputs.test_env_name }}
run: |
if [ "${TEST_ENVIRONMENT_NAME}" == 'main' ]; then
echo 'aws_access_key=${{secrets.OTELBIN_AUTOMATION_ACCESS_KEY_ID_PROD}}' >> ${GITHUB_OUTPUT}
echo 'aws_secret_access_key=${{secrets.OTELBIN_AUTOMATION_SECRET_ACCESS_KEY_PROD}}' >> ${GITHUB_OUTPUT}
echo 'role_arn=${{secrets.OTELBIN_AUTOMATION_ROLE_ARN_PROD}}' >> ${GITHUB_OUTPUT}
else
echo 'aws_access_key=${{secrets.OTELBIN_AUTOMATION_ACCESS_KEY_ID_DEV}}' >> ${GITHUB_OUTPUT}
echo 'aws_secret_access_key=${{secrets.OTELBIN_AUTOMATION_SECRET_ACCESS_KEY_DEV}}' >> ${GITHUB_OUTPUT}
echo 'role_arn=${{secrets.OTELBIN_AUTOMATION_ROLE_ARN_DEV}}' >> ${GITHUB_OUTPUT}
fi
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ steps.select_credentials.outputs.aws_access_key }}
aws-secret-access-key: ${{ steps.select_credentials.outputs.aws_secret_access_key }}
aws-region: 'us-east-2'
mask-aws-account-id: true
role-to-assume: ${{ steps.select_credentials.outputs.role_arn }}
- name: Retrieve API Key for Validation API and run tests
shell: bash
working-directory: packages/otelbin-validation
env:
AWS_DEFAULT_REGION: 'us-east-2'
API_GATEWAY_NAME: ${{ needs.prep-itests.outputs.validation_api_apigateway_name }}
API_GATEWAY_URL: ${{ needs.prep-itests.outputs.validation_api_apigateway_url }}
RELEASE_UNDER_TEST: ${{ matrix.test_matrix }}
run: |
VALIDATION_API_KEY=$(aws apigateway get-api-key --api-key ${{ needs.prep-itests.outputs.validation_api_apigateway_key_id }} --include-value | jq -r '.value') npm run test