-
Notifications
You must be signed in to change notification settings - Fork 0
254 lines (235 loc) · 9.17 KB
/
Copy pathci.yml
File metadata and controls
254 lines (235 loc) · 9.17 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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
name: CI
on:
push:
branches: [main]
pull_request:
concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
permissions:
contents: read
jobs:
pre-commit-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
with:
enable-cache: true
- name: Install dev dependencies (pre-commit lives in geocomponents dev group)
run: uv sync --project geocomponents --frozen
- name: Cache pre-commit hook environments
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ runner.os }}-${{ hashFiles('.pre-commit-config.yaml') }}
restore-keys: |
pre-commit-${{ runner.os }}-
- name: Run pre-commit
run: uv run --project geocomponents pre-commit run --all-files --show-diff-on-failure
test:
runs-on: ubuntu-latest
services:
db:
image: postgis/postgis:16-3.4
env:
POSTGRES_USER: geocomponents
POSTGRES_PASSWORD: geocomponents
POSTGRES_DB: geocomponents
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U geocomponents"
--health-interval 3s
--health-timeout 3s
--health-retries 20
env:
DB_HOST: localhost
DB_PORT: "5432"
DB_NAME: geocomponents
DB_USER: geocomponents
DB_PASSWORD: geocomponents
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
with:
enable-cache: true
- name: Sync dependencies
run: uv sync --project geocomponents --frozen
- name: Run tests
working-directory: geocomponents
run: uv run pytest
test-gcimport:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
with:
enable-cache: true
- name: Sync dependencies
run: uv sync --project gcimport --frozen
- name: Run tests
working-directory: gcimport
run: uv run pytest
audit:
runs-on: ubuntu-latest
defaults:
run:
working-directory: geocomponents
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
with:
enable-cache: true
- name: Export runtime dependencies to requirements.txt
run: uv export --frozen --no-dev --no-emit-project --format requirements-txt -o requirements.txt
- name: Audit dependencies with pip-audit
run: uvx pip-audit -r requirements.txt --disable-pip
audit-gcimport:
runs-on: ubuntu-latest
defaults:
run:
working-directory: gcimport
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
with:
enable-cache: true
- name: Export runtime dependencies to requirements.txt
run: uv export --frozen --no-dev --no-emit-project --format requirements-txt -o requirements.txt
- name: Audit dependencies with pip-audit
run: uvx pip-audit -r requirements.txt --disable-pip
# Builds each Docker image on every PR and every push, loads it into the local
# Docker daemon (no registry credentials), and fails the run on HIGH/CRITICAL
# OS or library CVEs. Populates the GHA build cache so `publish` can reuse
# layers.
build-and-scan:
needs: [pre-commit-lint, test, test-gcimport, audit, audit-gcimport]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- service: geocomponents
context: ./geocomponents
local_tag: geocomponents:scan
image_name: ${{ github.repository }}-geocomponents
cache_scope: geocomponents
- service: gcimport
context: ./gcimport
local_tag: gcimport:scan
image_name: ${{ github.repository }}-gcimport
cache_scope: gcimport
- service: gccore
context: ./gccore
local_tag: gccore:scan
image_name: ${{ github.repository }}-gccore
cache_scope: gccore
- service: gcjobs
context: ./gcjobs
local_tag: gcjobs:scan
image_name: ${{ github.repository }}-gcjobs
cache_scope: gcjobs
- service: gcmapview
context: ./gcmapview
local_tag: gcmapview:scan
image_name: ${{ github.repository }}-gcmapview
cache_scope: gcmapview
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4.2.0
- name: Build ${{ matrix.service }} image (load into local daemon for scanning)
uses: docker/build-push-action@cb941d0b895b09c17fa011d41c411b33c752cf28 # v6.16.0
with:
context: ${{ matrix.context }}
load: true
tags: ${{ matrix.local_tag }}
cache-from: type=gha,scope=${{ matrix.cache_scope }}
cache-to: type=gha,mode=max,scope=${{ matrix.cache_scope }}
- name: Trivy vulnerability scan
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
with:
image-ref: ${{ matrix.local_tag }}
format: table
exit-code: '1'
ignore-unfixed: true
vuln-type: 'os,library'
severity: 'CRITICAL,HIGH'
# Publishes one GHCR artifact per Dockerfile only on merges to main. Depends
# on build-and-scan so a failing Trivy scan (or lint/test) blocks publish.
# Rebuilds via buildx but `cache-from: type=gha` makes it a near-no-op that
# just re-tags and pushes.
publish:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: [build-and-scan]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- service: geocomponents
context: ./geocomponents
image_name: ${{ github.repository }}-geocomponents
cache_scope: geocomponents
- service: gcimport
context: ./gcimport
image_name: ${{ github.repository }}-gcimport
cache_scope: gcimport
- service: gccore
context: ./gccore
image_name: ${{ github.repository }}-gccore
cache_scope: gccore
- service: gcjobs
context: ./gcjobs
image_name: ${{ github.repository }}-gcjobs
cache_scope: gcjobs
- service: gcmapview
context: ./gcmapview
image_name: ${{ github.repository }}-gcmapview
cache_scope: gcmapview
permissions:
contents: read
packages: write
attestations: write
id-token: write
env:
REGISTRY: ghcr.io
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4.2.0
- name: Log in to the Container registry
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@703896b4f30f62d53f5530a80bcdc589a3f702bc # v5.7.0
with:
images: ${{ env.REGISTRY }}/${{ matrix.image_name }}
tags: |
# Always tag with short git SHA (e.g. a1b2c3d)
type=sha,prefix=,format=short
# On v*.*.* tags, also tag with the semver (e.g. 1.2.3)
type=semver,pattern={{version}}
# Tag latest on every push to the default branch
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push ${{ matrix.service }} Docker image
id: push
uses: docker/build-push-action@cb941d0b895b09c17fa011d41c411b33c752cf28 # v6.16.0
with:
context: ${{ matrix.context }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=${{ matrix.cache_scope }}
cache-to: type=gha,mode=max,scope=${{ matrix.cache_scope }}
- name: Generate ${{ matrix.service }} artifact attestation
uses: actions/attest-build-provenance@0f67c3f4856b2e3261c31976d6725780e5e4c373 # v4.1.1
with:
subject-name: ${{ env.REGISTRY }}/${{ matrix.image_name }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true