URL Validation GitHub Action
URL Validation GitHub Action
This repository includes a GitHub Action workflow for validating government website URLs from TOON files.
How to Trigger the Workflow
- Navigate to the Actions tab in the GitHub repository
- Select “Validate Government URLs” from the workflows list
- Click “Run workflow”
- Configure the run:
- Country: (Optional) Enter a specific country code to validate (e.g.,
TEXAS,CALIFORNIA,NEW_YORK)- Leave empty to validate all countries
- Rate limit: (Optional) Maximum requests per second (default: 2.0)
- Country: (Optional) Enter a specific country code to validate (e.g.,
- Click “Run workflow” to start the validation
What the Workflow Does
The workflow will:
- Install dependencies - Sets up Python 3.12 and installs required packages
- Run URL validation - Validates URLs from TOON files
- Checks if URLs are accessible
- Tracks HTTP status codes
- Records redirects
- Marks URLs that fail twice for removal
- Generate report - Creates a comprehensive markdown report with:
- Summary statistics by country
- Success rates
- Detailed error information
- List of URLs with issues
- Upload artifacts - Makes the following available for download:
validation-report.md- Comprehensive validation reportvalidation-output.txt- Raw console outputmetadata.db- SQLite database with detailed results
- Display summary - Shows key results directly in the workflow summary
Viewing Results
In the Workflow Summary
After the workflow completes, you can view a summary directly in the GitHub Actions interface:
- Go to the Actions tab
- Click on the completed workflow run
- The validation report summary will be displayed at the top of the page
Downloading Detailed Results
To download the full report and data:
- Scroll to the bottom of the workflow run page
- Find the Artifacts section
- Click on “validation-report” to download a ZIP file containing:
- Full validation report (markdown)
- Raw validation output (text)
- SQLite database with all validation results
Understanding the Report
The validation report includes:
Summary Table
Shows for each country:
- Total URLs: Number of URLs checked
- Valid: URLs that responded successfully (HTTP 2xx)
- Invalid: URLs that returned errors or non-2xx status
- Redirected: URLs that redirected to another location
- Removed: URLs that failed validation twice (removed from TOON file)
- Success Rate: Percentage of valid URLs
Error Details
Lists all invalid URLs grouped by:
- Country
- HTTP status code
- Error message
URLs marked with ⚠️ REMOVED have failed validation twice and have been removed from the TOON file.
Validation Rules
- First failure: URL is marked as invalid but kept in the TOON file
- Second failure: URL is marked as invalid and removed from the TOON file
- Redirects: URLs that redirect are updated in the TOON file to point to the final destination
- Rate limiting: Requests are rate-limited to avoid overwhelming servers (default: 2 requests/second)
Manual Validation
You can also run validations locally using the CLI:
# Install dependencies
pip install -r requirements.txt
# Validate a specific country
python3 -m src.cli.validate_urls --country TEXAS --rate-limit 2
# Validate all countries
python3 -m src.cli.validate_urls --all --rate-limit 2
# Generate a report from the database
python3 -m src.cli.generate_validation_report --output validation-report.md
Scheduling Regular Validations
To set up automatic quarterly validations, you can add a schedule trigger to the workflow:
on:
workflow_dispatch:
# ... existing inputs ...
schedule:
# Run quarterly: January 1, April 1, July 1, October 1 at 00:00 UTC
- cron: '0 0 1 1,4,7,10 *'
Troubleshooting
Workflow Times Out
If validating all countries takes too long:
- Increase the
timeout-minutesvalue in the workflow - Run validations for individual countries instead of all at once
- Increase the
rate_limitparameter (but be mindful of server load)
High Failure Rate
If many URLs are failing:
- Check the error messages in the detailed report
- Common issues:
- DNS resolution failures
- SSL/TLS certificate errors
- Connection timeouts
- HTTP errors (404, 500, etc.)
Database Locked Errors
If you see database locked errors:
- Ensure only one validation is running at a time
- Don’t run multiple workflow instances simultaneously
Data Retention
- Workflow artifacts are retained for 90 days
- After 90 days, you’ll need to re-run the validation to regenerate reports
- The SQLite database can be queried for custom analysis