Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Link Check on PRs #3085

Merged
merged 6 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/link_checkPR.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#Checks links in a PR to ensure they are valid. If link is valid but failing, it can be added to the .lycheeignore file
#Code source: https://github.com/lycheeverse/lychee-action/issues/238

name: link check on PR

on:
pull_request:
branches: [main]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why limit it to a specific branch?

Suggested change
branches: [main]


jobs:
check-links:
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}

- name: Check out main branch
run: git checkout main
Comment on lines +21 to +22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- name: Check out main branch
run: git checkout main
- name: Check out ${{github.event.pull_request.base.ref}} branch
run: git checkout ${{github.event.pull_request.base.ref}}


- name: Dump all links from main
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- name: Dump all links from main
- name: Dump all links from ${{github.event.pull_request.base.ref}}

id: dump_links_from_main
uses: lycheeverse/lychee-action@v1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anything wrong with using v2 version?

Suggested change
uses: lycheeverse/lychee-action@v1
uses: lycheeverse/lychee-action@v2

with:
args: |
--dump
--include-fragments
.
output: ./links-main.txt

- name: Stash untracked files
run: git stash push --include-untracked

- name: Check out feature branch
run: git checkout ${{ github.head_ref }}

- name: Apply stashed changes
# Apply stashed changes, ignore errors if stash is empty
run: git stash pop || true

- name: Append links-main.txt to .lycheeignore
run: cat links-main.txt >> .lycheeignore

- name: Check links
uses: lycheeverse/lychee-action@v1
with:
args: |
--no-progress
--include-fragments
.
# Fail action on broken links
fail: true

- name: Suggestions
if: failure()
run: |
echo -e "\nPlease review the links reported in the Check links step above."
echo -e "If a link is valid but fails due to a CAPTCHA challenge, IP blocking, login requirements, etc.,
consider adding such links to .lycheeignore file to bypass future checks.\n"
exit 1
2 changes: 2 additions & 0 deletions .lycheeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Used for links to be ignored during the link check.
# Add link to file along with comment as to why it should be ignored
Loading