-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #347 from NLeSC/update_link_checker_PR_workflow_sq…
…uash update PR link checker workflow
- Loading branch information
Showing
1 changed file
with
30 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,38 @@ | ||
name: Link Checker for Pull requests | ||
on: pull_request | ||
jobs: | ||
changedFiles: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
files: ${{ steps.changed-markdown-files.outputs.all_changed_files }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Get changed markdown files | ||
id: changed-markdown-files | ||
uses: tj-actions/changed-files@v45 | ||
with: | ||
# Avoid using single or double quotes for multiline patterns | ||
files: | | ||
**.md | ||
matrix: true | ||
|
||
linkChecker: | ||
runs-on: ubuntu-latest | ||
needs: changedFiles | ||
if: ${{ needs.changedFiles.outputs.files != '' && toJSON(fromJSON(needs.changedFiles.outputs.files)) != '[]' }} | ||
strategy: | ||
matrix: | ||
file: ${{ fromJSON(needs.changedFiles.outputs.files) }} | ||
fail-fast: false | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- id: changed_files | ||
uses: jitterbit/get-changed-files@v1 | ||
- name: Link Checker | ||
uses: lycheeverse/[email protected] | ||
id: lychee | ||
env: | ||
GITHUB_TOKEN: ${{secrets.TOKEN_GITHUB}} | ||
- uses: actions/checkout@v4 | ||
with: | ||
args: ${{ steps.changed_files.outputs.all }} | ||
- name: Count broken links | ||
fetch-depth: 2 | ||
- name: download Lychee | ||
run: | | ||
wget https://github.com/lycheeverse/lychee/releases/download/nightly/lychee-x86_64-unknown-linux-gnu.tar.gz | ||
tar xzf lychee-x86_64-unknown-linux-gnu.tar.gz | ||
- name: Check all this file's additions for broken links | ||
run: | | ||
broken_max=10 | ||
broken_count=$(printf "%d" $(grep "🚫 Errors" lychee/out.md | cut -d'|' -f3)) | ||
if [ "$broken_count" -gt "$broken_max" ]; then | ||
echo "Number of broken links (${broken_count}) exceeds maximum allowed number (${broken_max})." | ||
cat lychee/out.md | ||
exit 1 | ||
else | ||
echo "Number of broken links (${broken_count}) less than or equal to maximum allowed number (${broken_max})." | ||
exit 0 | ||
fi | ||
export base_sha=$(git rev-parse ${{ github.sha }}^) | ||
git diff -U0 ${base_sha} ${{ github.event.pull_request.head.sha }} -- ${{ matrix.file }} | grep -v "+++" | grep "^+" | cut -c 2- | ./lychee - |