-
Notifications
You must be signed in to change notification settings - Fork 1
224 lines (184 loc) · 6.21 KB
/
Copy pathbuild.yaml
File metadata and controls
224 lines (184 loc) · 6.21 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
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
name: CI / Build and Push
on:
push:
branches: [main]
paths-ignore:
- "README.md"
- "CLAUDE.md"
- "config.yaml.example"
- "docs/**"
- "LICENSE"
pull_request:
branches: [main]
paths-ignore:
- "README.md"
- "CLAUDE.md"
- "config.yaml.example"
- "docs/**"
- "LICENSE"
workflow_dispatch:
jobs:
go-checks:
if: github.event_name != 'push'
runs-on: self-hosted
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Prepare web/dist placeholder for go:embed
run: mkdir -p web/dist && touch web/dist/.gitkeep
- name: go vet
run: go vet ./...
- name: go test
run: go test ./...
- name: go test -race -short
run: go test -race -short ./...
env:
CGO_ENABLED: "1"
- name: golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: v2.11.4
frontend-checks:
if: github.event_name != 'push'
runs-on: self-hosted
defaults:
run:
working-directory: web
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: "20"
- name: npm ci
run: npm ci
- name: npm run lint
run: npm run lint
- name: npm run test
run: npm run test --if-present
- name: npm run build
run: npm run build
- name: npm audit
run: npm audit --audit-level=high
govulncheck:
if: github.event_name != 'push'
runs-on: self-hosted
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Prepare web/dist placeholder for go:embed
run: mkdir -p web/dist && touch web/dist/.gitkeep
- name: Install govulncheck
run: go install golang.org/x/vuln/cmd/govulncheck@latest
# Fails only on symbol-level findings (your code actually calls the
# vulnerable symbol) that also have an upstream fix available.
# Module/package-level findings without a callable trace are noise from
# transitive deps and don't block CI.
- name: Run govulncheck (fail only on callable, fixable findings)
run: |
set -euo pipefail
govulncheck -format=json ./... > /tmp/vuln.json 2>&1 || true
FIXABLE=$(jq -s '[.[] | select(.finding != null
and (.finding.fixed_version // "") != ""
and (.finding.trace | any((.function // "") != "")))] | length' /tmp/vuln.json)
echo "callable + fixable findings: ${FIXABLE}"
govulncheck ./... || true
if [ "${FIXABLE:-0}" -gt 0 ]; then
echo "::error::Callable, fixable vulnerabilities detected. See output above."
exit 1
fi
echo "No callable, fixable vulnerabilities. Remaining findings are uncalled by this code or have no upstream fix."
hadolint:
if: github.event_name != 'push'
runs-on: self-hosted
steps:
- uses: actions/checkout@v6
- name: Hadolint
uses: hadolint/hadolint-action@v3.3.0
with:
dockerfile: Dockerfile
shellcheck:
if: github.event_name != 'push'
runs-on: self-hosted
steps:
- uses: actions/checkout@v6
- name: ShellCheck
uses: ludeeus/action-shellcheck@2.0.0
with:
scandir: scripts
image-scan:
if: github.event_name != 'push'
runs-on: self-hosted
steps:
- uses: actions/checkout@v6
- name: Prepare web/dist placeholder for go:embed
run: mkdir -p web/dist && touch web/dist/.gitkeep
- name: Build image for scan
run: docker build -t contextmatrix:scan .
- name: Trivy image scan
uses: aquasecurity/trivy-action@v0.36.0
with:
image-ref: contextmatrix:scan
format: table
severity: CRITICAL,HIGH
exit-code: "1"
ignore-unfixed: true
vuln-type: os,library
scanners: vuln
- name: Clean up scan image
if: always()
run: docker rmi contextmatrix:scan || true
build:
runs-on: self-hosted
needs: [go-checks, frontend-checks, govulncheck, hadolint, shellcheck, image-scan]
if: |
always() &&
(github.event_name == 'push' || github.event_name == 'workflow_dispatch') &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled')
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
fetch-tags: true
- name: Set image tag
run: |
SHORT_SHA="${GITHUB_SHA::7}"
echo "SHORT_SHA=${SHORT_SHA}" >> "$GITHUB_ENV"
if [ "${GITHUB_EVENT_NAME}" = "workflow_dispatch" ]; then
BRANCH_SLUG=$(echo "${GITHUB_REF_NAME}" | tr '[:upper:]' '[:lower:]' | sed 's|[^a-z0-9._-]|-|g' | cut -c1-50)
echo "IMAGE_TAG=${BRANCH_SLUG}-${SHORT_SHA}" >> "$GITHUB_ENV"
echo "PUSH_LATEST=false" >> "$GITHUB_ENV"
else
echo "IMAGE_TAG=${SHORT_SHA}" >> "$GITHUB_ENV"
echo "PUSH_LATEST=true" >> "$GITHUB_ENV"
fi
- name: Set version info
run: |
echo "BUILD_TIME=$(date -u '+%Y-%m-%d %H:%M')" >> "$GITHUB_ENV"
VERSION=$(git describe --tags --exact-match 2>/dev/null || true)
echo "VERSION=${VERSION}" >> "$GITHUB_ENV"
- name: Build image
run: |
TAGS="-t ${{ vars.REGISTRY }}/contextmatrix:${IMAGE_TAG}"
if [ "${PUSH_LATEST}" = "true" ]; then
TAGS="${TAGS} -t ${{ vars.REGISTRY }}/contextmatrix:latest"
fi
docker build \
--build-arg VERSION="${VERSION}" \
--build-arg GIT_COMMIT="${SHORT_SHA}" \
--build-arg BUILD_TIME="${BUILD_TIME}" \
${TAGS} \
.
- name: Push image
run: |
docker push ${{ vars.REGISTRY }}/contextmatrix:${IMAGE_TAG}
if [ "${PUSH_LATEST}" = "true" ]; then
docker push ${{ vars.REGISTRY }}/contextmatrix:latest
fi
- name: Clean up
if: always()
run: docker image prune -f