Skip to content

Broken URL Check

Broken URL Check #11

Workflow file for this run

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: |
python3 scripts/urlcheck.py > output.json
- name: Process results
id: process_results
run: |
output=$(cat output.json)
echo "Raw output:"
echo "$output"
total_issues=$(echo "$output" | jq -r '.total_issues')
if [ "$total_issues" -gt 0 ]; then
issue_body=$(echo "$output" | jq -r '.issues | map("File: " + .file + "\nLine: " + (.line|tostring) + "\nURL: " + .url + "\nStatus Code: " + (.status_code|tostring) + "\nReason: " + .reason + "\nFinal URL: " + .final_url + "\n\n") | join("\n")')
echo "$issue_body"
echo "issue_body=$issue_body" >> $GITHUB_ENV
fi
rm output.json
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 issueTitle = `🚨 Broken URLs: ${process.env.total_issues} issues found`;
const issueBody = process.env.issue_body;
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.name,
title: issueTitle,
body: issueBody,
labels: ['url-check']
});