From f39342594f3aaa24c837b8f99a5d193b8c703acc Mon Sep 17 00:00:00 2001 From: "Ware, Joseph (DLSLtd,RAL,LSCI)" Date: Tue, 7 Jan 2025 08:51:42 +0000 Subject: [PATCH] Defer SemVer parsing to docker metadata action --- .github/workflows/publish-image.yml | 48 ++++++----------------------- 1 file changed, 10 insertions(+), 38 deletions(-) diff --git a/.github/workflows/publish-image.yml b/.github/workflows/publish-image.yml index 9fc9b3b5e..bbca7fa9d 100644 --- a/.github/workflows/publish-image.yml +++ b/.github/workflows/publish-image.yml @@ -3,7 +3,7 @@ # separate terms of service, privacy policy, and support # documentation. -name: Create and publish image +name: Create and publish image and chart on: push: @@ -15,7 +15,7 @@ env: IMAGE_NAME: ${{ github.repository }} jobs: - build-and-push-image: + build-and-push: runs-on: ubuntu-latest permissions: contents: read @@ -27,22 +27,6 @@ jobs: with: fetch-depth: 0 - # Validate that the Image is published with a tag that is a valid SemVer, required by Helm chart - - name: Validate SemVer2 version compliance - if: startsWith(github.ref, 'refs/tags/') - env: - SEMVER_REGEX: ^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$ - - run: | - ref="${{ github.ref_name }}" - my_regex="${{env.SEMVER_REGEX}}" - if [[ "$ref" =~ $my_regex ]]; then - echo "SemVer compliant version: $ref" - else - echo "Invalid SemVer version: $ref" - exit 1 - fi - - name: Log in to the Container registry uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 with: @@ -55,6 +39,8 @@ jobs: uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=semver,pattern={{version}} - name: Build and push Docker image uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc @@ -65,32 +51,18 @@ jobs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - build-and-publish-chart: - runs-on: ubuntu-latest - needs: build-and-push-image - steps: - - name: checkout repo - uses: actions/checkout@v3 - - - name: install helm + - name: Install Helm uses: Azure/setup-helm@v3 with: token: ${{ secrets.GITHUB_TOKEN }} id: install - - name: login to gcr using helm + - name: Log in to the Chart registry run: | - echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ${{ env.GCR_IMAGE }} --username ${{ github.repository_owner }} --password-stdin - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@57396166ad8aefe6098280995947635806a0e6ea - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - tags: | - type=ref,event=tag + echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} --username ${{ github.repository_owner }} --password-stdin - - name: package chart and push it + - name: Package and Push chart run: | helm dependencies update helm/tiled - helm package helm/tiled --version ${GITHUB_REF##*/?(v)} --app-version ${GITHUB_REF##*/} -d /tmp/ - helm push /tmp/tiled-${GITHUB_REF##*/?(v)}.tgz oci://ghcr.io/bluesky/charts + helm package helm/tiled --version ${{ steps.meta.outputs.version }} --app-version ${{ steps.meta.outputs.version }} -d /tmp/ + helm push /tmp/tiled-${{ steps.meta.outputs.version }}.tgz oci://ghcr.io/bluesky/charts