|
| 1 | +name: Broken links check |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + schedule: |
| 8 | + # Run every Monday at 9:00 AM UTC |
| 9 | + - cron: '0 9 * * 1' |
| 10 | + workflow_dispatch: |
| 11 | + # Allow manual triggering |
| 12 | + |
| 13 | +jobs: |
| 14 | + check-links: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + permissions: |
| 17 | + issues: write |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout repository |
| 21 | + uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + sparse-checkout: | |
| 24 | + metadata |
| 25 | + sparse-checkout-cone-mode: false |
| 26 | + |
| 27 | + - name: Set up Python |
| 28 | + uses: actions/setup-python@v5 |
| 29 | + with: |
| 30 | + python-version: '3.x' |
| 31 | + |
| 32 | + - name: Install bdip-tools |
| 33 | + run: pip install --extra-index-url https://maven.sing-group.org/repository/python-snapshots/simple/ bdip-tools |
| 34 | + |
| 35 | + - name: Check for broken links |
| 36 | + # Use || true to ensure the workflow continues even if bdip-tools exits with an error code |
| 37 | + run: bdip check-broken-links metadata/metadata.json --output report.md || true |
| 38 | + env: |
| 39 | + # Default terminal width on GitHub Actions breaks the table formatting |
| 40 | + COLUMNS: 240 |
| 41 | + |
| 42 | + - name: Check report file content |
| 43 | + id: check_report |
| 44 | + run: | |
| 45 | + # Check if the report file exists and has more than 5 lines (header + data) |
| 46 | + if [[ -f report.md && $(wc -l < report.md) -gt 5 ]]; then |
| 47 | + echo "Broken links found in report.md." |
| 48 | + echo "has_broken_links=true" >> $GITHUB_OUTPUT |
| 49 | + else |
| 50 | + echo "No broken links found or report is empty/missing." |
| 51 | + echo "has_broken_links=false" >> $GITHUB_OUTPUT |
| 52 | + fi |
| 53 | +
|
| 54 | + - name: Upload report |
| 55 | + if: steps.check_report.outputs.has_broken_links == 'true' |
| 56 | + run: | |
| 57 | + DATE=$(date +"%d/%m/%Y") |
| 58 | + LABELS="broken-links,maintenance" |
| 59 | + TITLE="Broken links detected - $DATE" |
| 60 | +
|
| 61 | + ISSUE_BODY=$(cat <<EOF |
| 62 | + The broken links check has detected potential broken links in \`metadata.json\`. |
| 63 | +
|
| 64 | + Please review the following report and fix the links as soon as possible: |
| 65 | +
|
| 66 | + $(cat report.md) |
| 67 | + EOF |
| 68 | + ) |
| 69 | +
|
| 70 | + # Check if an issue already exists |
| 71 | + EXISTING_ISSUE=$(gh issue list --label "$LABELS" --state open --json number --jq '.[0].number') |
| 72 | +
|
| 73 | + # Create the issue if no existing issue is found |
| 74 | + if [ -z "$EXISTING_ISSUE" ]; then |
| 75 | + gh issue create \ |
| 76 | + --title "$TITLE" \ |
| 77 | + --body "$ISSUE_BODY" \ |
| 78 | + --label "$LABELS" |
| 79 | + else |
| 80 | + # Update existing opened issue |
| 81 | + gh issue edit "$EXISTING_ISSUE" \ |
| 82 | + --title "$TITLE" \ |
| 83 | + --body "$ISSUE_BODY" |
| 84 | + fi |
| 85 | + env: |
| 86 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 87 | + GH_REPO: ${{ github.repository }} |
0 commit comments