Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH Manually work out make latest #13

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,38 @@ runs:
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_SHA: ${{ github.sha }}
run: |
# Work out if release should be marked as the latest
# Only do the for stable semver tags
# Note = not using "legacy" as GitHub seems to only consider if it's the latest tag in a particular major line
# whereas we only want to mark it the latest if it's the latest tag overall
MAKE_LATEST="false"
if [[ $TAG =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
# Gets latest 100 tags across all majors from via GitHub API
# https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#list-repository-tags
RESP_CODE=$(curl -w %{http_code} -s -o __response.json \
-X GET "https://api.github.com/repos/${GITHUB_REPOSITORY}/tags?per_page=100" \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ github.token }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
)
if [[ $RESP_CODE != "200" ]]; then
echo "Unable to read list of tags - HTTP response code was $RESP_CODE"
exit 1
fi
# Get the latest stable tag
LATEST_TAG=$(jq -r '.[].name' __response.json | grep -Po '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V -r | head -n 1)
echo "LATEST_TAG is $LATEST_TAG"
if [[ $LATEST_TAG =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
MAJOR=${BASH_REMATCH[1]}
MINOR=${BASH_REMATCH[2]}
PATCH=${BASH_REMATCH[3]}
NEXT_TAG="$MAJOR.$MINOR.$((PATCH+1))"
GuySartorelli marked this conversation as resolved.
Show resolved Hide resolved
if [[ $TAG == $NEXT_TAG ]]; then
MAKE_LATEST="true"
fi
fi
fi
echo "MAKE_LATEST is $MAKE_LATEST"
# Escape double quotes '"' => '\"'
RELEASE_DESCRIPTION=${RELEASE_DESCRIPTION//\"/\\\"}
# Create new release via GitHub API
Expand All @@ -169,7 +201,7 @@ runs:
"draft": false,
"prerelease": false,
"generate_release_notes": ${{ inputs.release_auto_notes }},
"make_latest": "legacy"
"make_latest": "$MAKE_LATEST"
}
EOF
)
Expand Down