diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 8c86123..dd39876 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -15,6 +15,23 @@ jobs: build: runs-on: ubuntu-latest steps: + + # 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: Checkout uses: actions/checkout@v4 @@ -59,3 +76,33 @@ jobs: labels: ${{ steps.meta.outputs.labels }} annotations: ${{ steps.meta.outputs.annotations }} push: true + + + build-and-publish-chart: + runs-on: ubuntu-latest + needs: build-and-push-image + steps: + - name: checkout repo + uses: actions/checkout@v3 + + - name: install helm + uses: Azure/setup-helm@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + id: install + + - name: login to gcr using helm + 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 + - name: package chart and push it + run: | + helm dependencies update helm/numtracker + helm package helm/numtracker --version ${GITHUB_REF##*/?(v)} --app-version ${GITHUB_REF##*/} -d /tmp/ + helm push /tmp/numtracker-${GITHUB_REF##*/?(v)}.tgz oci://ghcr.io/diamondlightsource/charts