This repository demonstrates a GitHub Actions workflow that:
- Dynamically generates a test matrix using Python (different for PRs vs pushes)
- Runs tests across multiple environments
- Pull Requests: Fast, minimal tests with table-based results
- Push to Main: Comprehensive tests with historical tracking (2-week rolling history)
- Publishes results to a GitHub Pages repository with separate views for PRs and historical data
- hello.py - Main test script that outputs both JSON and HTML table rows
- generate_matrix.py - Dynamically generates the test matrix (different for PR vs push)
- aggregate_results.py - Aggregates results and generates HTML (table-based for PRs, historical for pushes)
- .github/workflows/hello-world.yml - GitHub Actions workflow configuration
This workflow behaves differently depending on whether it's triggered by a pull request or a push to main:
| Aspect | Pull Request | Push to Main |
|---|---|---|
| Test Coverage | Fast, minimal tests | Comprehensive tests |
| Matrix Size | Ubuntu + Python 3.11, 3.12 | All OS + Python 3.9-3.12 |
| Results Format | Table-based HTML | Historical view with collapsible sections |
| Storage Location | /pr-tests/ |
/ (root) and /runs/ |
| History Tracking | No (overwritten each time) | Yes (2-week rolling window) |
| Purpose | Quick feedback for PRs | Full regression testing |
- PRs: Developers need fast feedback. Running a minimal test matrix (2 environments) provides quick validation.
- Push: After merge, run comprehensive tests (12 environments) to ensure nothing broke across all platforms.
The workflow consists of 3 jobs:
- generate-matrix - Runs the Python script to generate the test matrix
- hello-world - Executes tests across all matrix combinations and uploads results
- aggregate-and-publish - Collects all results, generates HTML, publishes to GitHub Pages, posts direct URLs to the workflow summary, and comments on PRs
After each workflow run, a detailed summary is automatically posted to the GitHub Actions summary page, including:
- Run information (run number, timestamp, environments tested)
- Direct links to the latest run
- Individual links to each environment result
- A summary table of all tested environments
To view the summary:
- Go to the Actions tab in your repository
- Click on a workflow run
- The summary appears at the top with all direct links
For pull requests, the workflow automatically posts a comment with:
- β Test status
- π¬ Number of environments tested
- π Direct link to detailed results page
- βΉοΈ Information about test coverage
- π Link to workflow run
Note: The workflow uses the default GITHUB_TOKEN with pull-requests: write permission to post PR comments.
- Go to GitHub Settings β Developer settings β Personal access tokens β Tokens (classic)
- Click "Generate new token (classic)"
- Give it a descriptive name (e.g., "GH Pages Deploy Token")
- Select the repo scope (full control of private repositories)
- Generate the token and copy it
- In this repository, go to Settings β Secrets and variables β Actions
- Click "New repository secret"
- Name:
GH_PAGES_DEPLOY_TOKEN - Value: Paste the token you copied
- Click "Add secret"
The workflow is already configured for repository ggbecker/workflow-testing-pages. If you want to change this:
In .github/workflows/hello-world.yml:
- Line 81: Update the
repositoryfield in the checkout step - Line 93: Update the
PAGES_URLenvironment variable - Line 106: Update the full report URL
- Line 107: Update the
external_repositoryfield in the publish step
Example changes:
repository: YOUR_USERNAME/YOUR_PAGES_REPO
PAGES_URL: https://YOUR_USERNAME.github.io/YOUR_PAGES_REPO
external_repository: YOUR_USERNAME/YOUR_PAGES_REPOAlso verify the publish_branch (line 82 and 108):
- Use
mainif your GitHub Pages repository uses the main branch - Use
gh-pagesif it uses a gh-pages branch
- Go to your GitHub Pages repository
- Navigate to Settings β Pages
- Under "Source", select the branch you're publishing to (main or gh-pages)
- Click Save
Edit generate_matrix.py to customize which environments to test. The function generate_matrix() can include any logic:
def generate_matrix():
# Example: Test only on Linux with Python 3.11+
matrix = {
"os": ["ubuntu-latest"],
"python-version": ["3.11", "3.12"]
}
return matrixThe workflow automatically maintains a historical record of test results:
- Retention Period: Results from the last 2 weeks are kept
- Automatic Cleanup: Results older than 2 weeks are automatically removed
- Storage: Each workflow run is saved in the
runs/directory as a timestamped JSON file - Merging: New results are merged with recent historical data on each run
- Before publishing, the workflow checks out the existing GitHub Pages repository
- It loads all previous runs from the
runs/directory - Filters out runs older than 2 weeks
- Adds the new run results
- Regenerates the HTML report with all retained runs
- Publishes only
index.htmlandruns/directory back to GitHub Pages- Note: The workflow uses
keep_files: trueto preserve any other files in your GitHub Pages repository - The
.githubfolder is explicitly protected withexclude_assets: '.github' - Only
index.htmland files inruns/directory are created/updated
- Note: The workflow uses
To change the 2-week retention period, edit aggregate_results.py line 342:
filtered_runs = filter_old_runs(historical_runs, max_age_days=14) # Change 14 to desired daysAfter a PR workflow runs:
- Automatic PR Comment: A comment is automatically posted to the PR with:
- Test status and summary
- Number of environments tested
- Direct link to detailed results
- Information about the test type
- Link to workflow run
- View the summary in the GitHub Actions tab (includes test count and status)
- PR results are published to:
https://YOUR_USERNAME.github.io/YOUR_PAGES_REPO/pr-tests/ - The PR results page shows:
- Summary with PR number and test type
- Table with all tested environments
- Status badge for each test
- Link back to full historical results
After a push to main:
- Results are published to your GitHub Pages repository
- View the HTML report at:
https://YOUR_USERNAME.github.io/YOUR_PAGES_REPO/ - The report shows:
- Summary of all test runs from the last 2 weeks
- Expandable sections for each workflow run
- All test environments with platform details
- Latest run marked with a badge
Each test run and environment result has a unique URL for easy sharing:
Method 1: From GitHub Actions Summary
- Go to the Actions tab and click on a workflow run
- The summary at the top contains direct links to all results
- Click any link to jump directly to that specific result
Method 2: From the HTML Report
- Click the "π Link" button next to any run number to copy its URL
- Click the "π" button on any environment card to copy its URL
- The URL is automatically copied to your clipboard
URL Examples:
- Full run:
https://YOUR_USERNAME.github.io/#run-0 - Specific environment:
https://YOUR_USERNAME.github.io/#env-0-1
When someone visits these URLs:
- The page automatically scrolls to the linked result
- The relevant section automatically expands if collapsed
- The target element is highlighted briefly for easy identification
Test the scripts locally:
# Test the hello world script
python hello.py
# Test matrix generation
python generate_matrix.py
# Test aggregation (after creating artifacts directory with results)
mkdir -p artifacts
# ... copy some result.json files to artifacts/ ...
python aggregate_results.pyThe workflow runs on:
- Push to main branch
- Pull requests to main branch
- Manual trigger (workflow_dispatch)
Results from each matrix job are stored as artifacts for 30 days and can be downloaded from the Actions tab.
After running the workflow, your GitHub Pages repository will have the following structure:
YOUR_PAGES_REPO/
βββ index.html # Historical HTML report with all push runs
βββ runs/ # Historical run data (from pushes)
β βββ 2025-11-05-14-30-15.json
β βββ 2025-11-04-10-22-33.json
β βββ 2025-11-03-08-15-42.json
β βββ ... # One JSON file per push workflow run
βββ pr-tests/ # Pull request test results
βββ index.html # Table-based PR results (updated per PR)
For Push Events:
- Each JSON file in the
runs/directory contains:- Timestamp of the run
- GitHub workflow run number and ID
- Array of results from all matrix environments tested in that run
For Pull Request Events:
- The
pr-tests/index.htmlfile is overwritten with each PR run - Contains a table view of the minimal test results
- No historical tracking for PRs (focused on speed)
- Smart Test Strategy:
- Pull Requests: Fast tests (2 environments) for quick feedback
- Push to Main: Comprehensive tests (12 environments) for full validation
- Dynamic Matrix Generation: Automatically adjusts test matrix based on PR vs push context
- Dual Result Views:
- PR Results: Clean table-based view for quick scanning
- Historical Results: Rich, collapsible sections with 2-week history
- Historical Tracking: View results from all push runs in the last 2 weeks (auto-cleanup)
- Direct URLs: Each run and environment result has a unique URL that can be copied and shared
- Click the "π Link" button on any run to copy its direct URL
- Click the "π" button on any environment card to copy its direct URL
- URLs automatically expand the relevant section when accessed
- GitHub Actions Integration:
- Automatic summary posted to each workflow run
- Different summaries for PR vs push events
- Direct links to results in summary
- PR Comments: Automatic comment on pull requests with test results and links
- Cross-Platform Testing: Test across Linux, Windows, and macOS with multiple Python versions
- Safe Publishing: Uses
keep_files: trueandexclude_assets: '.github'to preserve existing files and protect the.githubfolder in the GitHub Pages repository - Flexible Output: Results available as both JSON (for processing) and HTML (for viewing)
- Zero Maintenance: Once set up, the workflow handles everything automatically