Skip to content

Instantly share code, notes, and snippets.

@nhtzr
Last active October 21, 2020 18:19
Show Gist options
  • Save nhtzr/5d20fdb2ce81ceae075831738279c894 to your computer and use it in GitHub Desktop.
Save nhtzr/5d20fdb2ce81ceae075831738279c894 to your computer and use it in GitHub Desktop.
latest github tags
# for latest 0.x releases
$ for i in 2 3 4 5; do github-gql ~/tags.gql v0.$i. kubesvc-plugin | jq -r 'try(.repository.refs.edges[].node.name)'; done
#> v0.2.3
#> v0.3.13
#> v0.4.8
#> v0.5.0-rc.14
#!/usr/bin/env bash
[ -n "${GITHUB_API_TOKEN_PATH:-}" ] || GITHUB_API_TOKEN_PATH="$HOME/.config/token/github"
[ -n "${GITHUB_API_URL:-}" ] || GITHUB_API_URL='https://api.github.com/graphql'
main() {
local input
local auth_header
input="${1?}"
if ! test -s "$input"; then
echo "$0: $input not found" >/dev/stderr
return 1
fi
versionPrefix="${2:?Version prefix missing e.g. v0.5.}"
repo="${3:?Repo missing. e.g. kubesvc-plugin}"
owner="${4:-armory-io}"
auth_header="$(auth_header)"
: "${auth_header:? Missing auth header}"
jq -nRs '.query=input | .variables={$versionPrefix,$repo}' "$input" --arg versionPrefix "$versionPrefix" --arg repo "$repo" |
curl -sSf "$GITHUB_API_URL" -d '@-' -H "$auth_header" |
jq .data
}
auth_header() {
if [[ -n "${GITHUB_API_TOKEN:-}" ]]; then
echo "Authorization: bearer $GITHUB_API_TOKEN"
return
fi
if [[ -s "$GITHUB_API_TOKEN_PATH" ]]; then
echo "Authorization: bearer $(cat "$GITHUB_API_TOKEN_PATH")"
return
fi
return 1
}
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
set -ueo pipefail
main "$@"
fi
query($repo: String!, $versionPrefix: String!)
{
repository(owner: "armory-io", name: $repo) {
refs(first: 1, query: $versionPrefix, refPrefix: "refs/tags/", orderBy: {field: ALPHABETICAL, direction: DESC}) {
edges {
node {
name
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment