Skip to content

Commit

Permalink
Automatically pass Github token (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
mre authored Jun 16, 2023
1 parent 0c01f23 commit 7cdbd64
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ jobs:
uses: ./
with:
debug: true
- name: test custom GitHub token
uses: ./
with:
token: ${{ secrets.CUSTOM_TOKEN }}
22 changes: 13 additions & 9 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 @@ -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
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 Expand Up @@ -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.

Expand Down
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 7cdbd64

Please sign in to comment.