chaplean/continuous-integration-scripts
Installation
Clone the repository into your Laravel project’s root or a dedicated scripts directory:
git clone https://github.com/chaplean/continuous-integration-scripts.git bin/ci-scripts
Ensure the scripts are executable:
chmod +x bin/ci-scripts/*.sh
First Use Case: Running PHPUnit Tests
Use phpunit.sh to execute tests in CI environments (e.g., GitLab CI, Codeship). Example invocation:
./bin/ci-scripts/phpunit.sh --parallel=4
services-waiting.sh if needed).Key Configurations
./vendor/bin/phpunit).DB_DATABASE, DB_PASSWORD) in your CI pipeline or .env.CI Pipeline Integration
test:
script:
- ./bin/ci-scripts/services-waiting.sh
- ./bin/ci-scripts/phpunit.sh --parallel=2 --coverage
deploy.sh script in the deploy stage after tests pass.Parallel Test Execution
Split PHPUnit tests by class or group using --parallel=N in phpunit.sh. Merge coverage reports with:
./bin/ci-scripts/phpunit.sh --parallel=4 --merge-coverage
Environment-Specific Deployments
deploy-htaccess.sh to conditionally deploy .htaccess files with htpasswd only in staging/production:
if [ "$ENVIRONMENT" = "production" ]; then
./bin/ci-scripts/deploy-htaccess.sh
fi
Docker Service Dependencies
In Dockerized Laravel apps, use services-waiting.sh to wait for MySQL before running migrations/tests:
./bin/ci-scripts/services-waiting.sh mysql://root:secret@db:3306
phpunit.sh to include Laravel’s test bootstrapping (e.g., --bootstrap=vendor/autoload.php).@group unit/@group integration and configure phpunit.xml accordingly.deploy.sh to include Laravel-specific tasks (e.g., php artisan config:cache):
./bin/ci-scripts/deploy.sh --task=deploy:update_code --task=deploy:shared --task="run:artisan config:cache"
Outdated Scripts
--testdox-html or --log-junit flags).phpunit.sh paths).#!/usr/bin/env bash).Hardcoded Paths
bin/ directory structure. Override paths in CI variables:
export SCRIPTS_DIR="custom/path/ci-scripts"
./$SCRIPTS_DIR/phpunit.sh
MySQL Connection Issues
services-waiting.sh may fail if MySQL credentials are misconfigured. Use environment variables:
export DB_URL="mysql://user:pass@host:3306"
./bin/ci-scripts/services-waiting.sh $DB_URL
Parallel Test Conflicts
/tmp). Use --temp-dir in phpunit.sh:
./bin/ci-scripts/phpunit.sh --parallel=4 --temp-dir=/tmp/laravel-tests
set -x to script headers to debug failures.--dry-run (if supported by Capistrano).Custom Scripts
Extend the package by adding scripts (e.g., artisan.sh for Laravel commands):
#!/usr/bin/env bash
./vendor/bin/sail artisan "$@"
Place in bin/ci-scripts/ and make executable.
CI-Specific Hooks
before_script to set up dependencies:
before_script:
- apt-get install -y mysql-client
- ./bin/ci-scripts/services-waiting.sh
deploy: or test: stages with environment variables.Configuration Management
.env.ci file (e.g., DB_PASSWORD) and source it in scripts:
set -a && source .env.ci && set +a
How can I help you explore Laravel packages today?