Add GitHub workflow 'test'

Runs `composer install` and `phpcs` on basically every push, replaces Travis CI.
This commit is contained in:
Daniel Rudolf 2022-02-13 15:13:10 +01:00
parent e33f6c8148
commit 68c47429ef
No known key found for this signature in database
GPG key ID: A061F02CD8DE4538

98
.github/workflows/test.yml vendored Normal file
View file

@ -0,0 +1,98 @@
name: Test Pico CMS
on:
push:
branches:
- master
- pico-3.0
tags: [ 'v*.*.*' ]
pull_request:
branches:
- master
- pico-3.0
jobs:
test:
name: PHP ${{ matrix.PHP_VERSION }}
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
matrix:
PHP_VERSION:
- '7.2'
- '7.3'
- '7.4'
- '8.0'
- '8.1'
- 'nightly'
fail-fast: false
continue-on-error: ${{ matrix.PHP_VERSION == 'nightly' }}
env:
PHP_VERSION: ${{ matrix.PHP_VERSION }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup PHP ${{ env.PHP_VERSION }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.PHP_VERSION }}
tools: composer, phpcs
- name: Read Pico version
run: |
PICO_VERSION="$(php -r 'require("./lib/Pico.php"); echo Pico::VERSION;')"
echo "PICO_VERSION=$PICO_VERSION" | tee -a "$GITHUB_ENV"
- name: Setup Composer
if: ${{ github.ref_type == 'branch' }}
run: |
COMPOSER_ROOT_VERSION=
COMPOSER_BRANCH_ALIAS="$(php -r "
\$json = json_decode(file_get_contents('./composer.json'), true);
if (\$json !== null) {
if (isset(\$json['extra']['branch-alias']['dev-$GITHUB_REF_NAME'])) {
echo 'dev-$GITHUB_REF_NAME';
}
}
")"
if [ -z "$COMPOSER_BRANCH_ALIAS" ]; then
PICO_VERSION_PATTERN="$(php -r "
require_once('./lib/Pico.php');
echo preg_replace('/\.[0-9]+-dev$/', '.x-dev', Pico::VERSION);
")"
fi
if [ -n "$PICO_VERSION_PATTERN" ]; then
COMPOSER_ROOT_VERSION="$PICO_VERSION_PATTERN"
echo "COMPOSER_ROOT_VERSION=$COMPOSER_ROOT_VERSION" | tee -a "$GITHUB_ENV"
fi
- name: Get Composer cache directory
run: |
COMPOSER_CACHE_DIR="$(composer config cache-dir)"
echo "COMPOSER_CACHE_DIR=$COMPOSER_CACHE_DIR" | tee -a "$GITHUB_ENV"
- name: Restore Composer cache
uses: actions/cache@v2
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: ${{ runner.os }}-composer-php${{ matrix.PHP_VERSION }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install Composer dependencies
run: |
composer install
- name: Run PHP_CodeSniffer
run: |
phpcs --standard=.phpcs.xml