forked from G-Research/fasttrackml
-
Notifications
You must be signed in to change notification settings - Fork 0
244 lines (208 loc) · 7.15 KB
/
ci.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
name: CI
on:
push:
pull_request:
schedule:
# Run daily at 01:34 so we get notified if CI is broken before a pull request
# is submitted.
- cron: "34 1 * * *"
permissions:
contents: read
jobs:
lint:
if: github.event_name == 'schedule' || github.event_name == 'push' || github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: "1.20"
- name: Read build tags
id: tags
run: echo tags=$(jq -r '."go.buildTags"' .vscode/settings.json) >> $GITHUB_OUTPUT
- name: Download formatters
run: |
go install golang.org/x/tools/cmd/goimports@v0.11.0
go install mvdan.cc/gofumpt@v0.5.0
- name: Check formatting
run: |
unformatted=$(
gofumpt -l .
goimports -l --local github.com/G-Research/fasttrackml .
)
if [ -n "$unformatted" ]; then
for file in $unformatted; do
echo "::error file=$file::$file is not formatted properly (hint: run \"make go-format\" to fix this)"
done
exit 1
fi
- name: Download mockery
run: go install github.com/vektra/mockery/v2@v2.30.16
- name: Generate mocks
run: make mocks-generate
- name: Check with go vet
run: go vet --tags "${{ steps.tags.outputs.tags }}" ./...
- uses: dominikh/staticcheck-action@v1.3.0
with:
version: "2022.1.3"
build-tags: ${{ steps.tags.outputs.tags }}
golang-unit-tests:
if: github.event_name == 'schedule' || github.event_name == 'push' || github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id
name: Golang Unit Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: "1.20"
- name: Download mockery
run: go install github.com/vektra/mockery/v2@v2.30.16
- name: Generate mocks
run: make mocks-generate
- name: Run Golang Unit Tests
run: make test-go-unit
golang-integration-tests:
if: github.event_name == 'schedule' || github.event_name == 'push' || github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id
name: Golang Integration Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: "1.20"
- name: Run Integration Tests
run: make service-test
env:
DOCKER_BUILDKIT: 1
python-integration-tests:
if: github.event_name == 'schedule' || github.event_name == 'push' || github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id
name: Python Integration Tests
runs-on: ubuntu-latest
strategy:
matrix:
api: [aim, mlflow]
fail-fast: false
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test
LC_COLLATE: POSIX
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: "1.20"
- name: Run ${{ matrix.api }} integration tests
run: ./tests/integration/python/${{ matrix.api }}/test.sh
build-image:
if: github.event_name == 'schedule' || github.event_name == 'push' || github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id
name: Build container image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Compute build args
id: build-args
run: |
echo tags=$(jq -r '."go.buildTags"' .vscode/settings.json) >> $GITHUB_OUTPUT
echo version=$(git describe --tags | sed 's/^v//') >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: fasttrackml
tags: |
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=edge
- name: Build container image
uses: docker/build-push-action@v4
with:
context: .
build-args: |
tags=${{ steps.build-args.outputs.tags }}
version=${{ steps.build-args.outputs.version }}
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false
sbom: false
outputs: type=oci,dest=fasttrackml-oci.tar
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: fasttrackml-oci-image
path: fasttrackml-oci.tar
# Virtual job that can be configured as a required check before a PR can be merged.
all-required-checks-done:
name: All required checks done
needs:
- lint
- golang-unit-tests
- golang-integration-tests
- python-integration-tests
- build-image
runs-on: ubuntu-latest
steps:
- run: echo "All required checks done"
# Publish any push to a branch or tag to ghcr.io as a convenience
# Actual release to Docker Hub happens in a different workflow
push-ghcr:
name: Push to GitHub Container Registry
if: github.event_name == 'push'
runs-on: ubuntu-latest
needs: all-required-checks-done
permissions:
packages: write
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: fasttrackml-oci-image
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Compute repo name
id: repo
run: echo name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_OUTPUT
- name: Push to GitHub Container Registry
run: |
tags=$(tar -xOf fasttrackml-oci.tar index.json | jq -r '.manifests[].annotations."org.opencontainers.image.ref.name"')
for tag in $tags
do
echo "::group::Pushing image to ghcr.io/${{ steps.repo.outputs.name }}:$tag"
skopeo copy --all oci-archive:fasttrackml-oci.tar:$tag docker://ghcr.io/${{ steps.repo.outputs.name }}:$tag
echo "::endgroup::"
done