-
Notifications
You must be signed in to change notification settings - Fork 123
237 lines (206 loc) · 6.19 KB
/
pr-test.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
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
---
name: CI
on:
pull_request:
branches:
- main
- 'v*'
jobs:
changes:
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
code: ${{ steps.filter.outputs.code }}
docs: ${{ steps.filter.outputs.docs }}
protos: ${{ steps.filter.outputs.protos }}
steps:
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
code:
- '!(docs/**)'
docs:
- .github/workflows/pr-test.yaml
- 'docs/**'
protos:
- .github/workflows/pr-test.yaml
- '**/*.proto'
cache:
uses: ./.github/workflows/cache.yaml
generate:
needs: changes
if: ${{ needs.changes.outputs.code == 'true' }}
name: Generate
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Go and restore cached dependencies
uses: ./.github/actions/setup-go
- name: Generate
run: make generate
- name: Check repo status
run: |-
REPO_STATUS="$(git status --porcelain)"
if [[ ! -z $REPO_STATUS ]]; then
echo "::error::Uncommitted changes detected"
echo "$REPO_STATUS"
exit 1
fi
download-test-times:
name: Download test times
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Download previous test times
continue-on-error: true
uses: dawidd6/action-download-artifact@v2
with:
workflow: pr-test.yaml
name: test-times
search_artifacts: true
- name: Upload previous test times
uses: actions/upload-artifact@v3
with:
name: previous-test-times
path: test-times.json
test:
needs:
- changes
- download-test-times
if: ${{ needs.changes.outputs.code == 'true' }}
name: Test
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
split: [0, 1, 2, 3, 4, 5]
outputs:
job-total: ${{ strategy.job-total }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
lfs: true
- name: Install Go and restore cached dependencies
uses: ./.github/actions/setup-go
- name: Download previous test times
uses: actions/download-artifact@v3
with:
name: previous-test-times
- name: Test
run: make test-all TESTSPLIT_INDEX=${{ strategy.job-index }} TESTSPLIT_TOTAL=${{ strategy.job-total }}
env:
GOEXPERIMENT: loopvar # https://github.com/golang/go/wiki/LoopvarExperiment
CERBOS_LOG_LEVEL: "debug"
CERBOS_TEST_LOG_LEVEL: "debug"
CERBOS_DEBUG_DB: "true"
CERBOS_DEBUG_ENGINE: "true"
- name: Upload JUnit reports
uses: actions/upload-artifact@v3
with:
name: junit-reports-${{ strategy.job-index }}
path: junit.*.xml
- name: Upload unit coverage to Coveralls
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: unit.cover
flag-name: unit-${{ strategy.job-index }}
parallel: true
- name: Upload integration coverage to Coveralls
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: integration.cover
flag-name: integration-${{ strategy.job-index }}
parallel: true
upload-test-times:
needs: test
if: ${{ always() && needs.test.result != 'skipped' }}
name: Upload test times
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Check test results
run: test "${{ needs.test.result }}" = "success"
- name: Checkout code
uses: actions/checkout@v4
- name: Install Go and restore cached dependencies
uses: ./.github/actions/setup-go
- name: Download JUnit reports
uses: actions/download-artifact@v3
- name: Combine JUnit reports
run: |-
mv junit-reports-*/junit.*.xml .
make test-times TESTSPLIT_TOTAL=${{ needs.test.outputs.job-total }}
- name: Upload new test times
uses: actions/upload-artifact@v3
with:
name: test-times
path: test-times.json
- name: Complete coveralls report
uses: shogo82148/actions-goveralls@v1
with:
parallel-finished: true
docs:
needs: changes
if: ${{ needs.changes.outputs.docs == 'true' }}
name: Build docs
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
lfs: true
- name: Generate docs
uses: ./.github/actions/antora-docs
id: docs
golangci:
needs: changes
if: ${{ needs.changes.outputs.code == 'true' }}
name: Lint
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 1.21.x
check-latest: true
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3.7.0
with:
version: latest
args: '--config=.golangci.yaml -v'
buf:
needs: changes
if: ${{ needs.changes.outputs.protos == 'true' }}
name: Proto check
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Setup Buf
uses: bufbuild/buf-setup-action@v1.27.0
with:
github_token: ${{ github.token }}
- name: Lint protos
uses: bufbuild/buf-lint-action@v1.1.0
- name: Check formatting
run: buf format --diff --exit-code
- name: Find latest release
id: latest-release
run: gh release view --json tagName --jq '"tag=\(.tagName)"' >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ github.token }}
- name: Check backwards compatibility
uses: cerbos/buf-breaking-action@since
with:
against: https://github.com/cerbos/cerbos.git#tag=${{ steps.latest-release.outputs.tag }}
since: https://github.com/cerbos/cerbos.git#branch=main