From fd3a54a157c14340dfea3ffbf8d429388497a87a Mon Sep 17 00:00:00 2001 From: Dante Di Domenico Date: Tue, 2 Feb 2021 10:33:39 +0100 Subject: [PATCH] GitHub actions (#36) * feat: github actions php workflow --- .github/workflows/php.yml | 177 ++++++++++++++++++++++++++++++++++++++ .travis.yml | 50 ----------- README.md | 2 +- 3 files changed, 178 insertions(+), 51 deletions(-) create mode 100644 .github/workflows/php.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml new file mode 100644 index 0000000..c7cf247 --- /dev/null +++ b/.github/workflows/php.yml @@ -0,0 +1,177 @@ +name: 'php' + +on: + pull_request: + paths: + - '**/*.php' + push: + paths: + - '**/*.php' + +jobs: + cs: + name: 'Check coding style' + if: "!contains(github.event.commits[0].message, '[skip ci]') && !contains(github.event.commits[0].message, '[ci skip]')" + runs-on: 'ubuntu-18.04' + + strategy: + matrix: + php-version: [7.2] + + steps: + - name: 'Checkout current revision' + uses: 'actions/checkout@v2' + + - name: 'Setup PHP' + uses: 'shivammathur/setup-php@v2' + with: + php-version: '${{ matrix.php-version }}' + tools: 'composer:v1' + extensions: 'mbstring, intl' + coverage: 'none' + + - name: 'Discover Composer cache directory' + id: 'cachedir' + run: 'echo "::set-output name=path::$(composer global config cache-dir)"' + + - name: 'Share Composer cache across runs' + uses: 'actions/cache@v2' + with: + path: '${{ steps.cachedir.outputs.path }}' + key: "composer-${{ github.job }}-${{ hashFiles('**/composer.json') }}" + restore-keys: | + composer-${{ github.job }}- + composer- + + - name: 'Install dependencies with Composer' + run: 'composer install --prefer-dist --no-interaction' + + - name: 'Run PHP CodeSniffer' + run: | + vendor/bin/phpcs -n -p --extensions=php \ + --standard=vendor/cakephp/cakephp-codesniffer/CakePHP \ + ./config ./src ./tests + + stan: + name: 'Static code analyzer' + if: "!contains(github.event.commits[0].message, '[skip ci]') && !contains(github.event.commits[0].message, '[ci skip]')" + runs-on: 'ubuntu-18.04' + continue-on-error: true + + strategy: + matrix: + php-version: [7.2, 7.3, 7.4] + + steps: + - name: 'Checkout current revision' + uses: 'actions/checkout@v2' + + - name: 'Setup PHP' + uses: 'shivammathur/setup-php@v2' + with: + php-version: '${{ matrix.php-version }}' + tools: 'composer:v1, phpstan' + extensions: 'mbstring, intl' + coverage: 'none' + + - name: 'Discover Composer cache directory' + id: 'cachedir' + run: 'echo "::set-output name=path::$(composer global config cache-dir)"' + + - name: 'Share Composer cache across runs' + uses: 'actions/cache@v2' + with: + path: '${{ steps.cachedir.outputs.path }}' + key: "composer-${{ github.job }}-${{ hashFiles('**/composer.json') }}" + restore-keys: | + composer-${{ github.job }}- + composer- + + - name: 'Install dependencies with Composer' + run: 'composer install --prefer-dist --no-interaction' + + - name: 'Run PHP STAN' + run: | + phpstan analyse --no-progress src + + unit: + name: 'Run unit tests' + if: "!contains(github.event.commits[0].message, '[skip ci]') && !contains(github.event.commits[0].message, '[ci skip]')" + runs-on: 'ubuntu-18.04' + env: + BEDITA_API_KEY: 12345 + BEDITA_API: http://127.0.0.1:8080 + BEDITA_ADMIN_USR: admin + BEDITA_ADMIN_PWD: admin + BEDITA_DOCKER_IMG: bedita/bedita:4.2.1 + + strategy: + matrix: + php-version: [7.2, 7.3, 7.4] + + steps: + - name: 'Checkout current revision' + uses: 'actions/checkout@v2' + + - name: 'Composer config GH token if available' + run: 'if [ -n "$GH_TOKEN" ]; then composer config github-oauth.github.com ${GH_TOKEN}; fi' + + - name: 'Docker pull bedita image' + run: 'docker pull ${BEDITA_DOCKER_IMG}' + + - name: 'Docker inspect bedita image' + run: 'docker inspect ${BEDITA_DOCKER_IMG}' + + - name: 'Docker run bedita image' + run: 'docker run --name api -d -p 127.0.0.1:8080:80 --env BEDITA_API_KEY=${BEDITA_API_KEY} --env BEDITA_ADMIN_USR=${BEDITA_ADMIN_USR} --env BEDITA_ADMIN_PWD=${BEDITA_ADMIN_PWD} ${BEDITA_DOCKER_IMG}' + + - name: 'Wait for 10' + run: 'sleep 10' + + - name: 'Docker ps - show all containers' + run: 'docker ps -a' + + - name: 'Setup PHP' + uses: 'shivammathur/setup-php@v2' + with: + php-version: '${{ matrix.php-version }}' + tools: 'composer:v1' + extensions: 'mbstring, intl' + + - name: 'Discover Composer cache directory' + id: 'cachedir' + run: 'echo "::set-output name=path::$(composer global config cache-dir)"' + + - name: 'Share Composer cache across runs' + uses: 'actions/cache@v2' + with: + path: '${{ steps.cachedir.outputs.path }}' + key: "composer-${{ matrix.php-version }}-${{ hashFiles('**/composer.json') }}" + restore-keys: | + composer-${{ matrix.php-version }}- + composer- + + - name: 'Install dependencies with Composer' + run: 'composer install --prefer-dist --no-interaction' + + - name: 'Run PHPUnit with coverage' + run: 'vendor/bin/phpunit --coverage-clover=clover.xml' + + - name: Check test coverage + id: test-coverage + uses: johanvanhelden/gha-clover-test-coverage-check@v1 + with: + percentage: '85' + filename: 'clover.xml' + + - name: 'Export coverage results' + uses: 'codecov/codecov-action@v1' + with: + file: './clover.xml' + env_vars: PHP_VERSION + + - name: 'Archive code coverage results' + uses: 'actions/upload-artifact@v2' + with: + name: 'PHP ${{ matrix.php }}' + path: 'clover.xml' diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b62b493..0000000 --- a/.travis.yml +++ /dev/null @@ -1,50 +0,0 @@ -sudo: required - -services: - - docker - -language: php - -env: - global: - - BEDITA_API_KEY=12345 - - BEDITA_API=http://127.0.0.1:8080 - - BEDITA_ADMIN_USR=admin - - BEDITA_ADMIN_PWD=admin - - BEDITA_IMAGE=bedita/bedita:4.1.0 - -before_install: - # Use GitHub OAuth token with Composer to increase API limits. - - if [ -n "$GH_TOKEN" ]; then composer config github-oauth.github.com ${GH_TOKEN}; fi - - docker pull ${BEDITA_IMAGE} - - docker run -d -p 127.0.0.1:8080:80 --env BEDITA_API_KEY=${BEDITA_API_KEY} --env BEDITA_ADMIN_USR=${BEDITA_ADMIN_USR} --env BEDITA_ADMIN_PWD=${BEDITA_ADMIN_PWD} ${BEDITA_IMAGE} - - sleep 10 - - docker ps -a - -install: - # Install Composer dependencies. - - composer install --prefer-dist --no-interaction - -script: - # Run PHPUnit with coverage. - - vendor/bin/phpunit --coverage-clover=clover.xml - -after_success: - # Upload coverage report to CodeCov.io - - bash <(curl -s https://codecov.io/bash) - -jobs: - fast_finish: true - - include: - - php: 7.2 - - php: 7.3 - - php: 7.4 - - php: 7.2 - env: "RUN=phpcs" - before_install: skip - script: | - vendor/bin/phpcs -n -p --extensions=php \ - --standard=vendor/cakephp/cakephp-codesniffer/CakePHP --ignore=/Migrations/,/Seeds/ \ - ./config ./src ./tests - after_success: skip diff --git a/README.md b/README.md index d891ac4..3e7e83b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # BEdita/WebTools plugin for CakePHP web apps using BEdita 4 API -[![Build Status](https://travis-ci.com/bedita/web-tools.svg?branch=master)](https://travis-ci.com/bedita/web-tools) +[![Github Actions](https://github.com/bedita/dev-tools/workflows/php/badge.svg)](https://github.com/bedita/dev-tools/actions?query=workflow%3Aphp) [![codecov](https://codecov.io/gh/bedita/web-tools/branch/master/graph/badge.svg)](https://codecov.io/gh/bedita/web-tools) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/bedita/web-tools/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/bedita/web-tools/?branch=master) [![image](https://img.shields.io/packagist/v/bedita/web-tools.svg?label=stable)](https://packagist.org/packages/bedita/web-tools)