Skip to content
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
6 changes: 6 additions & 0 deletions .cspell/dev-dictionary.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Words pertaining to development of this site

aria
beautifulsoup
booleancheckbox
browserconfig
btn
calitp-
cdn
cgi
cli
Consolas
cta
Expand All @@ -29,8 +32,11 @@ gtfs
hbspt
homescreen
hubspot
ignorewarnings
img
jekyll
linkchecker
linkcheckerrc
linkify
liquidjs
Menlo
Expand Down
57 changes: 57 additions & 0 deletions .github/workflows/check-links-weekly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Weekly Broken Link Check

on:
schedule:
- cron: "0 2 * * MON"
timezone: "America/Los_Angeles"

jobs:
linkchecker:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
permissions:
issues: write

steps:
- name: Check out
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # 7.0.1
with:
persist-credentials: false # since the next step does not need it

- name: Install dependencies
run: pip install linkchecker beautifulsoup4

- name: Run linkchecker
id: linkchecker
run: linkchecker --config=linkcheckerrc --check-extern --file-output=html/utf-8/results.html https://www.camobilitymarketplace.org

- name: Strip all but body contents
id: extract-report-body
if: ${{ failure() }}
run: python3 -c 'from bs4 import BeautifulSoup; print(BeautifulSoup(open("results.html").read(), "html.parser").body.decode_contents())' > report_body.html

- name: Check for an open linkchecker issue
id: open-issue-check
if: ${{ failure() }}
run: echo "OPEN_ISSUE_ID=`gh issue list --label linkchecker --json number --jq '.[0].number'`" >> "$GITHUB_OUTPUT"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i dig that you're just using gh for all this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's a pretty powerful addition to the built-in GHA toolset!


- name: Add content to existing issue
if: ${{ failure() && steps.open-issue-check.outputs.OPEN_ISSUE_ID != '' }}
run: |
echo -e "## Updated broken link report\n\nFrom weekly run: https://github.com/cal-itp/mobility-marketplace/actions/runs/${{ github.run_id }}\n\n<details>\n" > comment.md
cat report_body.html >> comment.md
echo -e "\n</details>" >> comment.md
gh issue comment ${{ steps.open-issue-check.outputs.OPEN_ISSUE_ID }} \
--body-file comment.md

- name: Create new issue
if: ${{ failure() && steps.open-issue-check.outputs.OPEN_ISSUE_ID == '' }}
run: |
echo -e "## Broken link report\n\nDiscovered during weekly run: https://github.com/cal-itp/mobility-marketplace/actions/runs/${{ github.run_id }}\n\n<details>\n" > comment.md
cat report_body.html >> comment.md
echo -e "\n</details>" >> comment.md
gh issue create \
--title "Broken links found" \
--body-file comment.md \
--label "content,bug,linkchecker"
6 changes: 6 additions & 0 deletions linkcheckerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[filtering]
ignore=
/cdn-cgi/l/email-protection
Comment on lines +2 to +3

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what are these links pray tell?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Turns out that we have Cloudflare set up to mask email addresses, so the href that linkchecker sees for a mailto link looks like this:

<a href="/cdn-cgi/l/email-protection#79111c151516391a1815100d0957160b1e">
  <span class="__cf_email__" data-cfemail="670f020b0b082704060b0e131749081500">[email&#160;protected]</span>
</a>

And those result in 404s if it just tries to follow them directly.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

very cool!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I literally had no idea... 🤔

ignorewarnings=http-redirected

[AnchorCheck]