Skip to content

Instantly share code, notes, and snippets.

@Crell
Last active March 22, 2024 00:22
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Crell/68677c2c4bfce729a1ca0687bc2c534f to your computer and use it in GitHub Desktop.
Save Crell/68677c2c4bfce729a1ca0687bc2c534f to your computer and use it in GitHub Desktop.
Running Lando in GitHub Actions
name: myproject
recipe: laravel
config:
php: '8.1'
via: nginx
database: mysql:5.7
webroot: public
xdebug: true
services:
appserver:
overrides:
environment:
# Support debugging CLI with XDEBUG.
PHP_IDE_CONFIG: "serverName=appserver"
XDEBUG_TRIGGER: lando
xdebug: "debug,develop"
config:
php: php.ini
build_as_root:
# Disable XDebug by default
- rm -f /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && pkill -o -USR2 php-fpm
# Install additional necessary packages.
- pecl install pcov
tooling:
xdebug-on:
service: appserver
description: Enable xdebug for nginx.
cmd: rm -f /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && docker-php-ext-enable xdebug && pkill -o -USR2 php-fpm && echo "Xdebug enabled"
user: root
xdebug-off:
service: appserver
description: Disable xdebug for nginx.
cmd: rm -f /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && pkill -o -USR2 php-fpm && echo "Xdebug disabled"
user: root
{
"name": "mycorp/myapp",
"description": "My app for things",
"type": "project",
"require": {
"php": "^8.0",
"laravel/framework": "8.*"
},
"require-dev": {
"phpunit/phpunit": "^9.5.10",
"rregeer/phpunit-coverage-check": "^0.3.1"
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeds/"
}
},
"scripts": {
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate"
],
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover"
],
"test": "phpunit",
"coverage": "php -dpcov.enabled=1 -dpcov.directory=app vendor/bin/phpunit --coverage-clover build/coverage/clover.xml --coverage-text",
"coverage-check": "coverage-check build/coverage/clover.xml --only-percentage"
},
"config": {
"preferred-install": "dist",
"allow-plugins": {
"kylekatarnls/update-helper": true
}
}
}
name: PHPUnit Tests
on:
- pull_request
- push
env:
CODE_COVERAGE_MINIMUM: 65
LANDO_VERSION: v3.6.5
APP_ENV: testing
APP_DEBUG: true
DB_CONNECTION: mysql
DB_HOST: database
DB_PORT: 3306
DB_DATABASE: laravel
DB_USERNAME: laravel
DB_PASSWORD: laravel
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Grab latest Lando CLI
run: |
sudo curl -fsSL -o /usr/local/bin/lando "https://files.lando.dev/cli/lando-linux-x64-${LANDO_VERSION}"
sudo chmod +x /usr/local/bin/lando
# This is optional.
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
# Map GH Actions env vars into Lando env vars, which wil then be injected
# into the application container.
- run: |
cat > .lando.local.yml <<EOF
services:
appserver:
overrides:
environment:
APP_ENV: '$APP_ENV'
APP_DEBUG: '$APP_DEBUG'
DB_CONNECTION: $DB_CONNECTION
DB_HOST: $DB_HOST
DB_PORT: $DB_PORT
DB_DATABASE: $DB_DATABASE
DB_USERNAME: $DB_USERNAME
DB_PASSWORD: $DB_PASSWORD
EOF
# Boot Lando and set up Laravel
- run: lando start
- run: lando composer install
- run: lando ssh --command "cp .env.example .env"
- run: lando artisan key:generate
- run: lando artisan migrate
- run: lando artisan db:seed
# This will run tests and generate a code coverage file. If any tests fail, it will fail here.
- name: Run tests and generate code coverage report
run: lando composer coverage
# Report the code coverage and fail the build if it's below a threshold.
- run: lando composer coverage-check ${CODE_COVERAGE_MINIMUM} || exit 1
extension=pcov.so
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment