mirror of
https://github.com/Sea-Haven-Industries/engineering-handbook.git
synced 2026-09-30 06:53:15 +00:00
fix(scripts): select latest workflow tag by semver
Co-authored-by: Adam Moussa <amoussa1229@users.noreply.github.com>
This commit is contained in:
parent
e2bdb82938
commit
996579697e
1 changed files with 25 additions and 2 deletions
|
|
@ -23,8 +23,31 @@ if [[ ! "$REPO_NAME" =~ ^[a-z0-9]([a-z0-9-]*[a-z0-9])?$ ]]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
WORKFLOW_VERSION=$(gh api "repos/${ORG}/.github/tags?per_page=100" \
|
||||
--jq '[.[] | select(.name | test("^v[0-9]+\\.[0-9]+\\.[0-9]+$"))][0].name // empty')
|
||||
# GitHub returns tags by recency; compare semantic versions explicitly.
|
||||
WORKFLOW_TAGS=$(gh api --paginate "repos/${ORG}/.github/tags?per_page=100" \
|
||||
--jq '.[] | select(.name | test("^v[0-9]+\\.[0-9]+\\.[0-9]+$")) | .name')
|
||||
WORKFLOW_VERSION=""
|
||||
WORKFLOW_MAJOR=-1
|
||||
WORKFLOW_MINOR=-1
|
||||
WORKFLOW_PATCH=-1
|
||||
while IFS= read -r tag; do
|
||||
[[ -z "$tag" ]] && continue
|
||||
|
||||
if [[ "$tag" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
|
||||
major=$((10#${BASH_REMATCH[1]}))
|
||||
minor=$((10#${BASH_REMATCH[2]}))
|
||||
patch=$((10#${BASH_REMATCH[3]}))
|
||||
|
||||
if (( major > WORKFLOW_MAJOR || \
|
||||
(major == WORKFLOW_MAJOR && minor > WORKFLOW_MINOR) || \
|
||||
(major == WORKFLOW_MAJOR && minor == WORKFLOW_MINOR && patch > WORKFLOW_PATCH) )); then
|
||||
WORKFLOW_VERSION="$tag"
|
||||
WORKFLOW_MAJOR="$major"
|
||||
WORKFLOW_MINOR="$minor"
|
||||
WORKFLOW_PATCH="$patch"
|
||||
fi
|
||||
fi
|
||||
done <<< "$WORKFLOW_TAGS"
|
||||
if [[ -z "$WORKFLOW_VERSION" ]]; then
|
||||
echo "Error: no released Sea-Haven-Industries/.github vX.Y.Z tag found."
|
||||
exit 1
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue