Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into dockerless
Browse files Browse the repository at this point in the history
  • Loading branch information
mre committed May 29, 2022
2 parents 543ef69 + 099d823 commit ee75c11
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 47 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
on:
on:
- repository_dispatch
- workflow_dispatch
- push
Expand All @@ -14,14 +14,14 @@ jobs:
# we must check out the repository
- name: Checkout
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
# `lycheeverse/lychee-action@...` gets classified as an e-mail address,
# causing this test to fail.
# TODO: Reactive once this issue is fixed upstream:
# https://github.com/robinst/linkify/issues/29
#- name: test defaults
# uses: ./
# with:
# fail: true
- name: test defaults
uses: ./
with:
fail: true
- name: test explicit lychee version
uses: ./
with:
lycheeVersion: 0.9.0
- name: test globs
uses: ./
with:
Expand Down
80 changes: 49 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@

Quickly check links in Markdown, HTML, and text files using [lychee].

When used in conjunction with [Create Issue From File](https://github.com/peter-evans/create-issue-from-file), issues will be created when the action finds link problems.
When used in conjunction with [Create Issue From
File](https://github.com/peter-evans/create-issue-from-file), issues will be
created when the action finds link problems.

## Usage

Here is a full example of a GitHub workflow file:

It will check all repository links once per day and create an issue in case of errors.
Save this under `.github/workflows/links.yml`:
It will check all repository links once per day and create an issue in case of
errors. Save this under `.github/workflows/links.yml`:

```yaml
name: Links
Expand All @@ -31,7 +33,7 @@ jobs:

- name: Link Checker
id: lychee
uses: lycheeverse/lychee-action@v1.4.1
uses: lycheeverse/lychee-action@v1.5.0
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

Expand Down Expand Up @@ -66,7 +68,7 @@ jobs:
- uses: actions/checkout@v3

- name: Link Checker
uses: lycheeverse/lychee-action@v1.4.1
uses: lycheeverse/lychee-action@v1.5.0
with:
fail: true
env:
Expand All @@ -77,40 +79,46 @@ jobs:

This action uses [lychee] for link checking.
lychee arguments can be passed to the action via the `args` parameter.
On top of that, some other inputs are supported: `format`, `output`, and `fail`.
See [lychee's documentation][lychee-args] for all possible arguments.

On top of that, the action also supports some additional arguments.

| Argument | Description |
| ------------- | -------------------------------------------------------------------------------- |
| format | Summary output format (markdown, json,...) |
| output | Summary output file path |
| fail | Fail entire pipeline on error (i.e. when lychee exit code is not 0) |
| jobSummary | Write Github job summary at the end of the job (written on Markdown output only) |
| lycheeVersion | Overwrite the lychee version to be used |

See [action.yml](./action.yml) for a full list of supported arguments.

### Example of argument passing

```yml
- name: Link Checker
uses: lycheeverse/lychee-action@v1.4.1
uses: lycheeverse/lychee-action@v1.5.0
with:
# Check all markdown and html files in repo (default)
args: --verbose --no-progress './**/*.md' './**/*.html'
# Use json as output format (instead of markdown)
format: json
# Use different output filename
# Use different output file path
output: /tmp/foo.txt
# Fail action on broken links
fail: true
```

See [lychee's documentation][lychee-args] for all possible arguments.

## Excluding links from getting checked

Add a `.lycheeignore` file to the root of your repository to exclude links from
getting checked. It supports regular expressions. One expression per line.

## Optional environment variables

Issues with links will be written to a file containing the error report.
The default path is `lychee/out.md`. The path and filename may be overridden with the following variable:

- `LYCHEE_OUT` - The path to the output file for the Markdown error report

## Fancy badge

Pro tip: You can add a little badge to your repo to show the status of your links.
Just replace `org` with your organisation name and `repo` with the repository name and put it into your `README.md`:
Pro tip: You can add a little badge to your repo to show the status of your
links. Just replace `org` with your organisation name and `repo` with the
repository name and put it into your `README.md`:

```
[![Check Links](https://github.com/org/repo/actions/workflows/links.yml/badge.svg)](https://github.com/org/repo/actions/workflows/links.yml)
Expand All @@ -122,19 +130,21 @@ It will look like this:

## Troubleshooting and common problems

See [lychee's Troubleshooting Guide](https://github.com/lycheeverse/lychee/blob/master/docs/TROUBLESHOOTING.md)
for solutions to common link-checking problems.
See [lychee's Troubleshooting Guide][troubleshooting] for solutions to common
link-checking problems.

## Performance

A full CI run to scan 576 links takes approximately 1 minute for the [analysis-tools-dev/static-analysis](https://github.com/analysis-tools-dev/static-analysis) repository.
A full CI run to scan 576 links takes approximately 1 minute for the
[analysis-tools-dev/static-analysis](https://github.com/analysis-tools-dev/static-analysis)
repository.

## Security and Updates

It is recommended to pin lychee-action to a fixed version [for security reasons](https://francoisbest.com/posts/2020/the-security-of-github-actions).
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.
It is recommended to pin lychee-action to a fixed version [for security
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.

Create a file named `.github/dependabot.yml` with the following contents:

Expand All @@ -148,12 +158,13 @@ updates:
```

When you add or update the `dependabot.yml` file, this triggers an immediate check for version updates.
Please see [the documentation](https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file) for all configuration options.
Please see [the documentation][dependabot] for all configuration options.

### Security tip

For additional security when relying on automation to update actions you can pin the action to a SHA-256 rather than the semver version so as to avoid tag spoofing
Dependabot will still be able to automatically update this.
For additional security when relying on automation to update actions you can pin
the action to a SHA-256 rather than the semver version so as to avoid tag
spoofing Dependabot will still be able to automatically update this.

For example:

Expand All @@ -165,17 +176,24 @@ For example:

## Credits

This action is based on [peter-evans/link-checker](https://github.com/peter-evans/link-checker) and uses lychee (written in Rust) instead of liche (written in Go) for link checking. For a comparison of both tools, check out this [comparison table](https://github.com/lycheeverse/lychee#features).
This action is based on
[peter-evans/link-checker](https://github.com/peter-evans/link-checker) and uses
lychee (written in Rust) instead of liche (written in Go) for link checking. For
a comparison of both tools, check out this [comparison
table](https://github.com/lycheeverse/lychee#features).

## License

lychee is licensed under either of

- Apache License, Version 2.0, (LICENSE-APACHE or
https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
- MIT license (LICENSE-MIT or https://choosealicense.com/licenses/mit/)

at your option.

[lychee]: https://github.com/lycheeverse/lychee
[lychee-args]: https://github.com/lycheeverse/lychee#commandline-parameters
[troubleshooting]: https://github.com/lycheeverse/lychee/blob/master/docs/TROUBLESHOOTING.md
[security]: https://francoisbest.com/posts/2020/the-security-of-github-actions
[dependabot]: https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
26 changes: 21 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,44 @@ inputs:
default: "--verbose --no-progress './**/*.md' './**/*.html'"
required: false
format:
description: "output format (e.g. json)"
description: "summary output format (e.g. json)"
default: "markdown"
required: false
output:
description: "output file"
description: "summary output file path"
default: "lychee/out.md"
required: false
fail:
description: "fail entire pipeline on error (exit code not 0)"
description: "fail entire pipeline on error (i.e. when lychee exit code is not 0)"
default: false
required: false
jobSummary:
description: "write Github job summary at the end of the job (written on Markdown output only)"
default: true
required: false
lycheeVersion:
description: "use custom version of lychee link checker"
default: 0.9.0
required: false
runs:
using: "composite"
steps:
- name: install lychee
run: |
curl -LO 'https://github.com/lycheeverse/lychee/releases/download/v0.9.0/lychee-v0.9.0-x86_64-unknown-linux-gnu.tar.gz'
tar -xvzf lychee-v0.9.0-x86_64-unknown-linux-gnu.tar.gz
curl -LO 'https://github.com/lycheeverse/lychee/releases/download/v${{ inputs.LYCHEEVERSION }}/lychee-v${{ inputs.LYCHEEVERSION }}-x86_64-unknown-linux-gnu.tar.gz'
tar -xvzf lychee-v${{ inputs.LYCHEEVERSION }}-x86_64-unknown-linux-gnu.tar.gz
chmod 755 lychee
mv lychee /usr/local/bin/lychee
shell: bash
- run: ${{ github.action_path }}/entrypoint.sh
env:
#https://github.com/actions/runner/issues/665
INPUT_GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
INPUT_ARGS: ${{ inputs.ARGS }}
INPUT_FORMAT: ${{ inputs.FORMAT }}
INPUT_OUTPUT: ${{ inputs.OUTPUT }}
INPUT_FAIL: ${{ inputs.FAIL }}
INPUT_JOBSUMMARY: ${{ inputs.JOBSUMMARY }}
shell: bash

branding:
Expand Down
8 changes: 6 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/bin/bash -l
set -uxo pipefail

env

LYCHEE_TMP="/tmp/lychee/out.md"
GITHUB_WORKFLOW_URL="https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}?check_suite_focus=true"

Expand Down Expand Up @@ -37,6 +35,12 @@ fi
cat "${LYCHEE_TMP}"
echo

if [ "${INPUT_FORMAT}" == "markdown" ]; then
if [ "${INPUT_JOBSUMMARY}" = true ]; then
cat "${LYCHEE_TMP}" > "${GITHUB_STEP_SUMMARY}"
fi
fi

# Pass lychee exit code to next step
echo ::set-output name=exit_code::$exit_code

Expand Down

0 comments on commit ee75c11

Please sign in to comment.