Merge pull request #611 from Azure/canary #155
This file contains 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: Check Broken Links | |
on: | |
schedule: | |
- cron: '0 0 * * *' | |
push: | |
branches: | |
- canary | |
- main | |
# Enable manual triggering from GitHub Actions tab | |
workflow_dispatch: | |
inputs: | |
fail-on-broken-links: | |
description: 'Fail workflow if broken links are found' | |
required: true | |
type: choice | |
default: 'true' | |
options: | |
- 'true' | |
- 'false' | |
jobs: | |
url-check: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.x' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install requests colorama | |
- name: Enable Color Output | |
run: echo "FORCE_COLOR=1" >> $GITHUB_ENV | |
- name: Check for broken links | |
id: check_links | |
continue-on-error: true | |
run: | | |
python scripts/python/url-checker/url-checker.py | |
EXIT_CODE=$? | |
echo "link_check_exit_code=$EXIT_CODE" >> $GITHUB_OUTPUT | |
# Always display the summary clearly | |
echo "### URL Check Results" >> $GITHUB_STEP_SUMMARY | |
if [ $EXIT_CODE -eq 0 ]; then | |
echo "✅ All links are valid!" >> $GITHUB_STEP_SUMMARY | |
else | |
echo "⚠️ Some broken links were found. Check the logs for details." >> $GITHUB_STEP_SUMMARY | |
echo "Download the log artifacts for the complete report." >> $GITHUB_STEP_SUMMARY | |
fi | |
- name: Upload log file | |
if: always() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: url-checker-log | |
path: scripts/python/url-checker/logs/*.log | |
- name: Clean up environment | |
if: always() | |
run: rm -rf scripts/python/url-checker/__pycache__ | |
- name: Extreme debugging | |
run: | | |
echo "EVENT NAME: ${{ github.event_name }}" | |
echo "INPUTS: ${{ toJSON(github.event.inputs) }}" | |
echo "FAIL ON BROKEN LINKS: ${{ github.event.inputs.fail-on-broken-links }}" | |
echo "EXIT CODE: ${{ steps.check_links.outputs.link_check_exit_code }}" | |
# Create a shell script to evaluate the condition | |
cat > test_condition.sh << 'EOF' | |
#!/bin/bash | |
EVENT_NAME="${1}" | |
FAIL_ON_BROKEN="${2}" | |
EXIT_CODE="${3}" | |
echo "Evaluating:" | |
echo "- EVENT_NAME: ${EVENT_NAME}" | |
echo "- FAIL_ON_BROKEN: ${FAIL_ON_BROKEN}" | |
echo "- EXIT_CODE: ${EXIT_CODE}" | |
if [[ "${EVENT_NAME}" == "workflow_dispatch" ]]; then | |
echo "✓ Event is workflow_dispatch" | |
else | |
echo "✗ Event is NOT workflow_dispatch" | |
fi | |
if [[ "${FAIL_ON_BROKEN}" == "true" ]]; then | |
echo "✓ fail-on-broken-links is true" | |
else | |
echo "✗ fail-on-broken-links is NOT true" | |
fi | |
if [[ "${EXIT_CODE}" != "0" ]]; then | |
echo "✓ EXIT_CODE is non-zero (links broken)" | |
else | |
echo "✗ EXIT_CODE is zero (no broken links)" | |
fi | |
if [[ "${EVENT_NAME}" == "workflow_dispatch" && "${FAIL_ON_BROKEN}" == "true" && "${EXIT_CODE}" != "0" ]]; then | |
echo "✓✓✓ ALL CONDITIONS MET - WORKFLOW SHOULD FAIL" | |
exit 1 | |
else | |
echo "✗✗✗ NOT ALL CONDITIONS MET - WORKFLOW SHOULD SUCCEED" | |
exit 0 | |
fi | |
EOF | |
chmod +x test_condition.sh | |
# Run the script with our values | |
./test_condition.sh "${{ github.event_name }}" "${{ github.event.inputs.fail-on-broken-links }}" "${{ steps.check_links.outputs.link_check_exit_code }}" | |
SHOULD_FAIL=$? | |
echo "SHOULD_FAIL: ${SHOULD_FAIL}" | |
echo "should_fail=${SHOULD_FAIL}" >> $GITHUB_OUTPUT | |
id: extreme_debug | |
- name: Fail workflow conditionally | |
if: steps.extreme_debug.outputs.should_fail == '1' | |
run: | | |
echo "::error::Broken links were found in the documentation and fail-on-broken-links is set to true." | |
exit 1 |