Skip to content

Commit 3f5ce5c

Browse files
committed
ci: split into build, test & deploy steps
1 parent de36b28 commit 3f5ce5c

File tree

1 file changed

+57
-30
lines changed

1 file changed

+57
-30
lines changed

.github/workflows/build.yml

Lines changed: 57 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,53 +8,80 @@ on:
88
- "*"
99
workflow_dispatch:
1010

11+
concurrency:
12+
group: ${{ github.workflow }}
13+
cancel-in-progress: true
14+
1115
env:
1216
DOCKER_IMAGE: ghcr.io/octoprint/custopizer
17+
TEST_TAG: testbuild
1318

1419
jobs:
1520
build:
16-
name: "Build"
21+
name: "🏗 Build"
1722

1823
runs-on: ubuntu-latest
1924

20-
permissions:
21-
contents: read
22-
packages: write
23-
attestations: write
24-
id-token: write
25-
2625
steps:
2726
- name: "⬇ Checkout"
2827
uses: actions/checkout@v4
2928

30-
- name: Docker meta
31-
id: meta
32-
uses: docker/metadata-action@v5
33-
with:
34-
images: ${{ env.DOCKER_IMAGE }}
35-
tags: |
36-
type=ref,event=branch
37-
type=ref,event=pr
38-
type=semver,pattern={{version}}
39-
type=semver,pattern={{major}}.{{minor}}
40-
4129
- name: "🐳 Set up Docker Buildx"
4230
uses: docker/setup-buildx-action@v3
4331

44-
- name: "🐳 Login to GHCR"
45-
uses: docker/login-action@v3
46-
if: github.event_name != 'pull_request'
47-
with:
48-
registry: ghcr.io
49-
username: ${{ github.repository_owner }}
50-
password: ${{ secrets.GITHUB_TOKEN }}
51-
52-
- name: "🏗 Build"
32+
- name: "🏗 Build & push with test tag"
5333
id: docker_build
5434
uses: docker/build-push-action@v6
5535
with:
5636
context: ./src
5737
platforms: linux/amd64,linux/arm64
58-
push: ${{ github.event_name != 'pull_request' }}
59-
tags: ${{ steps.meta.outputs.tags }}
60-
labels: ${{ steps.meta.outputs.labels }}
38+
tags: "${{ env.DOCKER_IMAGE }}:${{ env.TEST_TAG }}"
39+
40+
test:
41+
name: "🧪 Test"
42+
needs: build
43+
runs-on: "ubuntu-latest"
44+
45+
steps:
46+
- name: Dummy test
47+
run: |
48+
echo "A test will run here"
49+
50+
deploy:
51+
name: "📦 Deploy"
52+
needs: test
53+
runs-on: "ubuntu-latest"
54+
55+
if: github.event_name != 'pull_request'
56+
57+
permissions:
58+
contents: read
59+
packages: write
60+
attestations: write
61+
id-token: write
62+
63+
steps:
64+
- name: "🐳 Login to GHCR"
65+
uses: docker/login-action@v3
66+
with:
67+
registry: ghcr.io
68+
username: ${{ github.repository_owner }}
69+
password: ${{ secrets.GITHUB_TOKEN }}
70+
71+
- name: 🔍️ Determine metadata
72+
id: meta
73+
uses: docker/metadata-action@v5
74+
with:
75+
images: ${{ env.DOCKER_IMAGE }}
76+
tags: |
77+
type=ref,event=branch
78+
type=ref,event=pr
79+
type=semver,pattern={{version}}
80+
type=semver,pattern={{major}}.{{minor}}
81+
82+
- name: 🔖 Push correct tags
83+
run: |
84+
TAGS=$(echo "${{ steps.meta.outputs.json }}" | jq -r 'to_entries | map("-e " + .key + "=" + (.value | tostring)) | join(" ")'))
85+
86+
echo "Would run: docker buildx imagetools create $TAGS $DOCKER_IMAGE:$TEST_TAG"
87+

0 commit comments

Comments
 (0)