Skip to content

Commit 8e4df20

Browse files
Merge pull request #38 from tomtom-international/change-builds
Build images on every commit
2 parents 00a0493 + cdf403b commit 8e4df20

File tree

2 files changed

+78
-67
lines changed

2 files changed

+78
-67
lines changed

.github/workflows/build.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches:
6+
- '**' # Build on all branches
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
IMAGE_NAME: ${{ github.repository }}
11+
12+
permissions:
13+
contents: read
14+
packages: write
15+
16+
jobs:
17+
pre-check:
18+
runs-on: ubuntu-22.04
19+
outputs:
20+
skip-workflow: ${{ steps.check.outputs.skip-workflow }}
21+
steps:
22+
- name: Check if workflow should be skipped
23+
id: check
24+
run: |
25+
if [[ "${{ github.event.head_commit.author.name }}" == "github-actions[bot]" ]] && [[ "${{ github.event.head_commit.message }}" == Release\ version* ]]; then
26+
echo "skip-workflow=true" >> $GITHUB_OUTPUT
27+
echo "Skipping this workflow..."
28+
else
29+
echo "skip-workflow=false" >> $GITHUB_OUTPUT
30+
echo "Proceeding with this workflow..."
31+
fi
32+
33+
build-and-push-image:
34+
runs-on: ubuntu-22.04
35+
needs: [pre-check]
36+
if: ${{ needs.pre-check.outputs.skip-workflow == 'false' }}
37+
steps:
38+
- name: Checkout repository
39+
uses: actions/checkout@v4
40+
with:
41+
fetch-depth: 0
42+
43+
- name: Set up Docker Buildx
44+
uses: docker/setup-buildx-action@v3
45+
46+
- name: Log in to Container Registry
47+
uses: docker/login-action@v3
48+
with:
49+
registry: ${{ env.REGISTRY }}
50+
username: ${{ github.actor }}
51+
password: ${{ secrets.GITHUB_TOKEN }}
52+
53+
- name: Extract metadata
54+
id: meta
55+
uses: docker/metadata-action@v5
56+
with:
57+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
58+
tags: |
59+
type=ref,event=branch
60+
type=ref,event=pr
61+
type=sha,prefix=sha-
62+
63+
- name: Build and push Docker image
64+
id: build-and-push
65+
uses: docker/build-push-action@v5
66+
with:
67+
context: .
68+
platforms: linux/amd64,linux/arm64
69+
push: true
70+
tags: ${{ steps.meta.outputs.tags }}
71+
labels: ${{ steps.meta.outputs.labels }}
72+
build-args: |
73+
VERSION=${{ github.sha }}
74+
cache-from: type=gha
75+
cache-to: type=gha,mode=max

.github/workflows/prepare-release.yml

Lines changed: 3 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
name: Prepare release
22

33
on:
4-
push:
5-
branches:
6-
- main
74
release:
85
types: [published]
96

@@ -16,70 +13,9 @@ permissions:
1613
packages: write
1714

1815
jobs:
19-
pre-check:
20-
runs-on: ubuntu-22.04
21-
outputs:
22-
skip-workflow: ${{ steps.check.outputs.skip-workflow }}
23-
steps:
24-
- name: Check if workflow should be skipped
25-
id: check
26-
run: |
27-
if [[ "${{ github.event.head_commit.author.name }}" == "github-actions[bot]" ]] && [[ "${{ github.event.head_commit.message }}" == Release\ version* ]]; then
28-
echo "skip-workflow=true" >> $GITHUB_OUTPUT
29-
echo "Skipping this workflow..."
30-
else
31-
echo "skip-workflow=false" >> $GITHUB_OUTPUT
32-
echo "Proceeding with this workflow..."
33-
fi
34-
35-
build-and-push-image:
36-
runs-on: ubuntu-22.04
37-
needs: [pre-check]
38-
if: ${{ !startsWith(github.ref, 'refs/tags/') && needs.pre-check.outputs.skip-workflow == 'false' }}
39-
steps:
40-
- name: Checkout repository
41-
uses: actions/checkout@v4
42-
with:
43-
fetch-depth: 0
44-
45-
- name: Set up Docker Buildx
46-
uses: docker/setup-buildx-action@v3
47-
48-
- name: Log in to Container Registry
49-
uses: docker/login-action@v3
50-
with:
51-
registry: ${{ env.REGISTRY }}
52-
username: ${{ github.actor }}
53-
password: ${{ secrets.GITHUB_TOKEN }}
54-
55-
- name: Extract metadata
56-
id: meta
57-
uses: docker/metadata-action@v5
58-
with:
59-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
60-
tags: |
61-
type=ref,event=branch
62-
type=ref,event=pr
63-
type=sha,prefix=sha-
64-
65-
- name: Build and push Docker image
66-
id: build-and-push
67-
uses: docker/build-push-action@v5
68-
with:
69-
context: .
70-
platforms: linux/amd64,linux/arm64
71-
push: true
72-
tags: ${{ steps.meta.outputs.tags }}
73-
labels: ${{ steps.meta.outputs.labels }}
74-
build-args: |
75-
VERSION=${{ github.sha }}
76-
cache-from: type=gha
77-
cache-to: type=gha,mode=max
78-
7916
tag-release-image:
8017
runs-on: ubuntu-22.04
81-
needs: [pre-check]
82-
if: ${{ startsWith(github.event.release.tag_name, 'v') && needs.pre-check.outputs.skip-workflow == 'false' }}
18+
if: ${{ startsWith(github.event.release.tag_name, 'v') }}
8319
steps:
8420
- name: Log in to Container Registry
8521
uses: docker/login-action@v3
@@ -88,7 +24,7 @@ jobs:
8824
username: ${{ github.actor }}
8925
password: ${{ secrets.GITHUB_TOKEN }}
9026

91-
- name: Get latest SHA image
27+
- name: Get latest SHA image from the main branch
9228
id: get-sha
9329
run: |
9430
# Get the latest commit SHA from the main branch
@@ -196,5 +132,5 @@ jobs:
196132
token: ${{ secrets.GITHUB_TOKEN }}
197133
exclude-tags: '^v[0-9]+\.[0-9]+\.[0-9]+$'
198134
use-regex: true
199-
keep-n-tagged: 20
135+
keep-n-tagged: 30
200136
log-level: info

0 commit comments

Comments
 (0)