@@ -38,26 +38,40 @@ jobs:
38
38
39
39
build :
40
40
needs : [test-pfcon, test-cube]
41
- if : github.event_name == 'push' || github.event_name == 'release'
42
41
runs-on : ubuntu-22.04
43
42
steps :
44
43
- uses : actions/checkout@v4
44
+ - name : Install pixi
45
+ id : install-pixi
46
+ if : startsWith(github.ref, 'refs/tags/v')
47
+ uses : prefix-dev/setup-pixi@v0.8.1
45
48
with :
46
- fetch-depth : " 0"
49
+ pixi-version : v0.28.2
50
+ - name : Set version
51
+ id : set-version
52
+ if : steps.install-pixi.outcome == "success"
53
+ run :
54
+ ref_name='${{ github.ref_name }}'
55
+ version_number="${ref_name:1}"
56
+ pixi project version set "$version_number"
57
+ echo "LABEL org.opencontainers.image.version=\"$version_number\"" >> Dockerfile
58
+ echo "version=$version_number" >> "$GITHUB_OUTPUT"
47
59
- name : Get build tags
48
60
id : info
49
61
shell : python
50
62
run : |
51
63
import os
52
64
import itertools
53
65
54
- short_sha = os.getenv('GITHUB_SHA', 'unknown')[:7]
66
+ commit_sha = '${{ github.sha }}'
67
+ short_sha = commit_sha[:7]
55
68
git_refs = []
56
- if os.getenv('GITHUB_REF', '').startswith('refs/tags/v'):
57
- version_from_tag = os.getenv('GITHUB_REF')[11:]
58
- git_refs.append(version_from_tag.replace('+', '.'))
69
+ version_number = '${{ steps.set-version.outputs.version }}'
70
+ if version_number:
71
+ sanitized_version_number = version_number.replace('+', '.')
72
+ git_refs.append(sanitized_version_number)
59
73
registries = ['docker.io', 'ghcr.io']
60
- repo = os.environ['GITHUB_REPOSITORY'] .lower()
74
+ repo = '${{ github.repository }}' .lower()
61
75
tags = ['latest'] + git_refs
62
76
names = ','.join(''.join(c) for c in itertools.product(
63
77
(r + '/' for r in registries),
@@ -69,24 +83,26 @@ jobs:
69
83
- uses : docker/setup-qemu-action@v3
70
84
- uses : docker/setup-buildx-action@v3
71
85
- name : Login to DockerHub
86
+ id : login-dockerhub
87
+ if : github.event_name == 'push'
72
88
uses : docker/login-action@v3
73
89
with :
74
90
username : ${{ secrets.DOCKERHUB_USERNAME }}
75
91
password : ${{ secrets.DOCKERHUB_PASSWORD }}
76
92
- name : Login to GitHub Container Registry
93
+ id : login-ghcr
94
+ if : github.event_name == 'push'
77
95
uses : docker/login-action@v3
78
96
with :
79
97
registry : ghcr.io
80
98
username : ${{ github.repository_owner }}
81
99
password : ${{ secrets.GITHUB_TOKEN }}
82
100
83
101
- name : Build and push
84
- uses : docker/build-push-action@v5
102
+ uses : docker/build-push-action@v6
85
103
with :
86
- build-args : |
87
- ENVIRONMENT=production
88
- BUILD_VERSION=${{ github.ref_name }}
89
- push : true
104
+ build-args : ENVIRONMENT=prod
105
+ push : ${{ steps.login-dockerhub.outcome }} == 'success' && ${{ steps.login-ghcr.outcome }} == 'success'
90
106
context : .
91
107
file : ./Dockerfile
92
108
tags : " ${{ steps.info.outputs.tags }}"
0 commit comments