Skip to content

Check for broken links #170

Check for broken links

Check for broken links #170

Workflow file for this run

name: Check for broken links
on:
workflow_dispatch:
schedule:
# Run every weekend
- cron: '0 2 * * 6'
jobs:
url:
runs-on: ubuntu-latest
outputs:
url: ${{ steps.get-url.outputs.url }}
steps:
- name: Get URL
id: get-url
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -ex
url=$(gh api --jq .html_url repos/${{ github.repository }}/pages)
echo "url=$url" >> $GITHUB_OUTPUT
# internal and external links
linkchecker:
needs: url
runs-on: ubuntu-latest
env:
LINKCHECKER_FLAGS: ''
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
cache: 'pip'
cache-dependency-path: |
.github/workflows/linkchecker.yaml
- name: Install linkchecker
run: |
pip3 install 'LinkChecker >= 10.2'
- id: attempt1
continue-on-error: true
name: Run linkchecker
run: |
linkchecker --check-extern ${{ env.LINKCHECKER_FLAGS }} ${{ needs.url.outputs.url }}
- name: Sleep
if: steps.attempt1.outcome == 'failure'
run: sleep 30
- id: attempt2
if: steps.attempt1.outcome == 'failure'
continue-on-error: true
name: Run linkchecker
run: |
linkchecker --check-extern ${{ env.LINKCHECKER_FLAGS }} ${{ needs.url.outputs.url }}
- name: Sleep
if: steps.attempt2.outcome == 'failure'
run: sleep 30
- id: attempt3
if: steps.attempt2.outcome == 'failure'
continue-on-error: true
name: Run linkchecker
run: |
linkchecker --check-extern ${{ env.LINKCHECKER_FLAGS }} ${{ needs.url.outputs.url }}
- name: Fail
if: steps.attempt1.outcome == 'failure' && steps.attempt2.outcome == 'failure' && steps.attempt3.outcome == 'failure'
run: false
# internal links and anchors
linkcheck:
needs: url
runs-on: ubuntu-latest
steps:
- id: attempt1
continue-on-error: true
name: Run linkcheck
uses: filiph/linkcheck@3.0.0
with:
arguments: ${{ needs.url.outputs.url }}
- name: Sleep
if: steps.attempt1.outcome == 'failure'
run: sleep 30
- id: attempt2
if: steps.attempt1.outcome == 'failure'
continue-on-error: true
name: Run linkcheck
uses: filiph/linkcheck@3.0.0
with:
arguments: ${{ needs.url.outputs.url }}
- name: Sleep
if: steps.attempt2.outcome == 'failure'
run: sleep 30
- id: attempt3
if: steps.attempt2.outcome == 'failure'
continue-on-error: true
name: Run linkcheck
uses: filiph/linkcheck@3.0.0
with:
arguments: ${{ needs.url.outputs.url }}
- name: Fail
if: steps.attempt1.outcome == 'failure' && steps.attempt2.outcome == 'failure' && steps.attempt3.outcome == 'failure'
run: false
workflow-keepalive:
if: github.event_name == 'schedule'
runs-on: ubuntu-latest
permissions:
actions: write
steps:
- uses: liskin/gh-workflow-keepalive@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}