Using GitHub Actions

Continuing the discussion from Link to latest plugin release:

Splitting off the thread so we can share configs and chat about GitHub actions here :slight_smile:

2 Likes

Ok so heres our config:

.github/workflows/phpcs.yml

name: PHPCS Checks

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v1
    - name: Composer (php-actions)
      uses: php-actions/[email protected]
    - name: Run phpcs
      run: vendor/bin/phpcs

In the root of the project if you dont have one already you need a composer file to include php, phpcs and the wpcs rules:
composer.json

{
    "require": {
        "php": ">=5.3.2"
    },
    "require-dev": {
        "dealerdirect/phpcodesniffer-composer-installer": "*",
        "wp-coding-standards/wpcs": "*"
    }
}

Then lastly the phpcs config itself.

phpcs.xml

<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards">

	<rule ref="WordPress-Core">
		<exclude name="PEAR.Functions.FunctionCallSignature.MultipleArguments" />
		<exclude name="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket" />
		<exclude name="PEAR.Functions.FunctionCallSignature.CloseBracketLine" />
		<exclude name="WordPress.WP.CapitalPDangit.Misspelled" />
		<exclude name="WordPress.Files.FileName.InvalidClassFileName" />
		<exclude name="WordPress.PHP.StrictComparisons.LooseComparison" />
		<exclude name="WordPress.PHP.StrictInArray.MissingTrueStrict" />
	</rule>
	<file>.</file>
	<arg name="extensions" value="php"/>
	<arg name="parallel" value="20"/>
	<arg value="ps"/>
	<arg name="colors" />
	<arg value="sp" />
	<ini name="memory_limit" value="512M" />
	<config name="ignore_warnings_on_exit" value="1"/>
</ruleset>
4 Likes

Nice! Do you find you run through a lot of your minutes running on every push? Though I guess with PHPCS you would want to know prior to a PR.

We have an action to run our Laravel test suite on PRs to the master branch. Mainly because running on every push was eating up a ton of the minutes, even at an average of 29s :man_shrugging:

Ours takes about 80-100s to run, nowhere near the 3000m per month limit.

1 Like

This was a really good blog post about GitHub Actions: Using GitHub actions to run the tests of Laravel projects and packages - Freek Van der Herten's blog on PHP, Laravel and JavaScript

2 Likes