-
Notifications
You must be signed in to change notification settings - Fork 11
199 lines (178 loc) · 5.75 KB
/
build-and-test.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
name: build-and-test
on:
pull_request:
push:
branches:
- main
jobs:
npm-install-if-needed:
runs-on: ubuntu-20.04
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set up Node 16
uses: actions/setup-node@v2
with:
node-version: '16'
- id: cache
name: Cache node modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json') }}
- name: NPM Install
if: steps.cache.outputs.cache-hit != 'true'
run: npm ci
build:
runs-on: ubuntu-20.04
needs: [npm-install-if-needed]
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set up Node 16
uses: actions/setup-node@v2
with:
node-version: '16'
cache: 'npm'
- name: Cache node modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json') }}
- name: Build
run: npm run build:ci
- name: Archive build artifacts
uses: actions/upload-artifact@v2
with:
name: dist
path: dist
lint:
runs-on: ubuntu-20.04
needs: [npm-install-if-needed]
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Restore node modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json') }}
- name: Lint
run: npm run lint
- name: Prettier Check
run: npm run prettier:check
setup-test-batches:
runs-on: ubuntu-20.04
needs: [npm-install-if-needed]
env:
PARALLELISM: 4
outputs:
test-chunks: ${{ steps['set-test-chunks'].outputs['test-chunks'] }}
test-chunk-ids: ${{ steps['set-test-chunk-ids'].outputs['test-chunk-ids'] }}
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Cache node modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json') }}
- id: set-test-chunks
name: Set Chunks
run: echo "::set-output name=test-chunks::$(npx jest --listTests --json | jq -cM "[_nwise(length / $PARALLELISM | ceil)]")"
- id: set-test-chunk-ids
name: Set Chunk IDs
run: echo "::set-output name=test-chunk-ids::$(echo $CHUNKS | jq -cM 'to_entries | map(.key)')"
env:
CHUNKS: ${{ steps['set-test-chunks'].outputs['test-chunks'] }}
test:
name: test (chunk ${{ matrix.chunk }})
runs-on: ubuntu-20.04
needs: [npm-install-if-needed, setup-test-batches]
strategy:
fail-fast: false
matrix:
chunk: ${{ fromJson(needs['setup-test-batches'].outputs['test-chunk-ids']) }}
steps:
- name: Check out code
uses: actions/checkout@v2
# Used by CCI uploader to detect base commit
with:
fetch-depth: 0
- name: Cache node modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json') }}
- name: Test
run: npm run test:ci -- $(echo $CHUNKS | jq -r '.[${{ matrix.chunk }}] | .[] | "--test-path-pattern "+.')
env:
CHUNKS: ${{ needs['setup-test-batches'].outputs['test-chunks'] }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
fail_ci_if_error: true
- name: Upload Unit Test Results
if: always()
uses: actions/upload-artifact@v2
with:
name: Unit Test Results (chunk ${{ matrix.chunk }})
path: test-results/**/*.xml
validate-helm-charts:
runs-on: ubuntu-20.04
steps:
- name: Check out code
uses: actions/checkout@v2
- name: validate charts
uses: hypertrace/github-actions/validate-charts@main
publish-test-results:
name: "Publish Unit Tests Results"
needs: test
runs-on: ubuntu-20.04
# Only run if prereq jobs completed - successfully or not
if: success() || failure()
steps:
- name: Download Artifacts
uses: actions/download-artifact@v2
with:
path: artifacts
- name: Publish Unit Test Results
uses: docker://ghcr.io/enricomi/publish-unit-test-result-action:v1.6
continue-on-error: true
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
files: artifacts/**/*.xml
merge-publish:
if: github.event_name == 'push'
runs-on: ubuntu-20.04
needs: [npm-install-if-needed, build, lint, test, validate-helm-charts]
steps:
- name: Check out code
uses: actions/checkout@v2
# Used by gradle version calculation
with:
fetch-depth: 0
- name: Create checksum file
uses: hypertrace/github-actions/checksum@main
- name: Cache gradle
uses: actions/cache@v2
with:
path: ~/.gradle
key: gradle-${{ runner.os }}-${{ hashFiles('**/checksum.txt') }}
restore-keys: |
gradle-${{ runner.os }}
- name: Download build results
uses: actions/download-artifact@v2
with:
name: dist
path: dist
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_READ_USER }}
password: ${{ secrets.DOCKERHUB_READ_TOKEN }}
- name: Push docker image
run: ./gradlew dockerPushImages
env:
DOCKER_USERNAME: ${{ secrets.DOCKERHUB_PUBLISH_USER }}
DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_PUBLISH_TOKEN }}