This project is configured to automatically run tests on GitHub Actions.
File: .github/workflows/tests.yml
| Version | Runner | Status | Notes |
|---|---|---|---|
| PHP 7.4 | ubuntu-latest |
✅ Required | Last 7.x version |
| PHP 8.1 | ubuntu-latest |
✅ Required | LTS 8.x version |
| PHP 8.3 | ubuntu-latest |
✅ Required | Latest stable |
| Job | PHP Version | Purpose |
|---|---|---|
coverage |
8.3 | Code coverage analysis with percentage badge generation |
lint |
8.3 | PHP syntax validation |
phpstan |
8.3 | Static analysis |
┌─────────────────────────────────────────────────┐
│ Push/Pull Request to Repository │
└──────────────────┬──────────────────────────────┘
│
┌──────────┴──────────┐
│ │
┌───▼────┐ ┌────▼────┐
│ Test │ │Analysis │
│ Jobs │ │ Jobs │
└───┬────┘ └────┬────┘
│ │
┌───┴────────────┬───────┴─────┬──────────┐
│ │ │ │
┌──▼──┐ ┌──▼──┐ ┌───▼───┐ ┌──▼────┐
│PHP │ │PHP │ │ Lint │ │PHPStan│
│7.4 │ │8.1 │ │ │ │ │
└─────┘ └─────┘ └───────┘ └───────┘
✓ ✓ ✓ ✓
│ │ │ │
┌──▼──┐ ┌───▼────┐ │ │
│PHP │ │Coverage│ │ │
│8.3 │ │ Report │ │ │
└─────┘ └────────┘ │ │
✓ ✓ │ │
└───────────────┴──────────────┴──────────┘
All Required Tests Pass
name: "PHP 7.4 LTS Tests"
runs-on: ubuntu-latest
steps:
- Setup PHP 7.4
- Install PHPUnit 9.5
- Run tests- Purpose: Verify compatibility with PHP 7.4
- Requirement: MUST pass
- Artifacts: test-results-php74 (7 days retention)
- Special: Uses PHPUnit 9.5 for PHP 7.4 compatibility
name: "PHP 8.1 LTS Tests"
runs-on: ubuntu-latest
steps:
- Setup PHP 8.1
- Install dependencies
- Run tests- Purpose: Verify compatibility with PHP 8.1 (LTS)
- Requirement: MUST pass
- Artifacts: test-results-php81 (7 days retention)
name: "PHP 8.3 LTS Tests"
runs-on: ubuntu-latest
steps:
- Setup PHP 8.3
- Install dependencies
- Run tests- Purpose: Verify compatibility with PHP 8.3 (latest stable)
- Requirement: MUST pass
- Artifacts: test-results-php83 (7 days retention)
name: "Code Coverage (PHP 8.3)"
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'- Purpose: Generate detailed coverage report with percentage calculation
- Coverage Calculation: Extracts lines covered vs valid lines from phpunit XML output
- Percentage Color: Badge color changes based on coverage percentage
- 🟢 >= 80%: brightgreen
- 🟢 >= 70%: green
- 🟡 >= 60%: yellowgreen
- 🟡 >= 50%: yellow
- 🔴 < 50%: red
- Requirement: OPTIONAL (continue-on-error: true)
- Artifacts: coverage-report (includes HTML report, XML, and badge.json) - 30 days retention
- Trigger: Only on
mainormasterbranches - Analysis: Uses Xdebug for coverage measurement
- Outputs:
coverage/index.html- Interactive HTML coverage reportcoverage.xml- Clover XML format for tools integration.coverage/badge.json- JSON badge with calculated coverage percentage and color- Log output shows "Coverage: XX%" message
name: "PHP Syntax Check"
continue-on-error: true- Purpose: Validate PHP syntax in all files
- Requirement: OPTIONAL
- Trigger: All pushes and PRs
name: "PHPStan Static Analysis"
continue-on-error: true
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'- Purpose: Static code analysis
- Requirement: OPTIONAL
- Trigger: Only on
mainormasterbranches
- ✅ Project on GitHub.com or GitHub Enterprise
- ✅
.github/workflows/tests.ymlfile in repository - ✅ GitHub Actions enabled for the repository (enabled by default)
Workflow runs automatically:
- ✅ On every
git pushto main/master/develop branches - ✅ On Pull Requests targeting main/master/develop
- ✅ Manual trigger via "Run workflow" button
- Go to Repository > Actions tab
- Select "Tests" workflow
- Click "Run workflow" button
- Select the branch
- Click "Run workflow" to start
Configured:
env:
COMPOSER_FLAGS: --no-progress --no-interactionYou can add repository secrets in Settings > Secrets and variables > Actions
- ✅ Caches Composer dependencies per PHP version
- ✅ Significantly speeds up workflow runs
- ✅ Automatic cache invalidation when composer.json changes
- ✅ All test jobs run in parallel
- ✅ Faster feedback than sequential execution
- ✅ Independent job failures don't block others
- Uses
shivammathur/setup-php@v2action for fast PHP installation - Includes extensions:
curl,json,xdebug(for coverage) - Pre-configured with Composer v2
test-results-phpXX- Test results for each PHP version- Retention: 7 days
coverage-report/- HTML coverage reportcoverage.xml- Clover coverage XML- Retention: 30 days
- Upload: Automatically uploaded to Codecov
On GitHub:
- Repository > Actions tab
- See all workflow runs with status
- Click on a workflow run
- Click on individual jobs to see logs
- View status of each test
- Download
coverage-reportartifact from the workflow run - View Coverage Percentage:
- Go to workflow run details
- Scroll to "Artifacts" section
- Download
coverage-reportartifact - Open
.coverage/badge.jsonto see coverage percentage - Or open
coverage/index.htmlin a browser for interactive report
- Coverage Summary:
- Check job logs in "Code Coverage (PHP 8.3)" job
- Look for "Coverage: XX%" in the output
- Download test artifacts from completed runs
- View in Actions summary page
Add badges to your README.md:
## CI/CD Status
[](https://github.com/deathbycaptcha/deathbycaptcha-api-client-php/actions/workflows/tests.yml)
[](https://github.com/deathbycaptcha/deathbycaptcha-api-client-php/actions/workflows/tests.yml)Coverage reports are automatically generated on every push to main/master:
- Coverage Percentage: Calculated from PHPUnit's clover XML output
- Badge Color: Automatically assigned based on coverage level
- 🟢 80%+: brightgreen | 70-79%: green | 60-69%: yellowgreen | 50-59%: yellow | <50%: red
- Access Reports:
- Download
coverage-reportartifact from workflow run - View HTML report:
coverage/index.html - Check badge data:
.coverage/badge.json - See percentage in job logs
- Download
Recommended settings in Settings > Branches > Branch protection rules:
- ✅ Require status checks to pass before merging
- ✅ Select status checks:
test-php74test-php81test-php83
- ✅ Require branches to be up to date before merging
| Feature | GitLab CI | GitHub Actions |
|---|---|---|
| Config file | .gitlab-ci.yml |
.github/workflows/tests.yml |
| Runners | Docker images | Ubuntu runners with setup-php |
| Caching | Built-in | Uses actions/cache |
| Artifacts | 1-30 days | 1-90 days configurable |
| Parallel | By default | Matrix or separate jobs |
| Triggers | push/MR | push/PR/workflow_dispatch |
- ✅ Composer caching - Much faster dependency installation
- ✅ Matrix builds - Easy to test multiple PHP versions
- ✅ Marketplace - 1000s of pre-built actions
- ✅ Native integration - Deep GitHub integration
- ✅ Free minutes - 2000-3000 minutes/month on free tier
- Check that Actions are enabled: Settings > Actions > General
- Verify the workflow file is in
.github/workflows/directory - Check YAML syntax is valid
- Ensure you have push access to the repository
- Check that the default branch is
mainormaster
- Check PHP version matches (
php -v) - Verify all required extensions are installed
- Check environment variables
- Review detailed logs in Actions tab
- Ensure coverage job ran successfully (check workflow logs)
- Verify
coverage.xmlwas generated from PHPUnit - Check that
.coverage/badge.jsonexists in artifacts - Review "Extract coverage percentage" step in logs
- Ensure Xdebug was properly enabled in coverage job
GitHub Actions includes:
- Public repositories: Unlimited minutes
- Private repositories:
- Free: 2000 minutes/month
- Pro: 3000 minutes/month
- Team/Enterprise: 50,000+ minutes/month
Each workflow run (3 test jobs + coverage + lint + phpstan) takes approximately:
- ~5-8 minutes total (jobs run in parallel)
- ~2-3 minutes billed time per PHP version test job
- ~5-6 minutes billed time for coverage job
- Push this configuration to your repository
- Navigate to Actions tab to see workflow runs
- Add status badge to README.md
- Set up branch protection rules
- Monitor test results and coverage reports
- Download coverage reports from workflow artifacts
- GitHub Actions Documentation: https://docs.github.com/en/actions
- setup-php Action: https://github.com/shivammathur/setup-php
- PHPUnit Documentation: https://docs.phpunit.de/
- Composer: https://getcomposer.org/doc
- Set up branch protection rules
- Monitor test results and coverage on every push
- GitHub Actions Documentation: https://docs.github.com/en/actions
- setup-php Action: https://github.com/shivammathur/setup-php
- PHPUnit Documentation: https://docs.phpunit.de/
- Composer: https://getcomposer.org/doc