Broken URL Check #8
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 | |
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 | |
- name: Process results | |
id: process_results | |
run: | | |
output='${{ steps.run_checker.outputs.checker_output }}' | |
echo "Raw output:" | |
echo "$output" | |
total_issues=$(echo "$output" | jq -r '.total_issues') | |
echo "total_issues=$total_issues" >> $GITHUB_OUTPUT | |
- name: Create Issue with Results | |
if: ${{ fromJson(steps.process_results.outputs.total_issues) > 0 }} | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const output = JSON.parse('${{ steps.run_checker.outputs.checker_output }}'); | |
const issueTitle = `🚨 Broken URLs: ${output.total_issues} issues found`; | |
let issueBody = `## URL Check Results\n\n`; | |
issueBody += `### Issues Found: ${output.total_issues}\n\n`; | |
issueBody += "| File | Line | URL | Status Code | Reason |\n"; | |
issueBody += "|------|------|-----|-------------|--------|\n"; | |
output.issues.forEach(issue => { | |
issueBody += `| ${issue.file} | ${issue.line} | ${issue.url} | ${issue.status_code} | ${issue.reason} |\n`; | |
}); | |
issueBody += "\n\nPlease review and fix these broken URLs."; | |
await github.rest.issues.create({ | |
owner: context.repo.owner, | |
repo: context.repo.name, | |
title: issueTitle, | |
body: issueBody, | |
labels: ['url-check'] | |
}); |