From a8dd5d2d726afab38686cf23e3e9b487851d310b Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Mon, 25 Oct 2021 16:59:53 -0500 Subject: [PATCH] add version tag action --- .github/workflows/versioning.yml | 43 ++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/versioning.yml diff --git a/.github/workflows/versioning.yml b/.github/workflows/versioning.yml new file mode 100644 index 0000000..d435705 --- /dev/null +++ b/.github/workflows/versioning.yml @@ -0,0 +1,43 @@ +name: Keep the versions up-to-date +# Source: https://github.com/tchupp/actions-update-semver-tags + +on: + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' + release: + types: + - published + - edited + +jobs: + update-semver-tags: + runs-on: ubuntu-latest + steps: + + - name: Checkout + uses: actions/checkout@v2 + + - name: Update Previous Tags + shell: bash + run: | + release_sha="${GITHUB_SHA}" + git_ref="${GITHUB_REF}" + git_ref_type=$(echo "${git_ref}" | cut -d '/' -f 2) + if [[ "${git_ref_type}" != "tags" ]]; then + echo "Action should only run for 'tags' refs, was: '${git_ref}'" + exit 0 + fi + git_ref=$(echo "${git_ref}" | cut -d '/' -f 3-) + match="v[0-9]+.[0-9]+.[0-9]+" + if ! [[ "${git_ref}" =~ $match ]]; then + echo "Action should only run for tags that match the regex '$match', was: '${git_ref}'" + exit 0 + fi + prefix=$(echo "${git_ref}" | sed -E 's/([^0-9]*)([0-9]*)\.([0-9]*)\.([0-9]*)/\1/') + major=$(echo "${git_ref}" | sed -E 's/([^0-9]*)([0-9]*)\.([0-9]*)\.([0-9]*)/\2/') + minor=$(echo "${git_ref}" | sed -E 's/([^0-9]*)([0-9]*)\.([0-9]*)\.([0-9]*)/\3/') + patch=$(echo "${git_ref}" | sed -E 's/([^0-9]*)([0-9]*)\.([0-9]*)\.([0-9]*)/\4/') + git tag -f "${prefix}${major}" "${release_sha}" + git tag -f "${prefix}${major}.${minor}" "${release_sha}" + git push --tags -f