Installation
Clone the repository into your project’s bin/ directory:
git clone https://github.com/chaplean/codeship-scripts.git bin/codeship-scripts
Ensure scripts are executable:
chmod +x bin/codeship-scripts/*.sh
First Use Case: Running PHPUnit Tests
Use phpunit.sh in your CI pipeline (e.g., Codeship) to execute tests after MySQL is ready:
./bin/codeship-scripts/phpunit.sh --parallel=4
4 with the number of parallel processes (optional).services-waiting.sh.First Use Case: Deploying with Capistrano
Configure deploy.sh for your environment:
./bin/codeship-scripts/deploy.sh --env=production --user=deploy
config/deploy.rb file (Capistrano-compatible).--dry-run to test without deploying.CI Pipeline Integration
services-waiting.sh before database-dependent scripts (e.g., phpunit.sh or migrations).
./bin/codeship-scripts/services-waiting.sh --service=mysql
./bin/codeship-scripts/phpunit.sh
./bin/codeship-scripts/phpunit.sh --parallel=2 --chunk=1 # Run chunk 1 of 2
Environment-Specific Deployments
deploy-htaccess.sh for environment-specific .htaccess files (e.g., prod.htaccess vs. staging.htaccess):
./bin/codeship-scripts/deploy-htaccess.sh --env=staging
deploy.sh for full deployments:
./bin/codeship-scripts/deploy.sh --env=staging && ./bin/codeship-scripts/deploy-htaccess.sh --env=staging
Docker Service Dependencies
./bin/codeship-scripts/services-waiting.sh --service=mysql --service=redis
Laravel-Specific:
.env management, prepend deployment steps to copy .env.example and generate keys:
cp .env.example .env && php artisan key:generate && ./bin/codeship-scripts/deploy.sh
phpunit.sh with Laravel’s test configuration:
./bin/codeship-scripts/phpunit.sh --config=phpunit.xml --parallel=4
(Note: Requires passing --config explicitly if not using default phpunit.xml.)Codeship Configuration:
codeship-services.yml or codeship-steps.yml:
- service: app
command: ./bin/codeship-scripts/services-waiting.sh --service=mysql && ./bin/codeship-scripts/phpunit.sh
Hardcoded Paths
bin/codeship-scripts/ is in your $PATH or called with relative paths. Avoid moving the directory without updating references.MySQL Credentials
services-waiting.sh and phpunit.sh rely on environment variables (DB_HOST, DB_DATABASE, etc.). Ensure they are set in your CI environment:
export DB_HOST=mysql && ./bin/codeship-scripts/phpunit.sh
Capistrano Dependencies
deploy.sh requires:
config/deploy.rb (Capistrano 3.x syntax).--user flag).--dry-run:
./bin/codeship-scripts/deploy.sh --dry-run --env=production
Parallel Testing Quirks
--parallel in phpunit.sh splits tests by file order. For consistent chunks, sort your test files or use --chunk:
./bin/codeship-scripts/phpunit.sh --parallel=2 --chunk=1
HTAccess Overwrites
deploy-htaccess.sh assumes .htaccess files are named <env>.htaccess (e.g., staging.htaccess). Customize the script if your naming differs.-v to any script for debugging:
./bin/codeship-scripts/phpunit.sh -v
services-waiting.sh (default: 30 seconds) by editing the script or passing a custom timeout:
./bin/codeship-scripts/services-waiting.sh --service=mysql --timeout=60
Custom Services
Modify services-waiting.sh to support additional services (e.g., Elasticsearch) by adding logic to the check_service function.
PHPUnit Configuration
Extend phpunit.sh to support custom test suites or plugins:
./bin/codeship-scripts/phpunit.sh --group=unit,integration
(Requires editing the script to pass --group to PHPUnit.)
Post-Deploy Hooks
Append commands to deploy.sh for Laravel-specific tasks (e.g., cache clearing):
./bin/codeship-scripts/deploy.sh --env=production && ssh user@server "cd /path/to/app && php artisan cache:clear"
export CAPISTRANO_USER=deploy && ./bin/codeship-scripts/deploy.sh
#!/bin/bash (not #!/usr/bin/env bash) for consistency across CI environments.How can I help you explore Laravel packages today?