Broken links check #43
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 links check | |
| on: | |
| schedule: | |
| # Run every Monday at 9:00 AM UTC | |
| - cron: '0 9 * * 1' | |
| workflow_dispatch: | |
| # Allow manual triggering | |
| jobs: | |
| check-links: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| issues: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| with: | |
| sparse-checkout: | | |
| metadata | |
| sparse-checkout-cone-mode: false | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.x' | |
| - name: Install bdip-tools | |
| run: pip install --extra-index-url https://maven.sing-group.org/repository/python-snapshots/simple/ bdip-tools | |
| - name: Check for broken links | |
| run: bdip check-broken-links metadata/metadata.json --skip-cloudflare-403 --output report.md | |
| - name: Check report file content | |
| id: check_report | |
| run: | | |
| # The report file is created only if broken links are found | |
| if [[ -f report.md ]]; then | |
| echo "Broken links found in report.md." | |
| echo "has_broken_links=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "No broken links found." | |
| echo "has_broken_links=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Upload report | |
| if: steps.check_report.outputs.has_broken_links == 'true' | |
| run: | | |
| DATE=$(date +"%d/%m/%Y") | |
| LABELS="broken-links,maintenance" | |
| TITLE="Broken links detected - $DATE" | |
| ISSUE_BODY=$(cat <<EOF | |
| The broken links check has detected potential broken links in \`metadata.json\`. | |
| Please review the following report and fix the links as soon as possible: | |
| $(cat report.md) | |
| EOF | |
| ) | |
| # Check if an issue already exists | |
| EXISTING_ISSUE=$(gh issue list --label "$LABELS" --state open --json number --jq '.[0].number') | |
| # Create the issue if no existing issue is found | |
| if [ -z "$EXISTING_ISSUE" ]; then | |
| gh issue create \ | |
| --title "$TITLE" \ | |
| --body "$ISSUE_BODY" \ | |
| --label "$LABELS" | |
| else | |
| # Update existing opened issue | |
| gh issue edit "$EXISTING_ISSUE" \ | |
| --title "$TITLE" \ | |
| --body "$ISSUE_BODY" | |
| fi | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| GH_REPO: ${{ github.repository }} |