Skip to content

Commit

Permalink
add a separate script to get the latest tag
Browse files Browse the repository at this point in the history
  • Loading branch information
s-radyuk committed Dec 29, 2021
1 parent a20e2dd commit 326e5a0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
11 changes: 3 additions & 8 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,16 @@ jobs:
- name: Get tag
id: get_tag
run: |
for ref in $(git for-each-ref --sort=-creatordate --format '%(refname)' refs/tags); do
tag="${ref#refs/tags/}"
if echo "${tag}" | grep -Eq '^v?([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$'; then
latest_tag="${tag}"
break
fi
done
./ci/get-latest-tag.sh
# echo "::set-output name=tag::$(./ci/get-latest-tag.sh)"

- name: Lint GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: v1.2.2
args: --skip-publish --snapshot
env:
GORELEASER_CURRENT_TAG: ${{ steps.get_tag.outputs.TAG }}
GORELEASER_CURRENT_TAG: ${{ steps.get_tag.outputs.tag }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Helm
Expand Down
28 changes: 28 additions & 0 deletions ci/get-latest-tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/env bash

set -e

function get_latest_tag() {
git fetch --tags
# This suppress an error occurred when the repository is a complete one.
git fetch --prune || true

latest_tag=''

# Get a latest tag in the shape of semver.
for ref in $(git for-each-ref --sort=-creatordate --format '%(refname)' refs/tags); do
tag="${ref#refs/tags/}"
if echo "${tag}" | grep -Eq '^v?([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$'; then
latest_tag="${tag}"
break
fi
done

if [ "${latest_tag}" = '' ]; then
latest_tag="${INPUT_INITIAL_VERSION}"
fi

echo "${latest_tag}"
}

get_latest_tag

0 comments on commit 326e5a0

Please sign in to comment.