-
Notifications
You must be signed in to change notification settings - Fork 239
380 lines (324 loc) · 12 KB
/
PR-build.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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.
name: PR Build
on:
pull_request:
branches:
- main
- release/v*
- dev
- test/*
env:
IMAGE_NAME: aws-otel-collector
PACKAGING_ROOT: build/packages
TESTING_FRAMEWORK_REPO: aws-observability/aws-otel-test-framework
GO_VERSION: ~1.22.7
concurrency:
group: pr-build-${{ github.event.pull_request.number }}
cancel-in-progress: true
permissions:
id-token: write
contents: read
jobs:
validate-markdown:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files
id: changes
run: |
echo "MDS=$(git diff --name-only --diff-filter=ACMRTUXB $(git merge-base origin/${{ github.event.pull_request.base.ref }} ${{ github.event.pull_request.head.sha }}) ${{ github.event.pull_request.head.sha }} | grep .md$ | grep -v vendor/ | xargs)" >> $GITHUB_ENV
- name: Install markdown-link-check
run: npm install -g markdown-link-check
if: ${{ env.MDS }}
- name: Run markdown-link-check
run: |
markdown-link-check \
--verbose \
--config .github/config/markdown-links-config.json \
${{ env.MDS }} \
|| { echo "Check that anchor links are lowercase"; exit 1; }
if: ${{ env.MDS }}
create-test-ref:
runs-on: ubuntu-latest
outputs:
testRef: ${{ steps.setRef.outputs.ref }}
steps:
- name: Set testRef output
id: setRef
run: |
if [[ ${{ github.base_ref }} == release/v* ]]; then
echo "ref=${{github.base_ref}}" >> $GITHUB_OUTPUT
else
echo "ref=terraform" >> $GITHUB_OUTPUT
fi
changes:
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.filter.outputs.changed }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v2
id: filter
with:
list-files: shell
filters: .github/config/file-filters.yml
- name: List all updated files
run: |
for file in ${{ steps.filter.outputs.all_files }}; do
echo "$file"
done
- name: Check if this is a version bump PR
if: steps.filter.outputs.version == 'true'
run: echo "This is a version bump PR!"
build-windows:
runs-on: windows-latest
needs: [changes]
steps:
- name: Checkout
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/checkout@v4
- name: apply patches
if: ${{ needs.changes.outputs.changed == 'true' }}
run: make apply-patches
# Set up building environment, patch the dev repo code on dispatch events.
- name: Set up Go 1.x
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: install tools
if: ${{ needs.changes.outputs.changed == 'true' }}
run: make install-tools
- name: Lint
if: ${{ needs.changes.outputs.changed == 'true'}}
run: make golint
# only run unit tests on windows. The unix build job will lint, test, and build.
- name: Unit test
if: ${{ needs.changes.outputs.changed == 'true'}}
run: make gotest
build:
runs-on: ubuntu-latest
needs: [changes]
steps:
- name: Remove cache
run: rm -rf /opt/hostedtoolcache
- name: Checkout
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/checkout@v4
- name: apply patches
if: ${{ needs.changes.outputs.changed == 'true' }}
run: make apply-patches
# Set up building environment, patch the dev repo code on dispatch events.
- name: Set up Go 1.x
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Cache binaries
id: cached_binaries
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/cache@v3
with:
key: "cached_binaries_${{ github.run_id }}"
path: build
# Linting && Unit Test and attach test coverage badge
- name: Tests - Lint and unit test
if: ${{ needs.changes.outputs.changed == 'true' && steps.cached_binaries.outputs.cache-hit != 'true' }}
run: make test-all
- name: Upload Coverage report to CodeCov
if: ${{ needs.changes.outputs.changed == 'true' && steps.cached_binaries.outputs.cache-hit != 'true' }}
uses: codecov/codecov-action@v3
with:
file: ./coverage.txt
# Build and archive binaries into cache.
- name: Build Binaries
if: ${{ needs.changes.outputs.changed == 'true' && steps.cached_binaries.outputs.cache-hit != 'true' }}
run: make build
# upload the binaries to artifact as well because cache@v2 hasn't support windows
- name: Upload
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/upload-artifact@v3
with:
name: binary_artifacts
path: build
retention-days: 1
packaging-msi:
runs-on: windows-latest
needs: [changes, build]
steps:
- name: Checkout
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/checkout@v4
- name: Download built artifacts
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/download-artifact@v3
with:
name: binary_artifacts
path: build
- name: Display structure of downloaded files
run: ls -R
if: ${{ needs.changes.outputs.changed == 'true' }}
- name: Create msi file using candle and light
if: ${{ needs.changes.outputs.changed == 'true' }}
run: .\tools\packaging\windows\create_msi.ps1
packaging-rpm:
runs-on: ubuntu-latest
needs: [changes, build]
steps:
# Build and archive RPMs into cache.
- name: Checkout
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/checkout@v4
- name: restore cached binaries
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/cache@v3
with:
key: "cached_binaries_${{ github.run_id }}"
path: build
- name: Display structure of downloaded files
if: ${{ needs.changes.outputs.changed == 'true' }}
run: ls -R
- name: Build RPM
if: ${{ needs.changes.outputs.changed == 'true' }}
run: |
ARCH=x86_64 SOURCE_ARCH=amd64 DEST=build/packages/linux/amd64 tools/packaging/linux/create_rpm.sh
ARCH=aarch64 SOURCE_ARCH=arm64 DEST=build/packages/linux/arm64 tools/packaging/linux/create_rpm.sh
packaging-deb:
runs-on: ubuntu-latest
needs: [changes, build]
steps:
# Build and archive debs into cache.
- name: Checkout
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/checkout@v4
- name: Restore cached binaries
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/cache@v3
with:
key: "cached_binaries_${{ github.run_id }}"
path: build
- name: Cache built debian
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/cache@v3
with:
key: "cached_deb_${{ github.run_id }}"
path: build/packages/debian
- name: Build Debs
if: ${{ needs.changes.outputs.changed == 'true' }}
run: |
ARCH=amd64 DEST=build/packages/debian/amd64 tools/packaging/debian/create_deb.sh
ARCH=arm64 DEST=build/packages/debian/arm64 tools/packaging/debian/create_deb.sh
test-control-stript:
runs-on: ubuntu-latest
needs: [changes, packaging-deb]
steps:
- name: Checkout
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/checkout@v4
- name: Restore cached deb
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/cache@v3
with:
key: "cached_deb_${{ github.run_id }}"
path: build/packages/debian
- name: Execute tests
if: ${{ needs.changes.outputs.changed == 'true' }}
run: |
file ./build/packages/debian/amd64/aws-otel-collector.deb
sudo ./.github/scripts/test-collector-ctl.sh ./build/packages/debian/amd64/aws-otel-collector.deb ./config.yaml
get-test-cases:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: Get all the testing suites
id: set-matrix
run: |
matrix=$(python e2etest/get-testcases.py local_matrix)
echo "matrix=$matrix" >> $GITHUB_OUTPUT
- name: List testing suites
run: |
echo ${{ steps.set-matrix.outputs.matrix }}
run-test-case:
runs-on: ubuntu-latest
needs: [changes, get-test-cases, build, create-test-ref]
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.get-test-cases.outputs.matrix) }}
steps:
- name: Check out testing framework
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/checkout@v4
with:
repository: ${{ env.TESTING_FRAMEWORK_REPO }}
path: testing-framework
ref: ${{ needs.create-test-ref.outputs.testRef }}
- name: Check out Collector
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/checkout@v4
with:
path: aws-otel-collector
- name: Set up JDK 11
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '11'
- name: Set up terraform
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: hashicorp/setup-terraform@v3
with:
terraform_version: "~1.5"
- name: restore cached binaries
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/cache@v3
with:
key: "cached_binaries_${{ github.run_id }}"
path: build
- name: copy binary
if: ${{ needs.changes.outputs.changed == 'true' }}
run: cp -R build aws-otel-collector/build
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.COLLECTOR_PR_BUILD_ROLE_ARN }}
aws-region: us-east-1
- name: Login to Public Integration Test ECR
uses: docker/login-action@v3
with:
registry: public.ecr.aws
env:
AWS_REGION: us-east-1
- name: Run test
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: nick-invision/retry@v2
with:
max_attempts: 2
timeout_minutes: 10
command: |
if [[ -f testing-framework/terraform/testcases/${{ matrix.testcase }}/parameters.tfvars ]] ; then opts="-var-file=../testcases/${{ matrix.testcase }}/parameters.tfvars" ; else opts="" ; fi
cd testing-framework/terraform/mock && terraform init && terraform apply -auto-approve -var="testcase=../testcases/${{ matrix.testcase }}" $opts
on_retry_command: |
cd testing-framework/terraform/mock && terraform destroy -auto-approve && sleep $((RANDOM % 10))
env:
DOCKER_BUILDKIT: 1 # Required for TARGETARCH to be populated with Docker compose.