Skip to content

Commit c883875

Browse files
committed
only push image after tests pass
1 parent 0d23dc6 commit c883875

2 files changed

Lines changed: 90 additions & 52 deletions

File tree

.github/workflows/build_and_push.yaml

Lines changed: 0 additions & 52 deletions
This file was deleted.

.github/workflows/ci.yaml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ on:
1010
- main
1111
workflow_dispatch:
1212

13+
env:
14+
REGISTRY: ghcr.io
15+
1316
jobs:
1417
test:
1518
runs-on: ubuntu-latest
@@ -66,3 +69,90 @@ jobs:
6669

6770
- name: Run tests (including property tests)
6871
run: mix test --include test
72+
73+
docker-build:
74+
runs-on: ubuntu-latest
75+
permissions:
76+
contents: read
77+
78+
steps:
79+
- name: Checkout repository
80+
uses: actions/checkout@v4
81+
82+
- name: Set up Docker Buildx
83+
uses: docker/setup-buildx-action@v3
84+
85+
- name: Extract metadata
86+
id: meta
87+
uses: docker/metadata-action@v5
88+
with:
89+
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/cascade
90+
tags: |
91+
type=ref,event=branch
92+
type=ref,event=pr
93+
type=sha,prefix={{branch}}-
94+
type=raw,value=latest,enable={{is_default_branch}}
95+
96+
- name: Build Docker image (no push)
97+
uses: docker/build-push-action@v5
98+
with:
99+
context: .
100+
file: ./Dockerfile
101+
push: false
102+
tags: ${{ steps.meta.outputs.tags }}
103+
labels: ${{ steps.meta.outputs.labels }}
104+
cache-from: type=gha
105+
cache-to: type=gha,mode=max
106+
outputs: type=docker,dest=/tmp/cascade-image.tar
107+
108+
- name: Upload Docker image artifact
109+
uses: actions/upload-artifact@v4
110+
with:
111+
name: cascade-docker-image
112+
path: /tmp/cascade-image.tar
113+
retention-days: 1
114+
115+
docker-push:
116+
runs-on: ubuntu-latest
117+
needs: [test, docker-build]
118+
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop')
119+
permissions:
120+
contents: read
121+
packages: write
122+
123+
steps:
124+
- name: Checkout repository
125+
uses: actions/checkout@v4
126+
127+
- name: Download Docker image artifact
128+
uses: actions/download-artifact@v4
129+
with:
130+
name: cascade-docker-image
131+
path: /tmp
132+
133+
- name: Load Docker image
134+
run: docker load --input /tmp/cascade-image.tar
135+
136+
- name: Log in to Container Registry
137+
uses: docker/login-action@v3
138+
with:
139+
registry: ${{ env.REGISTRY }}
140+
username: ${{ github.actor }}
141+
password: ${{ secrets.GITHUB_TOKEN }}
142+
143+
- name: Extract metadata
144+
id: meta
145+
uses: docker/metadata-action@v5
146+
with:
147+
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/cascade
148+
tags: |
149+
type=ref,event=branch
150+
type=sha,prefix={{branch}}-
151+
type=raw,value=latest,enable={{is_default_branch}}
152+
153+
- name: Push Docker image to registry
154+
run: |
155+
for tag in $(echo "${{ steps.meta.outputs.tags }}" | tr ',' ' '); do
156+
docker tag $(docker images -q | head -n1) $tag
157+
docker push $tag
158+
done

0 commit comments

Comments
 (0)