-
Notifications
You must be signed in to change notification settings - Fork 61
130 lines (110 loc) · 3.99 KB
/
url-checker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
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