Skip to content

Commit

Permalink
Defer SemVer parsing to docker metadata action
Browse files Browse the repository at this point in the history
  • Loading branch information
DiamondJoseph committed Jan 7, 2025
1 parent e557887 commit f393425
Showing 1 changed file with 10 additions and 38 deletions.
48 changes: 10 additions & 38 deletions .github/workflows/publish-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -15,7 +15,7 @@ env:
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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

0 comments on commit f393425

Please sign in to comment.