feat(action): allow configuring the github token and set it when it exists (#34)

* fix: set Bearer token in curl request when GITHUB_TOKEN is set

Signed-off-by: Ludovic Ortega <ludovic.ortega@adminafk.fr>

* fix: use a dedicated input variable to pass github token

Signed-off-by: Ludovic Ortega <ludovic.ortega@adminafk.fr>

* fix: use github_token inputs

Signed-off-by: Ludovic Ortega <ludovic.ortega@adminafk.fr>

* Update README.md

* Update README.md

---------

Signed-off-by: Ludovic Ortega <ludovic.ortega@adminafk.fr>
Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
This commit is contained in:
Ludovic Ortega
2024-09-17 22:44:33 +02:00
committed by GitHub
parent 9f34d775d3
commit 143d9d4b8e
3 changed files with 27 additions and 8 deletions

View File

@@ -19,14 +19,21 @@ if [[ "${VERSION}" != 'latest' ]]; then
RELEASE_URL="https://api.github.com/repos/orhun/git-cliff/releases/tags/${VERSION}"
fi
# Although releases endpoint is available without authentication, the current github.token is still passed
# in order to increase the limit of 60 requests per hour per IP address to a higher value that's also counted
# per GitHub account.
# Caching is disabled in order not to receive stale responses from Varnish cache fronting GitHub API.
RELEASE_INFO="$(curl --silent --show-error --fail \
--header "authorization: Bearer ${GITHUB_TOKEN}" \
--header 'Cache-Control: no-cache, must-revalidate' \
"${RELEASE_URL}")"
if [[ -z "${GITHUB_API_TOKEN}" ]]; then
RELEASE_INFO="$(curl --silent --show-error --fail \
--header 'Cache-Control: no-cache, must-revalidate' \
"${RELEASE_URL}")"
else
# Although releases endpoint is available without authentication, the current github.token is still passed
# in order to increase the limit of 60 requests per hour per IP address to a higher value that's also counted
# per GitHub account.
RELEASE_INFO="$(curl --silent --show-error --fail \
--header "authorization: Bearer ${GITHUB_API_TOKEN}" \
--header 'Cache-Control: no-cache, must-revalidate' \
"${RELEASE_URL}")"
fi
TAG_NAME="$(echo "${RELEASE_INFO}" | jq --raw-output ".tag_name")"
TARGET="git-cliff-${TAG_NAME:1}-${ARCH}-${OS}.tar.gz"
LOCATION="$(echo "${RELEASE_INFO}" \