phpcq/travis-configuration-check
CLI tool to validate a project's .travis.yml against composer.json. Ensures required PHP versions are defined and covered in Travis, checks that Travis-listed PHP versions exist, and can fail on unmaintained PHP versions (pre-5.4).
Installation:
Add the package to your composer.json under require-dev:
"require-dev": {
"phpcq/travis-configuration-check": "^1.0"
}
Run composer update.
First Run: Execute the CLI tool in your project root:
./vendor/bin/check-travis-configuration.php
This validates that:
.travis.yml match those in composer.json..travis.yml are supported by Travis CI.Quick Use Case: Integrate into a pre-commit hook or CI pipeline to catch misconfigurations early:
# Example: Add to package.json scripts
"scripts": {
"validate:travis": "vendor/bin/check-travis-configuration.php"
}
Local Development Validation: Run during development to catch inconsistencies before pushing:
composer validate:travis
composer.json scripts or a custom Artisan command.CI Pipeline Enforcement:
Fail builds if .travis.yml is invalid:
# .travis.yml
before_script:
- composer validate:travis || travis_terminate 1
Unmaintained Version Checks: Enable stricter security checks (blocks PHP <5.4):
./vendor/bin/check-travis-configuration.php --unmaintained-version-error
Multi-Project Validation: Validate external projects (e.g., monorepos or vendor packages):
./vendor/bin/check-travis-configuration.php /path/to/external/project
Laravel-Specific Integration: Wrap the CLI tool in an Artisan command for seamless Laravel integration:
// app/Console/Commands/ValidateTravisConfig.php
public function handle() {
$command = base_path('vendor/bin/check-travis-configuration.php');
$exitCode = shell_exec("$command " . $this->option('path'));
if ($exitCode !== 0) {
$this->error('Travis config validation failed!');
exit(1);
}
$this->info('Travis config is valid.');
}
app/Console/Kernel.php and run via:
php artisan travis:validate
Git Hook Integration:
Add to .git/hooks/pre-commit to block invalid .travis.yml changes:
#!/bin/sh
./vendor/bin/check-travis-configuration.php || exit 1
CI/CD Pipeline Integration: Use in parallel with other checks (e.g., PHPStan, Pest):
# .github/workflows/ci.yml (GitHub Actions example)
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: composer install
- run: vendor/bin/check-travis-configuration.php
Customize Error Handling: Parse the tool’s output to generate Laravel-friendly error messages:
$output = shell_exec('vendor/bin/check-travis-configuration.php');
if (strpos($output, 'ERROR') !== false) {
throw new \RuntimeException("Travis config error: " . $output);
}
Combine with Laravel’s phpunit:
Ensure PHP versions in .travis.yml align with Laravel’s testing requirements:
# .travis.yml
php:
- 8.1
- 8.2
# composer.json
"config": {
"platform-check": false,
"platform": {
"php": "8.1"
}
}
Extend for Laravel-Specific Checks:
Add custom rules to validate Laravel-specific CI settings (e.g., deploy scripts):
# Example: Check for required Laravel CI variables
if ! grep -q "LARAVEL_ENV=testing" .travis.yml; then
echo "ERROR: Missing LARAVEL_ENV in .travis.yml"
exit 1
fi
Cache Validation Results: Avoid re-running validation in CI by caching results:
# .travis.yml
cache:
directories:
- $HOME/.cache/travis-validation
before_script:
- if [ ! -f "$HOME/.cache/travis-validation/valid" ]; then
composer validate:travis && touch "$HOME/.cache/travis-validation/valid";
fi
Archived Package Risks:
laravel-shift/ci-config).False Positives for Custom PHP Versions:
php: 8.3-nightly) as invalid.--unmaintained-version-error flag cautiously or whitelist versions in a custom wrapper.Circular Dependency in CI:
.travis.yml itself may fail if the tool’s PHP version requirements aren’t met.Laravel-Specific Misalignments:
composer.json may use platform-check: false or custom PHP constraints, causing conflicts.composer.json before validation:
composer config platform.php 8.1
Travis CI Environment Changes:
Verbose Output: The tool lacks verbose logging. To debug:
# Check raw YAML/JSON parsing
vendor/bin/check-travis-configuration.php --debug
.travis.yml and composer.json for inconsistencies.Handling Partial Validations: If the tool fails but you’re sure the config is correct:
#!/bin/sh
if [ "$CI" = "true" ]; then
exit 0 # Skip in CI
else
vendor/bin/check-travis-configuration.php
fi
CI-Specific Errors:
composer.json (e.g., platform constraints) or .travis.yml (e.g., environment variables).composer install --no-platform-reqs in CI to match local validation.Unmaintained Version Logic:
// Example: Update the unmaintained versions list
$unmaintainedVersions = ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3'];
Case Sensitivity in YAML:
.travis.yml keys are case-sensitive. Ensure:
# Correct:
php: 8.1
# Incorrect (will fail):
PHP: 8.1
Composer Platform Constraints:
composer.json uses platform-check: false, the tool may misalign with actual runtime PHP.composer config platform.php 8.1
vendor/bin/check-travis-configuration.php
How can I help you explore Laravel packages today?