update scripts: rework tag fetching with GitHub API

Use GitHub GraphQL API to sort fetched tags by date instead by version 
number.
This commit is contained in:
Portisch
2021-10-13 10:35:55 +02:00
parent 0cb023db74
commit b6da5ced51
3 changed files with 25 additions and 11 deletions

View File

@@ -84,17 +84,27 @@ resolve_tag_in_branch() {
resolve_tag_on_gh() {
local tag
tag=$(curl -s -L -H "Authorization: token ${GITHUB_API_TOKEN}" \
"${1/*github.com/https:\/\/api.github.com\/repos}/releases" | \
jq -r '[.[] | select(.target_commitish == "'$2'")][0].tag_name | select (.!=null)')
local QUERY=$(tr '\n' ' ' <<EOF
{
repository(owner: \\"${1}\\", name: \\"${2}\\") {
refs(refPrefix: \\"refs/tags/\\", first: 100, orderBy: {field: TAG_COMMIT_DATE, direction: DESC}) {
edges {
node {
name
}
}
}
}
}
EOF
)
if [ -z "$tag" ] ; then
tag=$(curl -s -L -H "Authorization: token ${GITHUB_API_TOKEN}" \
"${1/*github.com/https:\/\/api.github.com\/repos}/tags" | \
jq -r '[.[] | select(.name | contains("'$2'"))][0].name | select (.!=null)')
fi
tag=$(curl -s -L -H 'Content-Type: application/json' \
-H "Authorization: bearer ${GITHUB_API_TOKEN}" \
-X POST -d "{ \"query\": \"${QUERY}\" }" https://api.github.com/graphql | \
jq -r '[.data.repository.refs.edges[] | select(.node.name | contains("'${3}'"))][0].node.name | select (.!=null)')
echo "$tag"
echo "${tag}"
}
check_package_excluded() {