Skip to content

Commit

Permalink
Automatically pass Github token
Browse files Browse the repository at this point in the history
  • Loading branch information
mre committed May 23, 2023
1 parent 21b2b78 commit 84946df
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ jobs:
uses: ./
with:
debug: true
- name: test custom GitHub token
uses: ./
with:
token: ${{ secrets.CUSTOM_TOKEN }}
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ jobs:
- name: Link Checker
id: lychee
uses: lycheeverse/[email protected]
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

- name: Create Issue From File
if: env.lychee_exit_code != 0
Expand All @@ -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`.

Expand Down Expand Up @@ -75,8 +71,6 @@ jobs:
uses: lycheeverse/[email protected]
with:
fail: true
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
```

## Passing arguments
Expand All @@ -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
Expand All @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 84946df

Please sign in to comment.