-
Notifications
You must be signed in to change notification settings - Fork 0
223 lines (191 loc) · 7.48 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
name: ci
on:
push:
branches:
- main
tags:
- "**"
pull_request:
branches:
- main
merge_group:
branches:
- main
jobs:
context:
strategy:
matrix:
os: [ubuntu-latest]
name: context
runs-on: ${{ matrix.os }}
steps:
- name: Dump GitHub script context
uses: actions/github-script@v7
with:
script: console.log(context)
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo ${GITHUB_CONTEXT}
- name: Dump job context
env:
JOB_CONTEXT: ${{ toJson(job) }}
run: echo ${JOB_CONTEXT}
- name: Dump steps context
env:
STEPS_CONTEXT: ${{ toJson(steps) }}
run: echo ${STEPS_CONTEXT}
- name: Dump runner context
env:
RUNNER_CONTEXT: ${{ toJson(runner) }}
run: echo ${RUNNER_CONTEXT}
- name: Dump strategy context
env:
STRATEGY_CONTEXT: ${{ toJson(strategy) }}
run: echo ${STRATEGY_CONTEXT}
- name: Dump matrix context
env:
MATRIX_CONTEXT: ${{ toJson(matrix) }}
run: echo ${MATRIX_CONTEXT}
- name: Dump environment variables
run: ${{ (runner.os == 'Windows') && 'gci env:' || 'env | sort' }}
python:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python: [3.12]
name: python
runs-on: ${{ matrix.os }}
env:
ENVIRONMENT: ci
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Poetry
run: |
pipx install poetry
poetry config virtualenvs.in-project true
- name: Set up Python
id: setup-python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
cache: poetry
- name: Set up environment
if: ${{ runner.os != 'Windows' }}
run: |
echo "POETRY_CACHE_DIR=$(poetry config cache-dir)" >> ${GITHUB_ENV}
echo "$(poetry env info --path)/bin" >> ${GITHUB_PATH}
- name: Set up environment (Windows)
if: ${{ runner.os == 'Windows' }}
run: |
"POETRY_CACHE_DIR=$(poetry config cache-dir)" | Out-File -FilePath ${env:GITHUB_ENV} -Append
"$(poetry env info --path)/Scripts" | Out-File -FilePath ${env:GITHUB_PATH} -Append
- name: Poetry cache
if: ${{ steps.setup-python.outputs.cache-hit != 'true' }}
uses: actions/cache@v4
with:
path: ${{ env.POETRY_CACHE_DIR }}
key: pypoetry-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
pypoetry-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}
pypoetry-${{ runner.os }}
- name: Install dependencies
run: poetry install --no-interaction
- name: Lint and test
run: make lint test
docker:
name: docker
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
env:
GHCR_IMAGE_NAME: ghcr.io/${{ github.repository }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
sparse-checkout: |
Dockerfile
poetry.lock
- name: Cache buildkit mounts
uses: actions/cache@v4
with:
path: |
var-cache-apt
root-cache-pip
root-cache-pypoetry
key: buildkit-mounts-${{ runner.os }}-${{ hashFiles('**/Dockerfile', '**/poetry.lock') }}
restore-keys: |
buildkit-mounts-${{ runner.os }}
buildkit-mounts-${{ runner.os }}
- name: Inject var-cache-apt into docker
uses: reproducible-containers/buildkit-cache-dance@v3
with:
cache-source: var-cache-apt
cache-target: /var/cache/apt
- name: Inject root-cache-pip into docker
uses: reproducible-containers/buildkit-cache-dance@v3
with:
cache-source: root-cache-pip
cache-target: /root/.cache/pip
- name: Inject root-cache-pypoetry into docker
uses: reproducible-containers/buildkit-cache-dance@v3
with:
cache-source: root-cache-pypoetry
cache-target: /root/.cache/pypoetry
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build CI image
id: build-ci
env:
ENVIRONMENT: ci
uses: docker/build-push-action@v6
with:
target: ${{ env.ENVIRONMENT }}
cache-from: |
${{ env.GHCR_IMAGE_NAME }}:dev
${{ env.GHCR_IMAGE_NAME }}:cache
load: true
- name: Run CI image
run: docker run --rm ${{ steps.build-ci.outputs.imageid }}
- name: Docker metadata
id: docker_metadata
uses: docker/metadata-action@v5
with:
images: ${{ env.GHCR_IMAGE_NAME }}
- name: Login to GHCR
if: ${{ github.event_name != 'pull_request' }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push dev image
if: ${{ github.event_name != 'pull_request' }}
env:
ENVIRONMENT: dev
uses: docker/build-push-action@v6
with:
target: ${{ env.ENVIRONMENT }}
cache-from: |
${{ env.GHCR_IMAGE_NAME }}:dev
${{ env.GHCR_IMAGE_NAME }}:cache
cache-to: type=inline
tags: ${{ env.GHCR_IMAGE_NAME }}:dev
push: ${{ github.event_name != 'pull_request' }}
- name: Build and push prod image
if: ${{ github.event_name != 'pull_request' }}
env:
ENVIRONMENT: prod
uses: docker/build-push-action@v6
with:
cache-from: |
${{ env.GHCR_IMAGE_NAME }}:dev
${{ env.GHCR_IMAGE_NAME }}:cache
cache-to: type=registry,ref=${{ env.GHCR_IMAGE_NAME }}:cache,mode=max
tags: ${{ steps.docker_metadata.outputs.tags }}
labels: ${{ steps.docker_metadata.outputs.labels }}
annotations: ${{ steps.docker_metadata.outputs.annotations }}
push: ${{ github.event_name != 'pull_request' }}