Broken URL Check #12
Workflow file for this run
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: Broken URL Check | |
on: | |
schedule: | |
- cron: '0 0 * * 1' | |
workflow_dispatch: | |
jobs: | |
url-check: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
issues: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- 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 | |
- name: Run link checker | |
id: run_checker | |
run: | | |
output=$(python scripts/urlcheck.py) | |
echo 'checker_output<<EOF' >> $GITHUB_OUTPUT | |
echo "$output" >> $GITHUB_OUTPUT | |
echo 'EOF' >> $GITHUB_OUTPUT | |
env: | |
CHECK_PATH: './pages/' | |
- name: Process results | |
id: process_results | |
run: | | |
output='${{ steps.run_checker.outputs.checker_output }}' | |
echo "Raw output:" | |
echo "$output" | |
json_output=$(echo "$output" | grep -Eo '\{.*\}') | |
total_issues=$(echo "$json_output" | jq -r '.total_issues') | |
echo "TOTAL_ISSUES=$total_issues" >> $GITHUB_ENV | |
if [ "$total_issues" -gt 0 ]; then | |
issue_table=$(echo "$json_output" | jq -r '.issues[] | "| \(.file) | \(.line) | \(.url) | \(.status_code) | \(.reason) |"' | sed -e 's/^/ /') | |
echo 'ISSUE_TABLE<<EOF' >> $GITHUB_ENV | |
echo "$issue_table" >> $GITHUB_ENV | |
echo 'EOF' >> $GITHUB_ENV | |
fi | |
- name: Create Issue | |
if: ${{ env.TOTAL_ISSUES > 0 }} | |
uses: JasonEtco/create-an-issue@v2 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
filename: .github/ISSUE_TEMPLATE_URL_CHECK.md |