Skip to content

Commit

Permalink
Merge pull request #691 from westonruter/fix/linting
Browse files Browse the repository at this point in the history
Fix CI
  • Loading branch information
westonruter authored Mar 3, 2023
2 parents 21af0da + 3651a79 commit b42cac4
Show file tree
Hide file tree
Showing 14 changed files with 902 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab

[{.babelrc,.eslintrc,.rtlcssrc,*.json,*.yml}]
[{.babelrc,.eslintrc,.rtlcssrc,*.json,*.yml,*.yaml}]
indent_style = space
indent_size = 2

Expand Down
111 changes: 79 additions & 32 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,53 +1,100 @@
name: Continuous Integration
on:
pull_request:
push:
branches:
- actions-playground # TODO: Remove this after it works
- develop
- "*.*"
pull_request_target: ~

# Cancel previous workflow run groups that have not completed.
concurrency:
# Group workflow runs by workflow name, along with the head branch ref of the pull request
# or otherwise the branch or tag ref.
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
lint:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-18.04

lint-css:
name: 'Lint and Analyze'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node
uses: actions/[email protected]
with:
node-version-file: '.nvmrc'
cache: npm

- name: Install dependencies (Ubuntu)
if: runner.os == 'Linux'
run: |-
sudo apt-get update
sudo apt-get install -y libxml2-utils
- name: Install Node dependencies
run: npm ci
env:
CI: true

- name: Cache multiple paths
uses: actions/[email protected]
- name: Validate package.json
run: npm run lint:pkg-json

- name: Detect coding standard violations (stylelint)
run: npm run lint:css

- name: Detect ESLint coding standard violations
if: >
github.event.pull_request.head.repo.fork == true ||
github.event.pull_request.user.login == 'dependabot[bot]'
run: npm run lint:js

- name: Generate ESLint coding standard violations report
# Prevent generating the ESLint report if PR is from a fork or authored by Dependabot.
if: >
! ( github.event.pull_request.head.repo.fork == true ||
github.event.pull_request.user.login == 'dependabot[bot]' )
run: npm run lint:js:report
continue-on-error: true

- name: Annotate code linting results
# The action cannot annotate the PR when run from a PR fork or was authored by Dependabot.
if: >
! ( github.event.pull_request.head.repo.fork == true ||
github.event.pull_request.user.login == 'dependabot[bot]' )
uses: ataylorme/[email protected]
with:
path: |-
$HOME/.composer/cache
$HOME/.npm
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock', '**/package-lock.json') }}
repo-token: '${{ secrets.GITHUB_TOKEN }}'
report-json: 'lint-js-report.json'

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: '8.0'
extensions: dom, iconv, json, libxml, zip
coverage: none
tools: phpstan, cs2pr

- name: Setup Node
uses: actions/setup-node@v3
- name: Get Composer Cache Directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Configure Composer cache
uses: actions/[email protected]
with:
node-version: 14
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install Composer dependencies
run: composer install --prefer-dist --optimize-autoloader --no-progress --no-interaction

- name: Install Dependencies
run: |
npm install
composer install
- name: Validate composer.json
run: composer --no-interaction validate --no-check-all

- name: Build Plug-in
run: npm run build
- name: Detect coding standard violations (PHPCS)
run: vendor/bin/phpcs -q --report=checkstyle --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 | cs2pr --graceful-warnings

- name: Lint
run: npm run lint
- name: Normalize composer.json
run: composer --no-interaction normalize --dry-run

- name: Static Analysis (PHPStan)
run: |
phpstan --version
phpstan analyse
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
16 changes: 16 additions & 0 deletions .lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
"composer.*": [
() => "composer --no-interaction validate --no-check-all",
() => "npm run lint:composer"
],
"package.json": [
"npm run lint:pkg-json"
],
"**/*.js": [
"npm run lint:js"
],
"**/*.php": [
"npm run lint:php",
() => 'npm run lint:phpstan'
]
};
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Contributors: westonruter, allejo
Tags: block, code, code syntax, syntax highlight, code highlighting
Requires at least: 5.6
Tested up to: 6.1
Tested up to: 6.2
Stable tag: 1.3.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down
13 changes: 13 additions & 0 deletions bin/phpcbf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
# Wrap phpcbf to turn 1 success exit code into 0 code.
# See https://github.com/squizlabs/PHP_CodeSniffer/issues/1818#issuecomment-354420927

composer exec phpcbf $@
exit=$?

# Exit code 1 is used to indicate that all fixable errors were fixed correctly.
if [[ $exit == 1 ]]; then
exit=0
fi

exit $exit
25 changes: 24 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,40 @@
"scrivo/highlight.php": "v9.18.1.10"
},
"require-dev": {
"civicrm/composer-downloads-plugin": "^3.0",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0.0",
"php-stubs/wordpress-stubs": "^6.1",
"phpcompatibility/php-compatibility": "^9.1",
"wp-coding-standards/wpcs": "^2"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
"dealerdirect/phpcodesniffer-composer-installer": true,
"civicrm/composer-downloads-plugin": true
},
"platform": {
"php": "5.6"
},
"sort-packages": true
},
"extra": {
"downloads": {
"composer-normalize": {
"path": "vendor/bin/composer-normalize",
"type": "phar",
"url": "https://github.com/ergebnis/composer-normalize/releases/latest/download/composer-normalize.phar"
},
"phpstan": {
"path": "vendor/bin/phpstan",
"type": "phar",
"url": "https://github.com/phpstan/phpstan/releases/latest/download/phpstan.phar"
}
}
},
"scripts": {
"analyze": "if [ -z $TEST_SKIP_PHPSTAN ]; then phpstan --version; phpstan analyze --ansi; fi",
"normalize": "composer-normalize",
"phpcbf": "bin/phpcbf.sh",
"phpcs": "phpcs",
"zip": "git archive --format=zip HEAD > syntax-highlighting-code-block.zip && unzip -l syntax-highlighting-code-block.zip"
}
Expand Down
Loading

0 comments on commit b42cac4

Please sign in to comment.