From ca1fcffa4bc069971024f9c2ab5223ce44779b16 Mon Sep 17 00:00:00 2001 From: remsky Date: Fri, 7 Feb 2025 15:31:05 -0700 Subject: [PATCH] Update build-push.yml --- .github/workflows/build-push.yml | 45 ++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build-push.yml b/.github/workflows/build-push.yml index 779effc..fe90d13 100644 --- a/.github/workflows/build-push.yml +++ b/.github/workflows/build-push.yml @@ -1,4 +1,4 @@ -name: Docker Build and Publish Package +name: Docker Build and Publish on: push: @@ -8,35 +8,45 @@ on: - 'docs/**' workflow_dispatch: inputs: - package: - description: 'Name of the package to publish (e.g. my-docker-package)' + version: + description: 'Version to build and publish (e.g. v0.2.0)' required: true type: string jobs: - prepare-publish: + prepare-release: runs-on: ubuntu-latest outputs: - package: ${{ steps.get-package.outputs.package }} + version: ${{ steps.get-version.outputs.version }} + is_prerelease: ${{ steps.check-prerelease.outputs.is_prerelease }} steps: - name: Checkout repository uses: actions/checkout@v4 - - - name: Get package name - id: get-package + + - name: Get version + id: get-version run: | if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then - echo "package=${{ inputs.package }}" >> $GITHUB_OUTPUT + echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT else - # For non-dispatch events, read the package name from a file called PACKAGE. - echo "package=$(cat PACKAGE)" >> $GITHUB_OUTPUT + echo "version=$(cat VERSION)" >> $GITHUB_OUTPUT fi + - name: Check if prerelease + id: check-prerelease + run: | + echo "is_prerelease=${{ contains(steps.get-version.outputs.version, '-pre') }}" >> $GITHUB_OUTPUT + build-images: - needs: prepare-publish + needs: prepare-release runs-on: ubuntu-latest permissions: packages: write + env: + DOCKER_BUILDKIT: 1 + BUILDKIT_STEP_LOG_MAX_SIZE: 10485760 + # The version from the prepare-release job will override the VERSION variable + VERSION: ${{ needs.prepare-release.outputs.version }} steps: - name: Checkout repository uses: actions/checkout@v4 @@ -71,12 +81,7 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push image - env: - DOCKER_BUILDKIT: 1 - BUILDKIT_STEP_LOG_MAX_SIZE: 10485760 - PACKAGE: ${{ needs.prepare-publish.outputs.package }} + - name: Build and push images run: | - # This command assumes you have a docker-bake configuration that - # uses the image tag information. Here we override the tag to use the package name. - docker buildx bake --push --set "*.tags=ghcr.io/${{ github.repository_owner }}/${PACKAGE}:latest" \ No newline at end of file + # Override the VERSION variable in your bake file with the provided version. + docker buildx bake --push --set VERSION=$VERSION \ No newline at end of file