Skip to content

Merge pull request #31 from GaryJones/dependabot/composer/infection/i… #77

Merge pull request #31 from GaryJones/dependabot/composer/infection/i…

Merge pull request #31 from GaryJones/dependabot/composer/infection/i… #77

Workflow file for this run

name: CI for Plugin Boilerplate
on: [push]
# Cancel any in-progress runs for the same branch when a new push lands.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# Disable all permissions by default; grant minimal permissions per job.
permissions: {}
# wp-env mounts the working tree at wp-content/plugins/<basename>, so check out into
# a directory named to match the slug used in composer.json's "integration" script.
defaults:
run:
working-directory: plugin-slug
jobs:
lint:
name: Lint and code standards
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
path: plugin-slug
persist-credentials: false
- name: Setup PHP 8.4
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0
with:
php-version: '8.4'
coverage: none
tools: composer:v2
extensions: mbstring # Just enough to keep phpunit happy when installing Composer dependencies.
- name: Validate composer.json
run: composer validate --no-check-lock
- name: Install Composer dependencies
uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0
with:
working-directory: plugin-slug
composer-options: --prefer-dist --no-progress --no-suggest
# Needed as runs-on: system doesn't have xml-lint by default.
- name: Lint .phpcs.xml.dist
uses: ChristophWurst/xmllint-action@7c54ff113fc0f6d4588a15cb4dfe31b6ecca5212 # v1.2.1
with:
xml-file: ./plugin-slug/.phpcs.xml.dist
xml-schema-file: ./plugin-slug/vendor/squizlabs/php_codesniffer/phpcs.xsd
# Needed as runs-on: system doesn't have xml-lint by default.
- name: Lint phpunit.xml.dist
uses: ChristophWurst/xmllint-action@7c54ff113fc0f6d4588a15cb4dfe31b6ecca5212 # v1.2.1
with:
xml-file: ./plugin-slug/phpunit.xml.dist
xml-schema-file: ./plugin-slug/vendor/phpunit/phpunit/phpunit.xsd
- name: Lint PHP files
run: bin/php-lint
- name: Run PHPCS
run: composer cs
test:
name: WP ${{ matrix.wordpress }} on PHP ${{ matrix.php }}
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
fail-fast: false
matrix:
include:
# Lowest supported PHP with lowest supported WordPress.
- php: '8.4'
wordpress: '6.9'
# Latest supported PHP with the latest WordPress.
- php: '8.5'
wordpress: 'master'
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
path: plugin-slug
persist-credentials: false
- name: Setup Node.js (for wp-env)
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: 'lts/*'
- name: Cache npm registry for wp-env
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
with:
path: ~/.npm
key: ${{ runner.os }}-npm-wp-env-${{ hashFiles('plugin-slug/.wp-env.json') }}
restore-keys: |
${{ runner.os }}-npm-wp-env-
- name: Install wp-env
run: npm install -g @wordpress/env
- name: Setup PHP
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
php-version: ${{ matrix.php }}
coverage: pcov
tools: composer:v2
# https://make.wordpress.org/hosting/handbook/handbook/server-environment/#php-extensions
extensions: curl, dom, exif, fileinfo, hash, json, mbstring, mysqli, libsodium, openssl, pcre, imagick, xml, zip
- name: Install Composer dependencies
uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0
with:
working-directory: plugin-slug
composer-options: --prefer-dist --no-progress --no-suggest
- name: Setup Problem Matchers for PHPUnit
env:
RUNNER_TOOL_CACHE: ${{ runner.tool_cache }}
run: echo "::add-matcher::${RUNNER_TOOL_CACHE}/phpunit.json"
- name: Run unit tests
run: composer unit
- name: Run infection tests
run: composer infection
continue-on-error: true
- name: Start wp-env
run: wp-env start
env:
WP_ENV_CORE: WordPress/WordPress#${{ matrix.wordpress }}
WP_ENV_PHP_VERSION: ${{ matrix.php }}
- name: Run integration tests
run: composer integration