-
Notifications
You must be signed in to change notification settings - Fork 23
214 lines (194 loc) · 7.26 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
name: ci
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
pull_request:
branches:
- main
paths:
- "*.go"
- "**/*.go"
- Dockerfile
- docker-bake.hcl
- .github/workflows/ci.yml
- frontend/mariner2/Dockerfile
- "test/fixtures/*"
- go.mod
- go.sum
push:
branches:
- main
paths:
- "*.go"
- "**/*.go"
- Dockerfile
- docker-bake.hcl
- .github/workflows/ci.yml
- frontend/mariner2/Dockerfile
- go.mod
- go.sum
permissions:
contents: read
jobs:
lint:
runs-on: ubuntu-22.04
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
egress-policy: audit
- name: checkout
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: '1.22'
cache: false
# Use the golang-ci lint action which automattically sets up GHA caching and other things
# Note: There is also a "lint" target in docker-bake.hcl for local linting
# If you make changes to this, please make sure to also update the local linting target
- name: golangci-lint
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6.1.1
with:
version: v1.61
args: --timeout=30m
- name: validate generated files
run: |
go generate || exit $?
git diff --exit-code
if [ $? -ne 0 ]; then
echo "::error::Missing updates to generated files. Please run 'go generate' and commit the changes"
exit 1
fi
integration:
runs-on: ubuntu-22.04
# TODO: support diff/merge
# Right now this is handled by the e2e suite, but we can migrate that here.
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
egress-policy: audit
- name: checkout
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: '1.22'
cache: false
- name: Expose GitHub tokens for caching
uses: crazy-max/ghaction-github-runtime@b3a9207c0e1ef41f4cf215303c976869d0c2c1c4 # v3.0.0
- name: Setup jaeger
run: |
set -e
docker run -d --net=host --name jaeger -e COLLECTOR_OTLP_ENABLED=true jaegertracing/all-in-one:1.46
docker0_ip="$(ip -f inet addr show docker0 | grep -Po 'inet \K[\d.]+')"
echo "OTEL_EXPORTER_OTLP_ENDPOINT=http://${docker0_ip}:4318" >> "${GITHUB_ENV}"
echo "OTEL_SERVICE_NAME=dalec-integration-test" >> "${GITHUB_ENV}"
tmp="$(mktemp)"
echo "Environment=\"OTEL_EXPORTER_OTLP_ENDPOINT=http://${docker0_ip}:4318\"" > "${tmp}"
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo mkdir -p /etc/systemd/system/containerd.service.d
sudo cp "${tmp}" /etc/systemd/system/docker.service.d/otlp.conf
sudo cp "${tmp}" /etc/systemd/system/containerd.service.d/otlp.conf
sudo systemctl daemon-reload
sudo systemctl restart containerd
sudo systemctl restart docker
# Tests currently require buildkit v0.12.0 or higher
# The version of buildkit builtin to moby currently (v24) is too old
# So we need to setup a custom builder.
- name: Set up builder
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1
with:
driver-opts: |
network=host
env.OTLP_EXPORTER_OPTELP_ENDPOINT=http://127.0.0.1:4318
- name: download deps
run: go mod download
- name: Precache base images
run: go run ./cmd/ci-precache
- name: Run integration tests
run: go test -v -json ./test | go run ./cmd/test2json2gha --slow 5s
- name: dump logs
if: failure()
run: sudo journalctl -u docker
- name: Get traces
if: always()
run: |
set -ex
mkdir -p /tmp/reports
curl -sSLf localhost:16686/api/traces?service=${OTEL_SERVICE_NAME} > /tmp/reports/jaeger-trace.json
- name: Upload reports
if: always()
uses: actions/upload-artifact@v4
with:
name: integration-test-reports
path: /tmp/reports/*
retention-days: 1
unit:
runs-on: ubuntu-22.04
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
egress-policy: audit
- name: checkout
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: '1.22'
cache: false
- name: download deps
run: go mod download
- name: Run unit tests
run: go test -v --test.short --json ./... | go run ./cmd/test2json2gha
e2e:
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
disable_diff_merge: ["1", "0"]
name: "Test E2E (disable diff/merge: ${{ matrix.disable_diff_merge }})"
env:
DALEC_DISABLE_DIFF_MERGE: ${{ matrix.disable_diff_merge }}
FRONTEND_REF: localhost:5000/dalec/frontend
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
egress-policy: audit
- name: checkout
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
with:
# We need to fetch all commits so that we can diff against the base branch
fetch-depth: 0
- name: Expose GitHub tokens for caching
uses: crazy-max/ghaction-github-runtime@b3a9207c0e1ef41f4cf215303c976869d0c2c1c4 # v3.0.0
- name: Setup builder
run: |
# Sometimes the builder runs out of space... so cleanup anything we can first.
docker image prune -a -f
docker run -d --net=host registry
# If diff/merge are enabled we need to use a buildx builder to make sure the feature is supported.
# Otherwise we can just use the default docker builder.
if [ "${DALEC_DISABLE_DIFF_MERGE}" = "0" ]; then
docker buildx create --use --driver-opt network=host
echo FRONTEND_BAKE_TARGET="frontend-ci-full" >> $GITHUB_ENV
echo USE_BUILDX=1 >> $GITHUB_ENV
else
echo DALEC_NO_CACHE_EXPORT="1" >> $GITHUB_ENV
echo DALEC_DISABLE_NESTED="1" >> $GITHUB_ENV
echo FRONTEND_BAKE_TARGET="frontend-ci" >> $GITHUB_ENV
fi
- name: Build frontend image
run: docker buildx bake ${FRONTEND_BAKE_TARGET}
- name: test
run: |
docker buildx bake test
- name: dump logs
if: failure()
run: |
if [ "${USE_BUILDX}" = "1" ]; then
docker logs $(docker ps -lq)
else
sudo journalctl -u docker
fi