1+ name : Docker
2+
3+ on :
4+ push :
5+ branches : [ beta ]
6+ tags : [ 'magg/v*' ]
7+ pull_request :
8+ branches : [ main, beta ]
9+ workflow_dispatch :
10+
11+ env :
12+ REGISTRY : ghcr.io
13+ IMAGE_NAME : ${{ github.repository }}
14+
15+ jobs :
16+ test-dev-container :
17+ runs-on : ubuntu-latest
18+ permissions :
19+ contents : read
20+ packages : write
21+
22+ strategy :
23+ matrix :
24+ python-version : ['3.12', '3.13']
25+ fail-fast : false
26+
27+ steps :
28+ - name : Checkout
29+ uses : actions/checkout@v4
30+
31+ - name : Set up Docker Buildx
32+ uses : docker/setup-buildx-action@v3
33+
34+ - name : Log in to Container Registry
35+ uses : docker/login-action@v3
36+ with :
37+ registry : ${{ env.REGISTRY }}
38+ username : ${{ github.actor }}
39+ password : ${{ secrets.GITHUB_TOKEN }}
40+
41+ - name : Extract metadata
42+ id : meta
43+ uses : docker/metadata-action@v5
44+ with :
45+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
46+ tags : |
47+ type=ref,event=branch,suffix=-dev-py${{ matrix.python-version }}
48+ type=ref,event=pr,suffix=-dev-py${{ matrix.python-version }}
49+ type=semver,pattern={{version}},suffix=-dev-py${{ matrix.python-version }}
50+ type=semver,pattern={{major}}.{{minor}},suffix=-dev-py${{ matrix.python-version }}
51+ type=raw,value=${{ github.ref == 'refs/heads/main' && 'dev' || format('{0}-dev', github.ref_name) }},enable=${{ matrix.python-version == '3.13' }}
52+
53+ - name : Build dev image
54+ uses : docker/build-push-action@v6
55+ with :
56+ context : .
57+ file : ./dockerfile
58+ target : dev
59+ push : false
60+ tags : ${{ steps.meta.outputs.tags }}
61+ # labels: ${{ steps.meta.outputs.labels }}
62+ build-args : |
63+ PYTHON_VERSION=${{ matrix.python-version }}
64+ cache-from : type=gha
65+ cache-to : type=gha,mode=max
66+ load : true
67+ provenance : false
68+ sbom : false
69+
70+ - name : Run tests in container
71+ run : |
72+ # Use the first tag only (multiple tags break the docker run command)
73+ FIRST_TAG=$(echo "${{ steps.meta.outputs.tags }}" | head -n1)
74+ docker run --rm \
75+ -e MAGG_LOG_LEVEL= \
76+ ${FIRST_TAG} \
77+ pytest -v
78+
79+ - name : Push dev image
80+ if : github.event_name != 'pull_request'
81+ uses : docker/build-push-action@v6
82+ with :
83+ context : .
84+ file : ./dockerfile
85+ target : dev
86+ push : true
87+ tags : ${{ steps.meta.outputs.tags }}
88+ # labels: ${{ steps.meta.outputs.labels }}
89+ build-args : |
90+ PYTHON_VERSION=${{ matrix.python-version }}
91+ cache-from : type=gha
92+ cache-to : type=gha,mode=max
93+ provenance : false
94+ sbom : false
95+
96+ build-and-push :
97+ needs : test-dev-container
98+ runs-on : ubuntu-latest
99+ permissions :
100+ contents : read
101+ packages : write
102+
103+ strategy :
104+ matrix :
105+ include :
106+ - target : pre
107+ suffix : " -pre"
108+ - target : pro
109+ suffix : " "
110+
111+ steps :
112+ - name : Checkout
113+ uses : actions/checkout@v4
114+
115+ - name : Set up Docker Buildx
116+ uses : docker/setup-buildx-action@v3
117+
118+ - name : Log in to Container Registry
119+ uses : docker/login-action@v3
120+ with :
121+ registry : ${{ env.REGISTRY }}
122+ username : ${{ github.actor }}
123+ password : ${{ secrets.GITHUB_TOKEN }}
124+
125+ - name : Extract metadata
126+ id : meta
127+ uses : docker/metadata-action@v5
128+ with :
129+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
130+ tags : |
131+ type=ref,event=branch,suffix=${{ matrix.suffix }}
132+ type=ref,event=pr,suffix=${{ matrix.suffix }}
133+ type=semver,pattern={{version}},suffix=${{ matrix.suffix }}
134+ type=semver,pattern={{major}}.{{minor}},suffix=${{ matrix.suffix }}
135+ type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' && matrix.target == 'pro' }}
136+
137+ - name : Build and push Docker image
138+ uses : docker/build-push-action@v6
139+ with :
140+ context : .
141+ file : ./dockerfile
142+ target : ${{ matrix.target }}
143+ push : ${{ github.event_name != 'pull_request' }}
144+ tags : ${{ steps.meta.outputs.tags }}
145+ # labels: ${{ steps.meta.outputs.labels }}
146+ cache-from : type=gha
147+ cache-to : type=gha,mode=max
148+ provenance : false
149+ sbom : false
150+
151+ cleanup-untagged :
152+ needs : [test-dev-container, build-and-push]
153+ runs-on : ubuntu-latest
154+ if : github.event_name != 'pull_request'
155+ permissions :
156+ packages : write
157+ steps :
158+ - name : Delete untagged images
159+ uses : actions/delete-package-versions@v5
160+ with :
161+ package-name : ' magg'
162+ package-type : ' container'
163+ delete-only-untagged-versions : ' true'
164+ min-versions-to-keep : 0
165+ token : ${{ secrets.GITHUB_TOKEN }}
0 commit comments