-
Notifications
You must be signed in to change notification settings - Fork 263
196 lines (171 loc) · 5.39 KB
/
Copy pathPR-build.yml
File metadata and controls
196 lines (171 loc) · 5.39 KB
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
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT
name: PR Build
on:
workflow_dispatch:
pull_request:
branches:
- main*
- feature*
types:
- opened
- synchronize
- reopened
- ready_for_review
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true
jobs:
changes:
name: Check changes
runs-on: ubuntu-latest
outputs:
build: ${{ steps.filter.outputs.build }}
lint: ${{ steps.filter.outputs.lint }}
steps:
- uses: actions/checkout@v3
- 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.build_files }}; do
echo "$file"
done
lint:
needs: [changes]
name: Check lint
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
if: needs.changes.outputs.lint == 'true'
uses: actions/setup-go@v4
with:
go-version: ~1.22.2
cache: false
- name: Check out code
if: needs.changes.outputs.lint == 'true'
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Check format
if: needs.changes.outputs.lint == 'true'
run: |
make fmt fmt-sh
if [ ! -z "`git status --porcelain`" ]; then
echo "make fmt changed files"
git status
exit 1
fi
- name: Check license and imports
if: needs.changes.outputs.lint == 'true'
run: make lint
build:
needs: [lint, changes]
name: Build ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-2022, windows-latest, macos-13]
include:
- os: ubuntu-latest
family: linux
cache-path: |
~/.cache/go-build
~/go/pkg/mod
- os: macos-13
family: darwin
cache-path: |
~/Library/Caches/go-build
~/go/pkg/mod
- os: windows-2022
family: windows
cache-path: |
~\AppData\Local\go-build
~\go\pkg\mod
- os: windows-latest
family: windows
cache-path: |
~\AppData\Local\go-build
~\go\pkg\mod
steps:
- name: Set up Go 1.x
if: needs.changes.outputs.build == 'true'
uses: actions/setup-go@v4
with:
go-version: ~1.22.2
cache: false
- name: Check out code
if: needs.changes.outputs.build == 'true'
uses: actions/checkout@v3
- name: Cache binaries
id: cached_binaries
if: needs.changes.outputs.build == 'true'
uses: actions/cache@v3
with:
key: "cached-binaries-${{ matrix.os }}-${{ github.sha }}"
path: go.mod
- name: Cache build output
if: steps.cached_binaries.outputs.cache-hit != 'true' && needs.changes.outputs.build == 'true'
uses: actions/cache@v3
with:
path: ${{ matrix.cache-path }}
key: v1-go-pkg-mod-${{ matrix.os }}-${{ hashFiles('**/go.sum') }}
- name: Install make
if: matrix.family == 'windows' && steps.cached_binaries.outputs.cache-hit != 'true' && needs.changes.outputs.build == 'true'
run: choco install make
- name: Unit Test
if: steps.cached_binaries.outputs.cache-hit != 'true' && needs.changes.outputs.build == 'true'
run: make test
- name: Build
if: steps.cached_binaries.outputs.cache-hit != 'true' && needs.changes.outputs.build == 'true'
run: make amazon-cloudwatch-agent-${{ matrix.family }}
test-data-race:
needs: [lint, changes]
name: Test data race
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
if: needs.changes.outputs.build == 'true'
uses: actions/setup-go@v4
with:
go-version: ~1.22.2
cache: false
- name: Check out code
if: needs.changes.outputs.build == 'true'
uses: actions/checkout@v3
- name: Test data race
if: needs.changes.outputs.build == 'true'
run: make test-data-race
verify-all:
name: Verify All PR Build Jobs
needs: [ changes, lint, build, test-data-race ]
runs-on: ubuntu-latest
if: always()
steps:
- name: Check Job Status
run: |
# Convert needs context to JSON and process with jq
needs_json='${{ toJSON(needs) }}'
failed_jobs=()
successful_jobs=()
# Loop through all jobs in needs context
for job in $(echo "$needs_json" | jq -r 'keys[]'); do
result=$(echo "$needs_json" | jq -r ".[\"$job\"].result")
if [[ "$result" == "failure" ]]; then
failed_jobs+=("$job")
elif [[ "$result" == "success" ]]; then
successful_jobs+=("$job")
fi
done
echo "Successfully validated jobs:"
printf '%s\n' "${successful_jobs[@]}"
if [ ${#failed_jobs[@]} -ne 0 ]; then
echo -e "\nFailed jobs:"
printf '%s\n' "${failed_jobs[@]}"
exit 1
fi
echo -e "\nAll required jobs completed without failures!"