Check Links #32
This file contains hidden or 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
| name: Check Links | |
| on: | |
| # Run M/W/F mornings | |
| schedule: | |
| - cron: '0 10 * * 1,3,5' | |
| workflow_dispatch: | |
| jobs: | |
| check-links: | |
| name: Check links | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| site: | |
| - name: Fern Docs | |
| url: "buildwithfern.com/learn" | |
| steps: | |
| - name: Install link checker | |
| run: pip install linkchecker | |
| - name: Create config | |
| run: echo -e "[csv]\nseparator=,\n[filtering]\nignore=\n\texample.com\n\tus.i.posthog.com\n\tdocs.stack-auth.com\n\tgithub.com/owner/repo\n\t/_vercel/(speed-)?insights/\n\tc.vialoops.com/CL0\n[output]\nignoreerrors=\n ^http ^403 Forbidden" > lcconfig | |
| - name: Check ${{ matrix.site.name }} Links | |
| run: | | |
| set +e | |
| cat lcconfig | |
| linkchecker https://${{ matrix.site.url }} --check-extern --no-status --no-warnings --threads 25 --timeout 120 --config lcconfig -F csv/utf-8/link_report.csv | |
| if [ $? -ne 0 ]; then | |
| echo "Bad links found. Please see report." | |
| else | |
| echo "Check completed. No issues found." | |
| exit 0 | |
| fi | |
| echo "Scan done, generating summary" | |
| started=false | |
| shouldfail=false | |
| while read p; do | |
| # skip comments (top and bottom) | |
| if [[ $p == \#* ]]; then | |
| continue | |
| fi | |
| # make sure first line after comments is skipped | |
| if [[ "$started" = false ]]; then | |
| started=true | |
| continue | |
| fi | |
| IFS=',' read -r -a array <<< "$p" | |
| ret=$(curl -I -s "${array[0]}" -o /dev/null -w "%{http_code}\n") | |
| if [[ $ret == 200 ]]; then | |
| echo "Site now seems to be working, we should continue here" | |
| continue | |
| else | |
| echo "There is still an issue with ${array[0]}" | |
| fi | |
| shouldfail=true | |
| if [[ ${array[10]} == '' ]]; then | |
| echo "::error::URL: ${array[0]} on page: ${array[1]} is returning a ${array[3]}" | |
| else | |
| echo "::error::URL: ${array[0]} linked from '${array[10]}' on page: ${array[1]} is returning a ${array[3]}" | |
| fi | |
| done < link_report.csv | |
| if [[ "$shouldfail" = false ]]; then | |
| exit 0 | |
| fi | |
| exit 1 | |
| - name: Upload report | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: Report - ${{ matrix.site.name }} | |
| path: link_report.csv |