Broken Link Checker #135
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: Broken Link Checker | |
| # Workflow triggers | |
| on: | |
| schedule: | |
| # Run at 5:00 AM on Monday and Friday | |
| - cron: '0 5 * * 1,5' | |
| # Allow manual triggering | |
| workflow_dispatch: | |
| jobs: | |
| check-links: | |
| runs-on: ubuntu-latest | |
| name: Check for broken and insecure links | |
| timeout-minutes: 30 | |
| # Need permissions to create PRs, issues, and push cache changes | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| issues: write | |
| steps: | |
| # Step 1: Checkout repository | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Fetch all history for proper updating | |
| # Step 2: Set up Python environment | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| # Step 3: Install required Python packages | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install requests beautifulsoup4 PyGithub | |
| # Step 4: Configure Git | |
| - name: Configure Git | |
| run: | | |
| git config user.name "GitHub Actions Bot" | |
| git config user.email "[email protected]" | |
| # Step 5: Execute link checker script | |
| - name: Run link checker | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: python ./.github/scripts/link_checker.py | |
| # Step 6: Commit and push cache updates via a pull request | |
| - name: Commit cache changes | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| if git diff --quiet .github/scripts/link_check_cache.json; then | |
| echo "No changes to commit" | |
| exit 0 | |
| fi | |
| BRANCH="bot/update-link-check-cache-$(date +%Y%m%d%H%M%S)" | |
| git checkout -b "$BRANCH" | |
| git add .github/scripts/link_check_cache.json | |
| git commit -m "Update link check cache" | |
| git push origin "$BRANCH" | |
| gh pr create \ | |
| --title "Update link check cache" \ | |
| --body "Automated update of the link check cache by the Broken Link Checker workflow." \ | |
| --base master \ | |
| --head "$BRANCH" |