-
Notifications
You must be signed in to change notification settings - Fork 14
188 lines (168 loc) · 7.04 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
name: CI
on:
push:
branches:
- 'main'
tags:
- 'v*'
pull_request:
branches:
- 'main'
# Ensure we only have one such workflow running per branch, to avoid
# conflicts in the test env
concurrency:
group: ${{ github.ref }}
jobs:
verify:
name: Code 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
prep-itests:
name: Deploy validation backend
needs: ['verify']
runs-on: ubuntu-latest
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.AWS_ACCOUNT_PROD}}' >> ${GITHUB_OUTPUT}
echo 'aws_access_key=${{secrets.AWS_ACCESS_KEY_ID_PROD}}' >> ${GITHUB_OUTPUT}
echo 'aws_secret_access_key=${{secrets.AWS_SECRET_ACCESS_KEY_PROD}}' >> ${GITHUB_OUTPUT}
else
echo 'aws_account=${{secrets.AWS_ACCOUNT_DEV}}' >> ${GITHUB_OUTPUT}
echo 'aws_access_key=${{secrets.AWS_ACCESS_KEY_ID_DEV}}' >> ${GITHUB_OUTPUT}
echo 'aws_secret_access_key=${{secrets.AWS_SECRET_ACCESS_KEY_DEV}}' >> ${GITHUB_OUTPUT}
fi
- name: Deploy validation backend
shell: bash
working-directory: packages/otelbin-validation
env:
AWS_ACCESS_KEY_ID: ${{ steps.select_credentials.outputs.aws_access_key }}
AWS_SECRET_ACCESS_KEY: ${{ steps.select_credentials.outputs.aws_secret_access_key }}
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 }}
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.AWS_ACCESS_KEY_ID_PROD}}' >> ${GITHUB_OUTPUT}
echo 'aws_secret_access_key=${{secrets.AWS_SECRET_ACCESS_KEY_PROD}}' >> ${GITHUB_OUTPUT}
else
echo 'aws_access_key=${{secrets.AWS_ACCESS_KEY_ID_DEV}}' >> ${GITHUB_OUTPUT}
echo 'aws_secret_access_key=${{secrets.AWS_SECRET_ACCESS_KEY_DEV}}' >> ${GITHUB_OUTPUT}
fi
- name: Retrieve API Key for Validation API and run tests
shell: bash
working-directory: packages/otelbin-validation
env:
AWS_ACCESS_KEY_ID: ${{ steps.select_credentials.outputs.aws_access_key }}
AWS_SECRET_ACCESS_KEY: ${{ steps.select_credentials.outputs.aws_secret_access_key }}
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