-
Notifications
You must be signed in to change notification settings - Fork 1
74 lines (62 loc) · 2.6 KB
/
main.yml
File metadata and controls
74 lines (62 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
name: Docker Image CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
extract_version:
if: "startsWith(github.event.head_commit.message, 'chore: set version to v')"
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get version from commit message
id: get_version
run: |
# Get the commit message
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
# Extract version tag (assuming the version is in the format "vX.Y.Z")
VERSION=$(echo "$COMMIT_MESSAGE" | grep -oP 'v\K\d+\.\d+\.\d+$')
echo "Version: $VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
build:
if: "startsWith(github.event.head_commit.message, 'chore: set version to v')"
runs-on: ubuntu-latest
needs: extract_version # Ensure this job runs after the version extraction
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build for amd64 and cache it
uses: docker/build-push-action@v6
with:
platforms: linux/amd64
load: true
cache-from: type=registry,ref=bochaco/formicaio-gh:buildcache-v${{ needs.extract_version.outputs.version }}-amd64
cache-to: type=registry,ref=bochaco/formicaio-gh:buildcache-v${{ needs.extract_version.outputs.version }}-amd64
- name: Build for arm64 and cache it
uses: docker/build-push-action@v6
with:
platforms: linux/arm64
load: true
cache-from: type=registry,ref=bochaco/formicaio-gh:buildcache-v${{ needs.extract_version.outputs.version }}-arm64
cache-to: type=registry,ref=bochaco/formicaio-gh:buildcache-v${{ needs.extract_version.outputs.version }}-arm64
- name: Build multiplatform from cache and push
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
push: true
cache-from: |
type=registry,ref=bochaco/formicaio-gh:buildcache-v${{ needs.extract_version.outputs.version }}-arm64
type=registry,ref=bochaco/formicaio-gh:buildcache-v${{ needs.extract_version.outputs.version }}-amd64
tags: ${{ vars.DOCKERHUB_USERNAME }}/formicaio:latest
output: type=image