forked from ApeWorX/ape
-
Notifications
You must be signed in to change notification settings - Fork 1
276 lines (248 loc) · 11 KB
/
Copy pathbuild.yaml
File metadata and controls
276 lines (248 loc) · 11 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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
name: Container Images
on:
push:
branches:
- main
pull_request:
release:
types: [published]
env:
DEFAULT_PYTHON: "3.11"
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
build:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
env:
CACHE_TRUST_PREFIX: pr
permissions:
contents: read
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
target: ["slim", "full"]
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: 0 # Needed for setuptools-scm
# NOTE: We need to store `uv.lock` for building with
- uses: astral-sh/setup-uv@v7
with:
enable-cache: true
cache-dependency-glob: pyproject.toml
- uses: actions/cache@v5
with:
path: uv.lock
key: ${{ env.CACHE_TRUST_PREFIX }}-${{ matrix.python-version }}-uv-lock-${{ hashFiles('pyproject.toml') }}
restore-keys: |
${{ env.CACHE_TRUST_PREFIX }}-${{ matrix.python-version }}-uv-lock-
- run: uv lock --python ${{ matrix.python-version }}
- name: Get version from setuptools-scm
id: version
run: |
VERSION=$(uvx setuptools-scm)
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Check if default Python version
id: is-default
run: |
if [ "${{ matrix.python-version }}" = "${{ env.DEFAULT_PYTHON }}" ]; then
echo "value=true" >> $GITHUB_OUTPUT
else
echo "value=false" >> $GITHUB_OUTPUT
fi
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log into GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
latest=false
suffix=${{ matrix.target == 'slim' && '-slim' || ''}}
# NOTE: `latest=false` lets us manage it better here
tags: |
# For default Python version (unprefixed convenience tags)
# - 'latest' on push to main
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' && steps.is-default.outputs.value == 'true' }}
# - 'stable' on release
type=raw,value=stable,enable=${{ github.event_name == 'release' && steps.is-default.outputs.value == 'true' }}
# - version tag (e.g., v0.8.43) on release
type=ref,event=tag,enable=${{ steps.is-default.outputs.value == 'true' }}
# For all Python versions (including default):
# - 'python3.x-latest' on push to main
type=raw,value=python${{ matrix.python-version }}-latest,enable=${{ github.ref == 'refs/heads/main' }}
# - 'python3.x-stable' on release
type=raw,value=python${{ matrix.python-version }}-stable,enable=${{ github.event_name == 'release' }}
# - 'python3.x-v*' on release
type=ref,event=tag,prefix=python${{ matrix.python-version }}-,enable=${{ github.event_name == 'release' }}
# PR tags for testing (not pushed)
type=ref,event=pr,prefix=python${{ matrix.python-version }}-pr-
labels: |
org.opencontainers.image.title=ape
org.opencontainers.image.description=Build and explore on-chain with Python
org.opencontainers.image.url=https://apeworx.io/framework
org.opencontainers.image.documentation=https://docs.apeworx.io/ape/stable/userguides/quickstart
org.opencontainers.image.source=https://github.com/ApeWorX/ape
org.opencontainers.image.vendor=ApeWorX LTD
org.opencontainers.image.licenses=Apache-2.0
org.opencontainers.image.version=${{ steps.version.outputs.version }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.authors=ApeWorX LTD
org.opencontainers.image.base.name=python:${{ matrix.python-version }}-slim
- name: Build and push (if required) slim image
id: build
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
target: ${{ matrix.target }}
build-args: |
PYTHON_VERSION=${{ matrix.python-version }}
APE_VERSION=${{ steps.version.outputs.version }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=${{ env.CACHE_TRUST_PREFIX }}-build-py${{ matrix.python-version }}-${{ matrix.target }}
cache-to: type=gha,mode=max,scope=${{ env.CACHE_TRUST_PREFIX }}-build-py${{ matrix.python-version }}-${{ matrix.target }}
platforms: ${{ github.event_name != 'pull_request' && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
- name: Run container retention policy
if: ${{ github.event_name != 'pull_request' }}
# TODO: Use `v3` when available
uses: snok/container-retention-policy@v3.1.0
with:
account: ApeWorX
token: ${{ secrets.GITHUB_TOKEN }}
image-names: "ape"
# NOTE: Keep stable/stable-slim, latest/latest-slim, all v0.8.x series, and last in v0.7.x series
image-tags: "!stable* !latest* !v0.8* !v0.7.23*"
tag-selection: both
cut-off: 4w
dry-run: ${{ github.ref != 'refs/heads/main' }}
publish:
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
env:
CACHE_TRUST_PREFIX: trusted
permissions:
contents: read
packages: write
attestations: write
id-token: write
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
target: ["slim", "full"]
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: 0 # Needed for setuptools-scm
# NOTE: We need to store `uv.lock` for building with
- uses: astral-sh/setup-uv@v7
- uses: actions/cache@v5
with:
path: uv.lock
key: ${{ env.CACHE_TRUST_PREFIX }}-${{ matrix.python-version }}-uv-lock-${{ hashFiles('pyproject.toml') }}
restore-keys: |
${{ env.CACHE_TRUST_PREFIX }}-${{ matrix.python-version }}-uv-lock-
- run: uv lock --python ${{ matrix.python-version }}
- name: Get version from setuptools-scm
id: version
run: |
VERSION=$(uvx setuptools-scm)
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Check if default Python version
id: is-default
run: |
if [ "${{ matrix.python-version }}" = "${{ env.DEFAULT_PYTHON }}" ]; then
echo "value=true" >> $GITHUB_OUTPUT
else
echo "value=false" >> $GITHUB_OUTPUT
fi
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log into GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
latest=false
suffix=${{ matrix.target == 'slim' && '-slim' || ''}}
# NOTE: `latest=false` lets us manage it better here
tags: |
# For default Python version (unprefixed convenience tags)
# - 'latest' on push to main
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' && steps.is-default.outputs.value == 'true' }}
# - 'stable' on release
type=raw,value=stable,enable=${{ github.event_name == 'release' && steps.is-default.outputs.value == 'true' }}
# - version tag (e.g., v0.8.43) on release
type=ref,event=tag,enable=${{ steps.is-default.outputs.value == 'true' }}
# For all Python versions (including default):
# - 'python3.x-latest' on push to main
type=raw,value=python${{ matrix.python-version }}-latest,enable=${{ github.ref == 'refs/heads/main' }}
# - 'python3.x-stable' on release
type=raw,value=python${{ matrix.python-version }}-stable,enable=${{ github.event_name == 'release' }}
# - 'python3.x-v*' on release
type=ref,event=tag,prefix=python${{ matrix.python-version }}-,enable=${{ github.event_name == 'release' }}
labels: |
org.opencontainers.image.title=ape
org.opencontainers.image.description=Build and explore on-chain with Python
org.opencontainers.image.url=https://apeworx.io/framework
org.opencontainers.image.documentation=https://docs.apeworx.io/ape/stable/userguides/quickstart
org.opencontainers.image.source=https://github.com/ApeWorX/ape
org.opencontainers.image.vendor=ApeWorX LTD
org.opencontainers.image.licenses=Apache-2.0
org.opencontainers.image.version=${{ steps.version.outputs.version }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.authors=ApeWorX LTD
org.opencontainers.image.base.name=python:${{ matrix.python-version }}-slim
- name: Build and push image
id: build
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
target: ${{ matrix.target }}
build-args: |
PYTHON_VERSION=${{ matrix.python-version }}
APE_VERSION=${{ steps.version.outputs.version }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=${{ env.CACHE_TRUST_PREFIX }}-build-py${{ matrix.python-version }}-${{ matrix.target }}
cache-to: type=gha,mode=max,scope=${{ env.CACHE_TRUST_PREFIX }}-build-py${{ matrix.python-version }}-${{ matrix.target }}
platforms: linux/amd64,linux/arm64
- name: Run container retention policy
# TODO: Use `v3` when available
uses: snok/container-retention-policy@v3.1.0
with:
account: ApeWorX
token: ${{ secrets.GITHUB_TOKEN }}
image-names: "ape"
# NOTE: Keep stable/stable-slim, latest/latest-slim, all v0.8.x series, and last in v0.7.x series
image-tags: "!stable* !latest* !v0.8* !v0.7.23*"
tag-selection: both
cut-off: 4w
dry-run: ${{ github.ref != 'refs/heads/main' }}