I am using jq to get the tag_name index with the script:
curl \
https://api.github.com/repos/checkstyle/checkstyle/releases \
-H "Authorization: token $GITHUB_TOKEN" \
-o /var/tmp/cs-releases.json
TARGET_RELEASE_NUM=$1
TARGET_RELEASE_INDEX=$(cat /var/tmp/cs-releases.json | \
jq -r "[.[].tag_name] | to_entries | .[] | \
select(.value==\"checkstyle-${TARGET_RELEASE_NUM}\") | .key")
echo TARGET_RELEASE_INDEX="$TARGET_RELEASE_INDEX"
I get the expected result only when I use the $GITHUB_TOKEN as a hardcoded value (directly in the script) but when I use $GITHUB_TOKEN as a command line variable, I get this output:
jq: error (at <stdin>:4): Cannot index string with string "tag_name"
This error is getting when using:
rahul@rk7:~/Desktop/opensource/checkstyle$ GITHUB_TOKEN=ghp_xxxx && ./.ci/update-github-page.sh 10.1
and Working fine with:
curl \
https://api.github.com/repos/checkstyle/checkstyle/releases \
-H "Authorization: token ghp_xxxx" \
-o /var/tmp/cs-releases.json
TARGET_RELEASE_NUM=$1
TARGET_RELEASE_INDEX=$(cat /var/tmp/cs-releases.json | \
jq -r "[.[].tag_name] | to_entries | .[] | \
select(.value==\"checkstyle-${TARGET_RELEASE_NUM}\") | .key")
echo TARGET_RELEASE_INDEX="$TARGET_RELEASE_INDEX"