Skip to content

Blocklist Healthcheck #6

Blocklist Healthcheck

Blocklist Healthcheck #6

name: Blocklist Healthcheck
on:
workflow_dispatch:
schedule:
# Every Monday at 06:15 UTC (01:15 America/Toronto standard time)
- cron: "15 6 * * 1"
permissions:
contents: read
issues: write
jobs:
healthcheck:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests
# Important: do NOT fail the workflow here.
# We'll decide whether to open an issue based on the JSON report.
- name: Run blocklist healthcheck
run: |
python scripts/blocklist_healthcheck.py \
--catalog BLOCKLIST_CATALOG.md \
--out-md healthcheck-report.md \
--out-json healthcheck-report.json \
--timeout 12 \
--max-redirects 5
- name: Add report to workflow summary
run: |
echo "## Blocklist Healthcheck" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
cat healthcheck-report.md >> $GITHUB_STEP_SUMMARY
- name: Upload reports
uses: actions/upload-artifact@v4
with:
name: blocklist-healthcheck
path: |
healthcheck-report.md
healthcheck-report.json
- name: Determine if any lists are down
id: downcheck
run: |
python - <<'PY'
import json
with open("healthcheck-report.json","r",encoding="utf-8") as f:
data=json.load(f)
down=int(data.get("unreachable",0))
print(f"down={down}")
with open("$GITHUB_OUTPUT","a",encoding="utf-8") as out:
out.write(f"down={down}\n")
PY
- name: Create or update issue when lists are down
if: ${{ steps.downcheck.outputs.down != '0' }}
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const issueTitle = "Blocklist Healthcheck: Unreachable blocklists";
const body = fs.readFileSync('healthcheck-report.md', 'utf8');
// Find an existing open issue with the same title
const { data: issues } = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: "open",
per_page: 100,
});
const existing = issues.find(i => i.title === issueTitle);
if (!existing) {
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: issueTitle,
body: body + "\n\n---\n" +
`Workflow run: ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
labels: ["healthcheck", "blocklists"],
});
} else {
// Add a new comment to the existing issue
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: existing.number,
body: body + "\n\n---\n" +
`Workflow run: ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
});
}