Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linting GitHub Action workflows #20

Merged
merged 7 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/eslint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: JS Linting

on:
push:
branches:
- develop
- trunk
paths:
- '**.js'
pull_request:
branches:
- develop
paths:
- '**.js'

jobs:
eslint:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup node and npm cache
uses: actions/setup-node@v3
with:
node-version-file: .nvmrc
cache: npm

- name: Install Node dependencies
run: npm ci --omit=optional --force # Using force here to get the proper version of eslint-plugin-prettier installed, as the version @10up/eslint-config requires has a bug.

- name: Get updated JS files
id: changed-files
uses: tj-actions/changed-files@v39
with:
files: |
**/*.js

- name: Run JS linting
if: ${{ steps.changed-files.outputs.any_changed == 'true' }}
run: |
npx 10up-toolkit lint-js ${{ steps.changed-files.outputs.all_changed_files }}
54 changes: 54 additions & 0 deletions .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: PHP Linting

on:
push:
branches:
- develop
- trunk
paths:
- '**.php'
pull_request:
branches:
- develop
paths:
- '**.php'

jobs:
phpcs:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup proper PHP version
uses: shivammathur/setup-php@v2
with:
php-version: 7.4

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v39
with:
files: |
**/*.php

- name: Install dependencies
run: composer install --prefer-dist

- name: Run PHP_CodeSniffer
run: |
HEAD_REF=$(git rev-parse HEAD)
git checkout $HEAD_REF
./vendor/bin/phpcs-changed -s --git --git-base origin/${{ github.base_ref }} ${{ steps.changed-files.outputs.all_changed_files }}
9 changes: 6 additions & 3 deletions autoload.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php
/**
* Autoloader for the Block Catalog plugin.
*
* @package BlockCatalog
*/

namespace BlockCatalog;

Expand Down Expand Up @@ -111,9 +116,7 @@ protected function load_mapped_file( $prefix, $relative_class ) {
// replace the namespace prefix with the base directory,
// replace namespace separators with directory separators
// in the relative class name, append with .php
$file = $base_dir
. str_replace( '\\', '/', $relative_class )
. '.php';
$file = $base_dir . str_replace( '\\', '/', $relative_class ) . '.php';

// if the mapped file exists, require it
if ( $this->require_file( $file ) ) {
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"10up/phpcs-composer": "dev-master",
"squizlabs/php_codesniffer": "~3.7.1",
"yoast/phpunit-polyfills": "^1.0",
"phpunit/phpunit": "~7.5.0"
"phpunit/phpunit": "~7.5.0",
"sirbrillig/phpcs-changed": "^2.11"
},
"autoload": {
"psr-4": {
Expand Down
58 changes: 56 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.