@@ -2,6 +2,15 @@ name: Build and Push
22
33on :
44 workflow_call :
5+ inputs :
6+ version :
7+ description : " Version tag for the image (e.g. v1.2.3)"
8+ required : false
9+ type : string
10+ outputs :
11+ digest :
12+ description : " The published image manifest digest (sha256:...)"
13+ value : ${{ jobs.merge.outputs.digest }}
514
615env :
716 REGISTRY_IMAGE : ghcr.io/${{ github.repository }}
3342 - name : Get Build timestamp and branch name
3443 run : |
3544 echo "BUILD_TIMESTAMP=$(date +'%s')" >> $GITHUB_ENV
36- echo "VERSION=$( echo ${{ github.head_ref || github.ref_name }} | tr '/' '-' )" >> $GITHUB_ENV
45+ if [[ -n "${{ inputs.version }}" ]]; then
46+ echo "VERSION=${{ inputs.version }}" >> $GITHUB_ENV
47+ else
48+ echo "VERSION=$( echo ${{ github.head_ref || github.ref_name }} | tr '/' '-' )" >> $GITHUB_ENV
49+ fi
3750
3851 - name : Docker tags & labels
3952 id : meta
4659 # - type=sha,format=long,prefix= -> commit sha
4760 tags : |
4861 type=raw,${{ env.VERSION }}
62+ type=raw,latest,enable=${{ github.ref == 'refs/heads/main' }}
4963 type=ref,event=tag
5064 type=sha,format=long,prefix=
5165
94108 runs-on : ubuntu-latest
95109 needs :
96110 - build
111+ outputs :
112+ digest : ${{ steps.inspect.outputs.digest }}
97113 steps :
98114 - name : Download digests
99115 uses : actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
@@ -107,7 +123,11 @@ jobs:
107123
108124 - name : Get branch name
109125 run : |
110- echo "VERSION=$( echo ${{ github.head_ref || github.ref_name }} | tr '/' '-' )" >> $GITHUB_ENV
126+ if [[ -n "${{ inputs.version }}" ]]; then
127+ echo "VERSION=${{ inputs.version }}" >> $GITHUB_ENV
128+ else
129+ echo "VERSION=$( echo ${{ github.head_ref || github.ref_name }} | tr '/' '-' )" >> $GITHUB_ENV
130+ fi
111131
112132 - name : Docker tags & labels
113133 id : meta
@@ -120,6 +140,7 @@ jobs:
120140 # - type=sha,format=long,prefix= -> commit sha
121141 tags : |
122142 type=raw,${{ env.VERSION }}
143+ type=raw,latest,enable=${{ github.ref == 'refs/heads/main' }}
123144 type=ref,event=tag
124145 type=sha,format=long,prefix=
125146
@@ -138,6 +159,9 @@ jobs:
138159 $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
139160
140161 - name : Inspect image
162+ id : inspect
141163 if : env.REGISTRY_PUSH == 'true'
142164 run : |
143165 docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
166+ DIGEST=$(docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} | grep -m1 '^Digest:' | awk '{print $2}')
167+ echo "digest=$DIGEST" >> $GITHUB_OUTPUT
0 commit comments