From 9f1a664697ba8b43fc47bd81163f2f64f1e35977 Mon Sep 17 00:00:00 2001 From: Ludovic Ortega Date: Sun, 15 Sep 2024 23:53:36 +0200 Subject: [PATCH 1/5] fix: set Bearer token in curl request when GITHUB_TOKEN is set Signed-off-by: Ludovic Ortega --- install.sh | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/install.sh b/install.sh index 7401f72..e68cef0 100755 --- a/install.sh +++ b/install.sh @@ -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_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_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}" \ From 247ff27612c1e39f5f69a55b2ef84a2a3d23748b Mon Sep 17 00:00:00 2001 From: Ludovic Ortega Date: Mon, 16 Sep 2024 18:49:46 +0200 Subject: [PATCH 2/5] fix: use a dedicated input variable to pass github token Signed-off-by: Ludovic Ortega --- README.md | 8 ++++++++ action.yml | 6 +++++- install.sh | 4 ++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bf3aa47..543afc7 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ This action generates a changelog based on your Git history using [git-cliff](ht - `version`: `git-cliff` version to use. (e.g. `"latest"`, `"v2.5.0"`) - `config`: Path of the configuration file. (Default: `"cliff.toml"`) - `args`: [Arguments](https://github.com/orhun/git-cliff#usage) to pass to git-cliff. (Default: `"-v"`) +- `github_token`: The GitHub API token used to get git-cliff release information via the GitHub API to avoid rate limits. (Default: `${{ github.token }}`) ### Output variables @@ -32,6 +33,13 @@ This action generates a changelog based on your Git history using [git-cliff](ht > > Otherwise, you might end up getting empty changelogs or `git ref` errors depending on arguments passed to `git-cliff`. +### Running the action outside of GitHub + +If you run the action in Gitea or GitHub Enterprise, the `github_token` input is invalid. You have two options: + +- Pass an empty value `github_token: ""` (limit of 60 requests per hour per IP address). +- Create a GitHub token and pass it through GitHub secrets to avoid rate limiting. + ### Examples #### Simple diff --git a/action.yml b/action.yml index 1e5310b..abb072e 100644 --- a/action.yml +++ b/action.yml @@ -13,6 +13,10 @@ inputs: description: "git-cliff arguments" required: false default: "-v" + github_token: + description: "GitHub API token" + required: false + default: "${{ github.token }}" outputs: changelog: description: "output file" @@ -33,7 +37,7 @@ runs: RUNNER_OS: ${{ runner.os }} RUNNER_ARCH: ${{ runner.arch }} VERSION: ${{ inputs.version }} - GITHUB_TOKEN: ${{ github.token }} + GITHUB_API_TOKEN: ${{ inputs.version }} - name: Run git-cliff id: run-git-cliff diff --git a/install.sh b/install.sh index e68cef0..70b1076 100755 --- a/install.sh +++ b/install.sh @@ -20,7 +20,7 @@ if [[ "${VERSION}" != 'latest' ]]; then fi # Caching is disabled in order not to receive stale responses from Varnish cache fronting GitHub API. -if [[ -z "${GITHUB_TOKEN}" ]]; then +if [[ -z "${GITHUB_API_TOKEN}" ]]; then RELEASE_INFO="$(curl --silent --show-error --fail \ --header 'Cache-Control: no-cache, must-revalidate' \ "${RELEASE_URL}")" @@ -29,7 +29,7 @@ else # 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_TOKEN}" \ + --header "authorization: Bearer ${GITHUB_API_TOKEN}" \ --header 'Cache-Control: no-cache, must-revalidate' \ "${RELEASE_URL}")" fi From e716decbd8a6a7b9fabf484ce394c30ec854367d Mon Sep 17 00:00:00 2001 From: Ludovic Ortega Date: Mon, 16 Sep 2024 19:20:21 +0200 Subject: [PATCH 3/5] fix: use github_token inputs Signed-off-by: Ludovic Ortega --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index abb072e..978d7b8 100644 --- a/action.yml +++ b/action.yml @@ -37,7 +37,7 @@ runs: RUNNER_OS: ${{ runner.os }} RUNNER_ARCH: ${{ runner.arch }} VERSION: ${{ inputs.version }} - GITHUB_API_TOKEN: ${{ inputs.version }} + GITHUB_API_TOKEN: ${{ inputs.github_token }} - name: Run git-cliff id: run-git-cliff From df67a59da112356f7813ddb55bf32a662a48a90e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Tue, 17 Sep 2024 23:37:56 +0300 Subject: [PATCH 4/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 543afc7..b6e0a91 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ This action generates a changelog based on your Git history using [git-cliff](ht - `version`: `git-cliff` version to use. (e.g. `"latest"`, `"v2.5.0"`) - `config`: Path of the configuration file. (Default: `"cliff.toml"`) - `args`: [Arguments](https://github.com/orhun/git-cliff#usage) to pass to git-cliff. (Default: `"-v"`) -- `github_token`: The GitHub API token used to get git-cliff release information via the GitHub API to avoid rate limits. (Default: `${{ github.token }}`) +- `github_token`: The GitHub API token used to get `git-cliff` release information via the GitHub API to avoid rate limits. (Default: `${{ github.token }}`) ### Output variables From 9b60cd0fbcec523f9403a0c6221fb9f8ab745984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Tue, 17 Sep 2024 23:38:02 +0300 Subject: [PATCH 5/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b6e0a91..48ef412 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ This action generates a changelog based on your Git history using [git-cliff](ht If you run the action in Gitea or GitHub Enterprise, the `github_token` input is invalid. You have two options: -- Pass an empty value `github_token: ""` (limit of 60 requests per hour per IP address). +- Pass an empty value (`github_token: ""`) (limit of 60 requests per hour per IP address). - Create a GitHub token and pass it through GitHub secrets to avoid rate limiting. ### Examples