2021-10-20 11:18:23 +11:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
|
|
|
|
# https://stackoverflow.com/questions/59895/get-the-source-directory-of-a-bash-script-from-within-the-script-itself
|
|
|
|
|
|
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
|
|
|
|
|
# shellcheck source=shared.sh
|
|
|
|
|
|
source "${script_dir}/shared.sh"
|
|
|
|
|
|
|
2021-10-21 23:38:24 +11:00
|
|
|
|
if [[ "${input_errors}" == 'true' ]] ; then
|
2021-10-20 11:18:23 +11:00
|
|
|
|
exit 8
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
##==----------------------------------------------------------------------------
|
|
|
|
|
|
## Get tags from GitHub repo
|
|
|
|
|
|
|
2023-10-18 23:44:09 +11:00
|
|
|
|
# Skip if testing, or if use_api is true, otherwise pull tags
|
2021-10-20 11:18:23 +11:00
|
|
|
|
if [[ -z "${BATS_VERSION:-}" ]] ; then
|
2023-10-18 23:44:09 +11:00
|
|
|
|
if [[ "${use_api:-}" != 'true' ]] ; then
|
|
|
|
|
|
git fetch --quiet --force origin 'refs/tags/*:refs/tags/*'
|
|
|
|
|
|
fi
|
2021-10-20 11:18:23 +11:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
##==----------------------------------------------------------------------------
|
|
|
|
|
|
## Version parsing
|
|
|
|
|
|
|
|
|
|
|
|
# detect current version - removing "v" from start of tag if it exists
|
2023-10-18 23:44:09 +11:00
|
|
|
|
if [[ "${use_api:-}" == 'true' ]] ; then
|
|
|
|
|
|
current_version="$(
|
|
|
|
|
|
curl -fsSL \
|
|
|
|
|
|
-H "Accept: application/vnd.github+json" \
|
|
|
|
|
|
-H "Authorization: Bearer ${github_token}" \
|
|
|
|
|
|
-H "X-GitHub-Api-Version: 2022-11-28" \
|
|
|
|
|
|
"${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/git/matching-refs/tags/" \
|
|
|
|
|
|
| jq -r '.[].ref' | sed 's|refs/tags/||g' \
|
2024-08-30 11:05:23 +02:00
|
|
|
|
| { grep_p "${pcre_allow_vprefix}" || true; } \
|
|
|
|
|
|
| sed 's/^v//g' \
|
2024-08-31 13:49:15 +10:00
|
|
|
|
| while read -r tag; do remove_prefix "$tag"; done \
|
2024-08-30 11:05:23 +02:00
|
|
|
|
| sort -V | tail -n 1
|
2023-10-18 23:44:09 +11:00
|
|
|
|
)"
|
|
|
|
|
|
else
|
|
|
|
|
|
current_version="$(
|
|
|
|
|
|
git tag -l \
|
2024-08-30 11:05:23 +02:00
|
|
|
|
| { grep_p "${pcre_allow_vprefix}" || true; } \
|
|
|
|
|
|
| sed 's/^v//g' \
|
2024-08-31 13:49:15 +10:00
|
|
|
|
| while read -r tag; do remove_prefix "$tag"; done \
|
2024-08-30 11:05:23 +02:00
|
|
|
|
| sort -V | tail -n 1
|
2023-10-18 23:44:09 +11:00
|
|
|
|
)"
|
|
|
|
|
|
fi
|
2021-10-20 11:18:23 +11:00
|
|
|
|
|
|
|
|
|
|
# handle no version detected - start versioning!
|
|
|
|
|
|
if [[ -z "${current_version:-}" ]] ; then
|
|
|
|
|
|
echo "⚠️ No previous release version identified in git tags"
|
|
|
|
|
|
# brand new repo! (probably)
|
|
|
|
|
|
case "${scheme}" in
|
2024-03-20 15:41:06 +11:00
|
|
|
|
semver | conventional_commits)
|
2021-10-20 11:18:23 +11:00
|
|
|
|
current_version="0.0.0"
|
|
|
|
|
|
;;
|
|
|
|
|
|
calver)
|
|
|
|
|
|
current_version="$(date '+%Y.%-m.0')"
|
|
|
|
|
|
;;
|
|
|
|
|
|
esac
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
echo "ℹ️ The current normal version is ${current_version}"
|
|
|
|
|
|
|
2022-10-19 09:23:10 +11:00
|
|
|
|
echo "CURRENT_VERSION=${current_version}" >> "${GITHUB_OUTPUT}"
|
|
|
|
|
|
echo "CURRENT_V_VERSION=v${current_version}" >> "${GITHUB_OUTPUT}"
|