forked from aws-observability/aws-otel-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
256 lines (219 loc) · 8.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
# 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
concurrency:
group: pr-build-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
changes:
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.filter.outputs.changed }}
steps:
- uses: actions/checkout@v2
- 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:
runs-on: ubuntu-latest
needs: changes
steps:
# 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@v2
with:
go-version: 1.17
- name: Checkout
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/checkout@v2
- name: Cache go
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/cache@v2
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: v1-go-pkg-mod-${{ runner.os }}-${{ hashFiles('**/go.sum') }}
- name: Cache binaries
id: cached_binaries
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/cache@v2
with:
key: "cached_binaries_${{ github.run_id }}"
path: build
# Unit Test and attach test coverage badge
- name: Unit Test
if: ${{ needs.changes.outputs.changed == 'true' && steps.cached_binaries.outputs.cache-hit != 'true' }}
run: make test
- name: Upload Coverage report to CodeCov
if: ${{ needs.changes.outputs.changed == 'true' && steps.cached_binaries.outputs.cache-hit != 'true' }}
uses: codecov/codecov-action@v2
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@v2
with:
name: binary_artifacts
path: build
packaging-msi:
runs-on: windows-latest
needs: [changes, build]
steps:
- name: Checkout
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/checkout@v2
- name: Download built artifacts
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/download-artifact@v2
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@v2
- name: restore cached binaries
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/cache@v2
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@v2
- name: Restore cached binaries
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/cache@v2
with:
key: "cached_binaries_${{ github.run_id }}"
path: build
- 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
get-test-cases:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Python
uses: actions/[email protected]
- name: Get all the testing suites
id: set-matrix
run: |
matrix=$(python e2etest/get-testcases.py local_matrix)
echo "::set-output name=matrix::$matrix"
- name: List testing suites
run: |
echo ${{ steps.set-matrix.outputs.matrix }}
run-test-case:
runs-on: ubuntu-latest
needs: [changes, get-test-cases, build]
strategy:
matrix: ${{ fromJson(needs.get-test-cases.outputs.matrix) }}
steps:
- name: Check out testing framework
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/checkout@v2
with:
repository: 'aws-observability/aws-otel-collector-test-framework'
path: testing-framework
- name: Check out Collector
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/checkout@v2
with:
path: aws-otel-collector
- name: Set up JDK 11
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '11'
- name: Set up terraform
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: hashicorp/[email protected]
- name: restore cached binaries
if: ${{ needs.changes.outputs.changed == 'true' }}
uses: actions/cache@v2
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: 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.