From 68c47429ef6a0800ddf5ea22c76577a6e2993066 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Sun, 13 Feb 2022 15:13:10 +0100 Subject: [PATCH] Add GitHub workflow 'test' Runs `composer install` and `phpcs` on basically every push, replaces Travis CI. --- .github/workflows/test.yml | 98 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..59e8311 --- /dev/null +++ b/.github/workflows/test.yml @@ -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