|
| 1 | +name: Check Broken Links |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 0 * * *' |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - canary |
| 9 | + - main |
| 10 | + # Enable manual triggering from GitHub Actions tab |
| 11 | + workflow_dispatch: |
| 12 | + inputs: |
| 13 | + fail-on-broken-links: |
| 14 | + description: 'Fail workflow if broken links are found' |
| 15 | + required: true |
| 16 | + type: choice |
| 17 | + default: 'false' |
| 18 | + options: |
| 19 | + - 'true' |
| 20 | + - 'false' |
| 21 | + |
| 22 | +jobs: |
| 23 | + url-check: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Checkout repository |
| 28 | + uses: actions/checkout@v4 |
| 29 | + |
| 30 | + - name: Set up Python |
| 31 | + uses: actions/setup-python@v4 |
| 32 | + with: |
| 33 | + python-version: '3.x' |
| 34 | + |
| 35 | + - name: Install dependencies |
| 36 | + run: | |
| 37 | + python -m pip install --upgrade pip |
| 38 | + pip install requests colorama |
| 39 | +
|
| 40 | + - name: Enable Color Output |
| 41 | + run: echo "FORCE_COLOR=1" >> $GITHUB_ENV |
| 42 | + |
| 43 | + - name: Check for broken links |
| 44 | + id: check_links |
| 45 | + continue-on-error: true |
| 46 | + run: | |
| 47 | + python scripts/python/url-checker/url-checker.py |
| 48 | + EXIT_CODE=$? |
| 49 | + echo "link_check_exit_code=$EXIT_CODE" >> $GITHUB_OUTPUT |
| 50 | +
|
| 51 | + # Always display the summary clearly |
| 52 | + echo "### URL Check Results" >> $GITHUB_STEP_SUMMARY |
| 53 | + if [ $EXIT_CODE -eq 0 ]; then |
| 54 | + echo "✅ All links are valid!" >> $GITHUB_STEP_SUMMARY |
| 55 | + else |
| 56 | + echo "⚠️ Some broken links were found. Check the logs for details." >> $GITHUB_STEP_SUMMARY |
| 57 | + echo "Download the log artifacts for the complete report." >> $GITHUB_STEP_SUMMARY |
| 58 | + fi |
| 59 | +
|
| 60 | + - name: Upload log file |
| 61 | + if: always() |
| 62 | + uses: actions/upload-artifact@v4 |
| 63 | + with: |
| 64 | + name: url-checker-log |
| 65 | + path: scripts/python/url-checker/logs/*.log |
| 66 | + |
| 67 | + - name: Clean up environment |
| 68 | + if: always() |
| 69 | + run: rm -rf scripts/python/url-checker/__pycache__ |
| 70 | + |
| 71 | + - name: Debug values |
| 72 | + run: | |
| 73 | + echo "Event name: ${{ github.event_name }}" |
| 74 | + echo "Input fail-on-broken-links: ${{ github.event.inputs.fail-on-broken-links }}" |
| 75 | + echo "Link check exit code: ${{ steps.check_links.outputs.link_check_exit_code }}" |
| 76 | +
|
| 77 | + - name: Force workflow failure |
| 78 | + if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.fail-on-broken-links == 'true' && steps.check_links.outputs.link_check_exit_code != '0' }} |
| 79 | + run: | |
| 80 | + echo "::error::Broken links were found in the documentation and fail-on-broken-links is set to true." |
| 81 | + exit 1 |
0 commit comments