Skip to content

Commit ccd1392

Browse files
committed
ci: use registry push/pull pattern like gitlab ci
1 parent 576fc3d commit ccd1392

1 file changed

Lines changed: 45 additions & 45 deletions

File tree

.github/workflows/ci.yml

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -54,35 +54,47 @@ jobs:
5454
timeout-minutes: 30
5555
needs: check-changes
5656
if: needs.check-changes.outputs.source-changed == 'true'
57+
outputs:
58+
image-tag: ${{ steps.meta.outputs.tags }}
59+
image-digest: ${{ steps.build.outputs.digest }}
5760
steps:
5861
- name: Checkout repository
5962
uses: actions/checkout@v6
6063

6164
- name: Set up Docker Buildx
6265
uses: docker/setup-buildx-action@v3
6366

64-
- name: Build CI image
67+
- name: Log in to GitHub Container Registry
68+
uses: docker/login-action@v3
69+
with:
70+
registry: ghcr.io
71+
username: ${{ github.actor }}
72+
password: ${{ secrets.GITHUB_TOKEN }}
73+
74+
- name: Extract metadata
75+
id: meta
76+
uses: docker/metadata-action@v5
77+
with:
78+
images: ghcr.io/${{ github.repository }}/ci
79+
tags: |
80+
type=ref,event=branch
81+
type=ref,event=pr
82+
type=sha,prefix={{branch}}-
83+
type=raw,value={{branch}}-{{workflow}}-{{run_id}}
84+
85+
- name: Build and push CI image
86+
id: build
6587
timeout-minutes: 20
6688
uses: docker/build-push-action@v6
6789
with:
6890
context: .
6991
file: ./Dockerfile.ci
70-
tags: cutile-ci:${{ github.sha }}
92+
push: true
93+
tags: ${{ steps.meta.outputs.tags }}
94+
labels: ${{ steps.meta.outputs.labels }}
7195
cache-from: type=gha
7296
cache-to: type=gha,mode=max
73-
load: true
74-
outputs: type=docker,compression=zstd
75-
76-
- name: Export CI image
77-
run: |
78-
docker save cutile-ci:${{ github.sha }} | gzip > cutile-ci-image.tar.gz
79-
80-
- name: Upload CI image artifact
81-
uses: actions/upload-artifact@v5
82-
with:
83-
name: ci-image
84-
path: cutile-ci-image.tar.gz
85-
retention-days: 1
97+
outputs: type=registry,compression=zstd
8698
lint:
8799
name: Lint
88100
runs-on: ubuntu-latest
@@ -114,6 +126,11 @@ jobs:
114126
needs: [check-changes, build-ci-image]
115127
if: needs.check-changes.outputs.source-changed == 'true'
116128
timeout-minutes: 30
129+
container:
130+
image: ${{ fromJSON(needs.build-ci-image.outputs.image-tag)[0] }}
131+
credentials:
132+
username: ${{ github.actor }}
133+
password: ${{ secrets.GITHUB_TOKEN }}
117134
strategy:
118135
fail-fast: false
119136
matrix:
@@ -122,24 +139,12 @@ jobs:
122139
- name: Checkout repository
123140
uses: actions/checkout@v6
124141

125-
- name: Download CI image
126-
uses: actions/download-artifact@v5
127-
with:
128-
name: ci-image
129-
130-
- name: Load CI image
131-
run: docker load < cutile-ci-image.tar.gz
132-
133142
- name: Build wheel
134143
timeout-minutes: 15
135144
run: |
136-
docker run --rm -v ${{ github.workspace }}:/workspace -w /workspace \
137-
cutile-ci:${{ github.sha }} \
138-
bash -c "
139-
python${{ matrix.python-version }} -m venv .venv
140-
.venv/bin/pip install --upgrade pip build wheel setuptools
141-
.venv/bin/python -m build --wheel --outdir dist/
142-
"
145+
python${{ matrix.python-version }} -m venv .venv
146+
.venv/bin/pip install --upgrade pip build wheel setuptools
147+
.venv/bin/python -m build --wheel --outdir dist/
143148
144149
- name: Upload wheel artifact
145150
uses: actions/upload-artifact@v5
@@ -154,34 +159,29 @@ jobs:
154159
needs: [check-changes, build-ci-image, build-wheel]
155160
if: always() && (needs.check-changes.outputs.source-changed == 'true' || needs.check-changes.outputs.docs-changed == 'true')
156161
timeout-minutes: 15
162+
container:
163+
image: ${{ fromJSON(needs.build-ci-image.outputs.image-tag)[0] }}
164+
credentials:
165+
username: ${{ github.actor }}
166+
password: ${{ secrets.GITHUB_TOKEN }}
157167
steps:
158168
- name: Checkout repository
159169
uses: actions/checkout@v6
160170

161-
- name: Download CI image
162-
uses: actions/download-artifact@v5
163-
with:
164-
name: ci-image
165-
166-
- name: Load CI image
167-
run: docker load < cutile-ci-image.tar.gz
168-
169171
- name: Download wheel artifact
170172
uses: actions/download-artifact@v5
171173
with:
172174
name: wheel-linux-x86_64-py3.10
173175
path: dist/
174176

177+
- name: Install dependencies
178+
run: pip install dist/*.whl
179+
175180
- name: Build documentation
176181
timeout-minutes: 10
177182
run: |
178-
docker run --rm -v ${{ github.workspace }}:/workspace -w /workspace \
179-
cutile-ci:${{ github.sha }} \
180-
bash -c "
181-
pip install dist/*.whl
182-
cd docs
183-
timeout 8m make html
184-
"
183+
cd docs
184+
timeout 8m make html
185185
186186
- name: Upload documentation artifact
187187
uses: actions/upload-artifact@v5

0 commit comments

Comments
 (0)