Last active
October 21, 2020 18:19
-
-
Save nhtzr/5d20fdb2ce81ceae075831738279c894 to your computer and use it in GitHub Desktop.
latest github tags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment