diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3fd54d8..0106a24 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -55,3 +55,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 a1937d3..4c9ccf5 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 @@ -95,10 +89,13 @@ On top of that, the action also supports some additional arguments. | 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: diff --git a/action.yml b/action.yml index db12072..08dc61b 100644 --- a/action.yml +++ b/action.yml @@ -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..b837bce 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: