-
Notifications
You must be signed in to change notification settings - Fork 1
Add broken link checker #958
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
Changes from all commits
956a0ea
fd2501e
9a27547
f4047db
b7fb50e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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" | ||
|
|
||
| - 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" | ||
| 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what are these links pray tell?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 <a href="/cdn-cgi/l/email-protection#79111c151516391a1815100d0957160b1e">
<span class="__cf_email__" data-cfemail="670f020b0b082704060b0e131749081500">[email protected]</span>
</a>And those result in 404s if it just tries to follow them directly.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. very cool!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I literally had no idea... 🤔 |
||
| ignorewarnings=http-redirected | ||
|
|
||
| [AnchorCheck] | ||
There was a problem hiding this comment.
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
ghfor all this.There was a problem hiding this comment.
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!