1- name : Docker Build and Publish Package
1+ name : Docker Build and Publish
22
33on :
44 push :
88 - ' docs/**'
99 workflow_dispatch :
1010 inputs :
11- package :
12- description : ' Name of the package to publish (e.g. my-docker-package )'
11+ version :
12+ description : ' Version to build and publish (e.g. v0.2.0 )'
1313 required : true
1414 type : string
1515
1616jobs :
17- prepare-publish :
17+ prepare-release :
1818 runs-on : ubuntu-latest
1919 outputs :
20- package : ${{ steps.get-package.outputs.package }}
20+ version : ${{ steps.get-version.outputs.version }}
21+ is_prerelease : ${{ steps.check-prerelease.outputs.is_prerelease }}
2122 steps :
2223 - name : Checkout repository
2324 uses : actions/checkout@v4
24-
25- - name : Get package name
26- id : get-package
25+
26+ - name : Get version
27+ id : get-version
2728 run : |
2829 if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
29- echo "package =${{ inputs.package }}" >> $GITHUB_OUTPUT
30+ echo "version =${{ inputs.version }}" >> $GITHUB_OUTPUT
3031 else
31- # For non-dispatch events, read the package name from a file called PACKAGE.
32- echo "package=$(cat PACKAGE)" >> $GITHUB_OUTPUT
32+ echo "version=$(cat VERSION)" >> $GITHUB_OUTPUT
3333 fi
3434
35+ - name : Check if prerelease
36+ id : check-prerelease
37+ run : |
38+ echo "is_prerelease=${{ contains(steps.get-version.outputs.version, '-pre') }}" >> $GITHUB_OUTPUT
39+
3540 build-images :
36- needs : prepare-publish
41+ needs : prepare-release
3742 runs-on : ubuntu-latest
3843 permissions :
3944 packages : write
45+ env :
46+ DOCKER_BUILDKIT : 1
47+ BUILDKIT_STEP_LOG_MAX_SIZE : 10485760
48+ # The version from the prepare-release job will override the VERSION variable
49+ VERSION : ${{ needs.prepare-release.outputs.version }}
4050 steps :
4151 - name : Checkout repository
4252 uses : actions/checkout@v4
7181 username : ${{ github.actor }}
7282 password : ${{ secrets.GITHUB_TOKEN }}
7383
74- - name : Build and push image
75- env :
76- DOCKER_BUILDKIT : 1
77- BUILDKIT_STEP_LOG_MAX_SIZE : 10485760
78- PACKAGE : ${{ needs.prepare-publish.outputs.package }}
84+ - name : Build and push images
7985 run : |
80- # This command assumes you have a docker-bake configuration that
81- # uses the image tag information. Here we override the tag to use the package name.
82- docker buildx bake --push --set "*.tags=ghcr.io/${{ github.repository_owner }}/${PACKAGE}:latest"
86+ # Override the VERSION variable in your bake file with the provided version.
87+ docker buildx bake --push --set VERSION=$VERSION
0 commit comments