Skip to content

Instantly share code, notes, and snippets.

@hhamon
Last active October 1, 2022 15:28
Show Gist options
  • Save hhamon/378231d2852e45fffddaa7135fcd6773 to your computer and use it in GitHub Desktop.
Save hhamon/378231d2852e45fffddaa7135fcd6773 to your computer and use it in GitHub Desktop.
Github Actions PHP CI
name: '[PROJECT NAME]'
'on':
push:
branches:
- master
- develop
- 'releases/**'
pull_request: null
env:
working_directory: ./application
php_extensions: 'apcu, bcmath, ctype, curl, dom, iconv, intl, json, mbstring, opcache, openssl, pdo, pdo_pgsql, pcntl, pcov, posix, redis, session, simplexml, sockets, tokenizer, xml, xmlwriter, zip'
key: cache-v0.1
DATABASE_URL: 'postgres://postgres:postgres@localhost:5432/application?charset=UTF-8'
REDIS_URL: 'redis://localhost:6379'
jobs:
lint:
strategy:
fail-fast: false
matrix:
operating-system:
- ubuntu-latest
php-versions:
- '7.3'
runs-on: '${{ matrix.operating-system }}'
name: 'Lint / PHP ${{ matrix.php-versions }} @ ${{ matrix.operating-system }}'
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: 'Setup cache environment'
id: cache-env
uses: shivammathur/cache-extensions@v1
with:
php-version: '${{ matrix.php-versions }}'
extensions: '${{ env.php_extensions }}'
key: '${{ env.key }}'
-
name: 'Cache extensions'
uses: actions/cache@v1
with:
path: '${{ steps.cache-env.outputs.dir }}'
key: '${{ steps.cache-env.outputs.key }}'
restore-keys: '${{ steps.cache-env.outputs.key }}'
-
name: 'Setup PHP'
uses: shivammathur/setup-php@v2
with:
php-version: '${{ matrix.php-versions }}'
extensions: '${{ env.php_extensions }}'
ini-values: 'date.timezone=UTC, upload_max_filesize=20M, post_max_size=20M, memory_limit=512M, short_open_tag=Off'
coverage: xdebug
tools: 'cs2pr, php-cs-fixer, phpstan, phpunit'
-
name: 'Setup problem matchers for PHP (aka PHP error logs)'
run: 'echo "::add-matcher::${{ runner.tool_cache }}/php.json"'
-
name: 'Setup problem matchers for PHPUnit'
run: 'echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"'
-
name: 'Get Composer cache directory'
id: composer-cache
run: 'echo "::set-output name=dir::$(composer config cache-files-dir)"'
working-directory: '${{env.working_directory}}'
-
name: 'Cache dependencies'
uses: actions/cache@v1
with:
path: '${{ steps.composer-cache.outputs.dir }}'
key: '${{ runner.os }}-composer-${{ hashFiles(''**/composer.lock'') }}'
restore-keys: '${{ runner.os }}-composer-'
-
name: 'Validate composer.json and composer.lock'
run: 'composer validate'
working-directory: '${{env.working_directory}}'
-
name: 'Install PHP dependencies with Composer'
run: 'composer install --prefer-dist --no-progress --no-suggest --optimize-autoloader'
working-directory: '${{env.working_directory}}'
-
name: 'Linting PHP source files'
run: 'php -l src || echo "No syntax errors detected in src"'
working-directory: '${{env.working_directory}}'
-
name: 'Linting PHP tests files'
run: 'php -l tests || echo "No syntax errors detected in tests"'
working-directory: '${{env.working_directory}}'
-
name: 'Linting Twig templates'
run: 'php bin/console lint:twig --show-deprecations templates'
working-directory: '${{env.working_directory}}'
-
name: 'Linting YAML configuration files'
run: 'php bin/console lint:yaml --parse-tags config'
working-directory: '${{env.working_directory}}'
-
name: 'Linting YAML translations files'
run: 'php bin/console lint:yaml --parse-tags translations'
working-directory: '${{env.working_directory}}'
-
name: 'Linting XLIFF translations files'
run: 'php bin/console lint:xliff translations'
working-directory: '${{env.working_directory}}'
-
name: 'Linting Symfony service container'
run: 'php bin/console lint:container'
working-directory: '${{env.working_directory}}'
static_analysis:
strategy:
fail-fast: false
matrix:
operating-system:
- ubuntu-latest
php-versions:
- '7.3'
runs-on: '${{ matrix.operating-system }}'
name: 'Static Analysis / PHP ${{ matrix.php-versions }} @ ${{ matrix.operating-system }}'
needs:
- lint
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: 'Setup cache environment'
id: cache-env
uses: shivammathur/cache-extensions@v1
with:
php-version: '${{ matrix.php-versions }}'
extensions: '${{ env.php_extensions }}'
key: '${{ env.key }}'
-
name: 'Cache extensions'
uses: actions/cache@v1
with:
path: '${{ steps.cache-env.outputs.dir }}'
key: '${{ steps.cache-env.outputs.key }}'
restore-keys: '${{ steps.cache-env.outputs.key }}'
-
name: 'Setup PHP'
uses: shivammathur/setup-php@v2
with:
php-version: '${{ matrix.php-versions }}'
extensions: '${{ env.php_extensions }}'
ini-values: 'date.timezone=UTC, upload_max_filesize=20M, post_max_size=20M, memory_limit=512M, short_open_tag=Off'
coverage: xdebug
tools: 'cs2pr, php-cs-fixer, phpstan, phpunit'
-
name: 'Setup problem matchers for PHP (aka PHP error logs)'
run: 'echo "::add-matcher::${{ runner.tool_cache }}/php.json"'
-
name: 'Setup problem matchers for PHPUnit'
run: 'echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"'
-
name: 'Get Composer cache directory'
id: composer-cache
run: 'echo "::set-output name=dir::$(composer config cache-files-dir)"'
working-directory: '${{env.working_directory}}'
-
name: 'Cache dependencies'
uses: actions/cache@v1
with:
path: '${{ steps.composer-cache.outputs.dir }}'
key: '${{ runner.os }}-composer-${{ hashFiles(''**/composer.lock'') }}'
restore-keys: '${{ runner.os }}-composer-'
-
name: 'Validate composer.json and composer.lock'
run: 'composer validate'
working-directory: '${{env.working_directory}}'
-
name: 'Install PHP dependencies with Composer'
run: 'composer install --prefer-dist --no-progress --no-suggest --optimize-autoloader'
working-directory: '${{env.working_directory}}'
-
name: 'Static Analysis using PHP-CS-Fixer'
run: 'php-cs-fixer fix --dry-run --diff --format=checkstyle | cs2pr'
working-directory: '${{env.working_directory}}'
-
name: 'Static Analysis using PHPStan'
run: 'phpstan analyse --no-progress -v --level=max --error-format=checkstyle src | cs2pr'
working-directory: '${{env.working_directory}}'
-
name: 'Static Analysis using PSALM'
run: './vendor/bin/psalm --threads=8 --diff --diff-methods --show-info=true'
working-directory: '${{env.working_directory}}'
unit_testing:
strategy:
fail-fast: false
matrix:
operating-system:
- ubuntu-latest
php-versions:
- '7.3'
runs-on: '${{ matrix.operating-system }}'
name: 'Unit Testing / PHP ${{ matrix.php-versions }} @ ${{ matrix.operating-system }}'
needs:
- lint
- static_analysis
services:
postgres:
image: 'postgres:11'
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: application
ports:
- '5432:5432'
options: '--health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5'
redis:
image: redis
ports:
- '6379:6379'
options: '--health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=5'
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: 'Setup cache environment'
id: cache-env
uses: shivammathur/cache-extensions@v1
with:
php-version: '${{ matrix.php-versions }}'
extensions: '${{ env.php_extensions }}'
key: '${{ env.key }}'
-
name: 'Cache extensions'
uses: actions/cache@v1
with:
path: '${{ steps.cache-env.outputs.dir }}'
key: '${{ steps.cache-env.outputs.key }}'
restore-keys: '${{ steps.cache-env.outputs.key }}'
-
name: 'Setup PHP'
uses: shivammathur/setup-php@v2
with:
php-version: '${{ matrix.php-versions }}'
extensions: '${{ env.php_extensions }}'
ini-values: 'date.timezone=UTC, upload_max_filesize=20M, post_max_size=20M, memory_limit=512M, short_open_tag=Off'
coverage: xdebug
tools: 'cs2pr, php-cs-fixer, phpstan, phpunit'
-
name: 'Setup problem matchers for PHP (aka PHP error logs)'
run: 'echo "::add-matcher::${{ runner.tool_cache }}/php.json"'
-
name: 'Setup problem matchers for PHPUnit'
run: 'echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"'
-
name: 'Get Composer cache directory'
id: composer-cache
run: 'echo "::set-output name=dir::$(composer config cache-files-dir)"'
working-directory: '${{env.working_directory}}'
-
name: 'Cache dependencies'
uses: actions/cache@v1
with:
path: '${{ steps.composer-cache.outputs.dir }}'
key: '${{ runner.os }}-composer-${{ hashFiles(''**/composer.lock'') }}'
restore-keys: '${{ runner.os }}-composer-'
-
name: 'Validate composer.json and composer.lock'
run: 'composer validate'
working-directory: '${{env.working_directory}}'
-
name: 'Install PHP dependencies with Composer'
run: 'composer install --prefer-dist --no-progress --no-suggest --optimize-autoloader'
working-directory: '${{env.working_directory}}'
-
name: 'Create PostgreSQL Database'
run: 'php bin/console doctrine:database:create --if-not-exists'
working-directory: '${{env.working_directory}}'
-
name: 'Migrate PostgreSQL Database Schema'
run: 'php bin/console doctrine:migrations:migrate -n || echo "No migrations found or migration failed"'
working-directory: '${{env.working_directory}}'
-
name: 'Load PostgreSQL Database Fixtures'
run: 'php bin/console doctrine:fixtures:load -n'
working-directory: '${{env.working_directory}}'
-
name: 'Run Unit Tests with PHPUnit'
run: 'php bin/phpunit --coverage-text --coverage-clover=coverage/clover.xml'
working-directory: '${{env.working_directory}}'
-
name: 'Send Code Coverage Report'
continue-on-error: true
timeout-minutes: 1
run: 'curl -s https://codecov.io/bash | bash -s -- -t ${{secrets.CODECOV_TOKEN}} -f coverage/clover.xml -n github-actions-codecov-${{ matrix.operating-system }}-php${{ matrix.php-versions }}'
working-directory: '${{env.working_directory}}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment