From f58df38ae897b1478cb57d678af07ebe52ba55ef Mon Sep 17 00:00:00 2001 From: nicktrn <55853254+nicktrn@users.noreply.github.com> Date: Sun, 15 Sep 2024 19:29:14 +0100 Subject: [PATCH] image action updates --- .github/actions/get-image-tag/action.yml | 41 +++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/.github/actions/get-image-tag/action.yml b/.github/actions/get-image-tag/action.yml index 87bdba19e..a0078850f 100644 --- a/.github/actions/get-image-tag/action.yml +++ b/.github/actions/get-image-tag/action.yml @@ -6,6 +6,15 @@ outputs: tag: description: The image tag value: ${{ steps.get_tag.outputs.tag }} + is_semver: + description: Whether the tag is a semantic version + value: ${{ steps.check_semver.outputs.is_semver }} + +inputs: + tag: + description: The image tag. If this is set it will return the tag as is. + required: false + default: "" runs: using: "composite" @@ -14,7 +23,9 @@ runs: id: get_tag shell: bash run: | - if [[ "${{ github.ref_type }}" == "tag" ]]; then + if [[ -n "${{ inputs.tag }}" ]]; then + tag="${{ inputs.tag }}" + elif [[ "${{ github.ref_type }}" == "tag" ]]; then if [[ "${{ github.ref_name }}" == infra-*-* ]]; then env=$(echo ${{ github.ref_name }} | cut -d- -f2) sha=$(echo ${{ github.sha }} | head -c7) @@ -36,3 +47,31 @@ runs: exit 1 fi echo "tag=${tag}" >> "$GITHUB_OUTPUT" + + - name: 🔍 Check for validity + id: check_validity + shell: bash + env: + tag: ${{ steps.get_tag.outputs.tag }} + run: | + if [[ "${tag}" =~ ^[a-z0-9]+([._-][a-z0-9]+)*$ ]]; then + echo "Tag is valid: ${tag}" + else + echo "Tag is not valid: ${tag}" + exit 1 + fi + + - name: 🆚 Check for semver + id: check_semver + shell: bash + env: + tag: ${{ steps.get_tag.outputs.tag }} + run: | + if [[ "${tag}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z-]+)?$ ]]; then + echo "Tag is a semantic version: ${tag}" + is_semver=true + else + echo "Tag is not a semantic version: ${tag}" + is_semver=false + fi + echo "is_semver=${is_semver}" >> "$GITHUB_OUTPUT"