From 7cdbd6424d9567a3b47f5928d476b0ce10cb9da9 Mon Sep 17 00:00:00 2001 From: Matthias Endler Date: Fri, 16 Jun 2023 13:39:20 +0200 Subject: [PATCH] Automatically pass Github token (#196) --- .github/workflows/test.yml | 4 ++++ README.md | 22 +++++++++++++--------- action.yml | 6 +++++- entrypoint.sh | 5 +++++ 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b33086f..e17ea5d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -63,3 +63,7 @@ jobs: uses: ./ with: debug: true + - name: test custom GitHub token + uses: ./ + with: + token: ${{ secrets.CUSTOM_TOKEN }} diff --git a/README.md b/README.md index 027cb05..044f185 100644 --- a/README.md +++ b/README.md @@ -33,8 +33,6 @@ jobs: - name: Link Checker id: lychee uses: lycheeverse/lychee-action@v1.8.0 - env: - GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} - name: Create Issue From File if: env.lychee_exit_code != 0 @@ -45,8 +43,6 @@ jobs: labels: report, automated issue ``` -(You don't need to configure the `GITHUB_TOKEN` yourself; it is automatically set by Github.) - If you always want to use the latest features but avoid breaking changes, you can replace the version with `lycheeverse/lychee-action@v1`. @@ -75,8 +71,6 @@ jobs: uses: lycheeverse/lychee-action@v1.8.0 with: fail: true - env: - GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} ``` ## Passing arguments @@ -92,13 +86,16 @@ On top of that, the action also supports some additional arguments. | debug | `false` | Enable debug output in action (set -x). Helpful for troubleshooting. | | fail | `false` | Fail workflow run on error (i.e. when [lychee exit code][lychee-exit] is not 0). | | format | `markdown`, `json` | Summary output format. | -| jobSummary | `false` | Write Github job summary (on Markdown output only). | +| jobSummary | `false` | Write GitHub job summary (on Markdown output only). | | lycheeVersion | `0.13.0` | Overwrite the lychee version to be used. | | output | `lychee/results.md` | Summary output file path. | +| token | `""` | Custom GitHub token to use for API calls. | See [action.yml](./action.yml) for a full list of supported arguments and their default values. -### Example of argument passing +### Passing arguments + +Here is how to pass the arguments. ```yml - name: Link Checker @@ -110,10 +107,17 @@ See [action.yml](./action.yml) for a full list of supported arguments and their format: json # Use different output file path output: /tmp/foo.txt + # Use a custom GitHub token, which + token: ${{ secrets.CUSTOM_TOKEN }} # Fail action on broken links fail: true ``` +(If you need a token that requires permissions that aren't available in the +default `GITHUB_TOKEN`, you can create a [personal access +token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) +and pass it to the action via the `token` parameter.) + ## Utilising the cache feature In order to mitigate issues regarding rate limiting or to reduce stress on external resources, one can setup lychee's cache similar to this: @@ -192,7 +196,7 @@ repository. ## Security and Updates It is recommended to pin lychee-action to a fixed version [for security -reasons][security]. You can use dependabot to automatically keep your Github +reasons][security]. You can use dependabot to automatically keep your GitHub actions up-to-date. This is a great way to pin lychee-action, while still receiving updates in the future. It's a relatively easy thing to do. diff --git a/action.yml b/action.yml index cff413d..3c6f4e2 100644 --- a/action.yml +++ b/action.yml @@ -18,7 +18,7 @@ inputs: default: "markdown" required: false jobSummary: - description: "Write Github job summary at the end of the job (written on Markdown output only)" + description: "Write GitHub job summary at the end of the job (written on Markdown output only)" default: true required: false lycheeVersion: @@ -29,6 +29,10 @@ inputs: description: "Summary output file path" default: "lychee/out.md" required: false + token: + description: 'Your GitHub Access Token, defaults to: {{ github.token }}' + default: ${{ github.token }} + required: false outputs: exit_code: description: "The exit code returned from Lychee" diff --git a/entrypoint.sh b/entrypoint.sh index b6a9411..64601bf 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -10,6 +10,11 @@ fi LYCHEE_TMP="$(mktemp)" GITHUB_WORKFLOW_URL="https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}?check_suite_focus=true" +# If custom GitHub token is set, export it as environment variable +if [ -n "${INPUT_TOKEN:-}" ]; then + export GITHUB_TOKEN="${INPUT_TOKEN}" +fi + ARGS="${INPUT_ARGS}" FORMAT="" # Backwards compatibility: