Link Checker #17
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: Link Checker | |
| on: | |
| pull_request: | |
| branches: [main] | |
| schedule: | |
| - cron: '0 0 1,15 * *' | |
| workflow_dispatch: | |
| jobs: | |
| # ------------------------------------------------- | |
| # PR MODE | |
| # ------------------------------------------------- | |
| pr-check: | |
| if: github.event_name == 'pull_request' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Checkout history branch | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 | |
| with: | |
| ref: results_ci_checks | |
| path: health_history | |
| continue-on-error: true | |
| - name: Set up Python | |
| uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6 | |
| with: | |
| python-version: '3.12' | |
| - name: Install dependencies | |
| run: | | |
| pip install requests | |
| pip install requests curl_cffi | |
| - name: Get changed JSON files | |
| id: changed | |
| uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47 | |
| with: | |
| files: | | |
| collections/**/*.json | |
| indicators/**/*.json | |
| - name: Run link checker on changed files | |
| run: | | |
| if [ "${{ steps.changed.outputs.any_changed }}" = "true" ]; then | |
| echo "Changed files:" | |
| echo "${{ steps.changed.outputs.all_changed_files }}" | |
| python .github/link_checker.py \ | |
| --files ${{ steps.changed.outputs.all_changed_files }} | |
| else | |
| echo "No relevant JSON files changed." | |
| fi | |
| - name: Upload HTML report | |
| if: always() | |
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 | |
| with: | |
| name: link-check-report | |
| path: .github/link_check_report.html | |
| if-no-files-found: ignore | |
| # ------------------------------------------------- | |
| # FULL AUDIT MODE | |
| # ------------------------------------------------- | |
| full-audit: | |
| if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 | |
| - name: Checkout history branch | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 | |
| with: | |
| ref: results_ci_checks | |
| path: health_history | |
| continue-on-error: true | |
| - name: Create history branch if missing | |
| run: | | |
| if [ ! -d health_history/.git ]; then | |
| mkdir -p health_history | |
| cd health_history | |
| git init | |
| git checkout -b results_ci_checks | |
| git remote add origin \ | |
| "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" | |
| fi | |
| - name: Set up Python | |
| uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6 | |
| with: | |
| python-version: '3.12' | |
| - name: Install dependencies | |
| run: | | |
| pip install requests | |
| pip install requests curl_cffi | |
| - name: Run full link audit | |
| env: | |
| FULL_AUDIT: "1" | |
| GITHUB_RUN_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
| run: | | |
| python .github/link_checker.py | |
| - name: Upload HTML report | |
| if: always() | |
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 | |
| with: | |
| name: full-link-audit-report | |
| path: .github/link_check_report.html | |
| if-no-files-found: ignore | |
| - name: Ensure correct branch | |
| run: | | |
| cd health_history | |
| git checkout results_ci_checks || git checkout -b results_ci_checks | |
| - name: Commit new health report | |
| if: always() | |
| run: | | |
| cd health_history | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add health_report_*.json | |
| if git diff --staged --quiet; then | |
| echo "No new report to commit." | |
| else | |
| git commit -m "Health report: $(date -u +%Y-%m-%d)" | |
| git push -u origin results_ci_checks | |
| fi |