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 CI for testing and code review standards #14

Merged
merged 8 commits into from
Feb 1, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .distignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Exclude directories from WP.org
.git
.github
.wordpress-org
node_modules
vendor
tests

# Exclude files from WP.org
.distignore
.editorconfig
.eslintignore
.eslint.json
.gitattributes
.gitignore
.markdownlint.json
.markdownlintignore
.stylelintignore
.stylelintrc.json
composer.json
composer.lock
package-lock.json
package.json
phpcompat.xml
phpcs.xml
phpmd.xml
phpstan.neon
README.md
25 changes: 25 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

# WordPress Coding Standards
# https://make.wordpress.org/core/handbook/coding-standards/

root = true

[*]
charset = utf-8
indent_style = tab
indent_size = 4
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.yml]
indent_style = space
indent_size = 2

[*.txt]
end_of_line = crlf
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.min.js
/assets/lib/
/node_modules/
/vendor/
12 changes: 12 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": [
"plugin:@wordpress/eslint-plugin/es5"
],
"globals": {
"jQuery": true,
"console": true
},
"rules": {
"no-console": "off"
}
}
27 changes: 27 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Exclude directories from export
/.github/ export-ignore
/.wordpress-org/ export-ignore
/node_modules/ export-ignore
/vendor/ export-ignore
/tests/ export-ignore

# Exclude files from export
/.distignore export-ignore
/.editorconfig export-ignore
/.eslintignore export-ignore
/.eslint.json export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.markdownlint.json export-ignore
/.markdownlintignore export-ignore
/.stylelintignore export-ignore
/.stylelintrc.json export-ignore
/composer.json export-ignore
/composer.lock export-ignore
/package-lock.json export-ignore
/package.json export-ignore
/phpcompat.xml export-ignore
/phpcs.xml export-ignore
/phpmd.xml export-ignore
/phpstan.neon export-ignore
/README.md export-ignore
33 changes: 33 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Dependabot set up for three package managers: GitHub Actions, npm and Composer.
# Documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:

# Maintain dependencies for GitHub Actions.
- package-ecosystem: "github-actions"
# Files stored in repository root.
directory: "/"
schedule:
# Check for updates every weekday.
interval: "daily"
open-pull-requests-limit: 10

# Maintain dependencies for npm.
- package-ecosystem: "npm"
# Files stored in repository root.
directory: "/"
schedule:
# Check for updates every weekday.
interval: "daily"
open-pull-requests-limit: 10

# Maintain dependencies for Composer.
- package-ecosystem: "composer"
# Files stored in repository root.
directory: "/"
schedule:
# Check for updates every weekday.
interval: "daily"
open-pull-requests-limit: 10
127 changes: 127 additions & 0 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: Coding Standards

on:
push:
branches: [ master, dev ]
pull_request:
branches: [ master, dev ]
paths:
# Any change to a PHP, JavaScript, CSS/SCSS or Markdown file should run checks.
- '**.js'
- '**.php'
- '**.*css'
- '**.md'
# These files configure NPM. Changes could affect the outcome.
- 'package*.json'
# These files configure Composer. Changes could affect the outcome.
- 'composer.*'
# This file configures ESLint. Changes could affect the outcome.
- '.eslintrc.json'
# This file configures Stylelint. Changes could affect the outcome.
- '.stylelintrc.json'
# This file configures Markdownlint. Changes could affect the outcome.
- '.markdownlint.json'
# This file configures PHPCS. Changes could affect the outcome.
- 'phpcs.xml'
# Changes to workflow files should always verify all workflows are successful.
- '.github/workflows/*.yml'
# Allows you to run this workflow manually from the Actions tab.
workflow_dispatch:

jobs:
# Runs PHP coding standards checks.
#
# Violations are reported inline with annotations.
#
# Performs the following steps:
# - Checks out the repository.
# - Sets up PHP.
# - Logs debug information.
# - Installs Composer dependencies (use cache if possible).
# - Make Composer packages available globally.
# - Logs PHP_CodeSniffer debug information.
# - Runs PHPCS on the full codebase.
phpcs:
name: PHP coding standards
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/[email protected]

- name: Set up PHP
uses: shivammathur/[email protected]
with:
php-version: '7.4' # Results are the same across all versions, check only in the last stable version.
coverage: none
tools: cs2pr
env:
fail-fast: false

- name: Log debug information
run: |
php --version
composer --version

- name: Check syntax error in sources
run: find -L . -path ./vendor -prune -o -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Install Composer dependencies
uses: ramsey/composer-install@v1

- name: Make Composer packages available globally
run: echo "${PWD}/vendor/bin" >> $GITHUB_PATH

- name: Log PHPCS debug information
run: composer phpcs-i

- name: Run the PHP code sniffer
continue-on-error: true
run: phpcs --report-full --report-checkstyle=./phpcs-report.xml

- name: Show PHPCS results in PR
run: cs2pr ./phpcs-report.xml

# Runs the JavaScript, CSS/SCSS and Markdown coding standards checks.
#
# JS and CSS violations are not currently reported inline with annotations.
#
# Performs the following steps:
# - Checks out the repository.
# - Installs NodeJS 16 with caching for NPM.
# - Logs updated debug information.
# _ Installs NPM dependencies using install-changed to hash the `package.json` file.
# - Run the WordPress ESLint, Stylelint and Markdownlint checks.
js-css-md-cs:
name: JS, CSS/SCSS and MD coding standards
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/[email protected]

- name: Setup Node
uses: actions/[email protected]
with:
node-version: 16
cache: npm

- name: Log debug information
run: |
npm --version
node --version

- name: Install Dependencies
run: npm ci

- name: Run JavaScript Lint
run: npm run lint:js

- name: Run CSS/SCSS Lint
run: npm run lint:css

- name: Run Markdown Lint
run: npm run lint:md:docs
63 changes: 63 additions & 0 deletions .github/workflows/php-compatibility.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: PHP Compatibility

on:
push:
branches: [ master, dev ]
pull_request:
branches: [ master, dev ]
paths:
# Any change to a PHP file should run checks.
- '**.php'
# These files configure Composer. Changes could affect the outcome.
- 'composer.*'
# This file configures PHP Compatibility. Changes could affect the outcome.
- 'phpcompat.xml'
# Changes to workflow files should always verify all workflows are successful.
- '.github/workflows/*.yml'
# Allows you to run this workflow manually from the Actions tab.
workflow_dispatch:

jobs:
# Runs PHP compatibility check.
#
# Violations are reported inline with annotations.
#
# Performs the following steps:
# - Checks out the repository.
# - Sets up PHP.
# - Logs debug information about the runner container.
# - Installs Composer dependencies (use cache if possible).
# - Logs PHP_CodeSniffer debug information.
# - Runs the PHP compatibility tests.
php-compatibility:
name: Check PHP compatibility
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/[email protected]

- name: Set up PHP
uses: shivammathur/[email protected]
with:
php-version: '7.4' # Results are the same across all versions, check only in the last stable version.
coverage: none
env:
fail-fast: false

- name: Log debug information
run: |
php --version
composer --version

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Install Composer dependencies
uses: ramsey/composer-install@v1

- name: Log PHPCS debug information
run: composer phpcs-i

- name: Run PHP compatibility tests
run: composer compat:php
69 changes: 69 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Static Analysis

on:
push:
branches: [ master, dev ]
pull_request:
branches: [ master, dev ]
paths:
# Any change to a PHP file should run checks.
- '**.php'
# These files configure Composer. Changes could affect the outcome.
- 'composer.*'
# This file configures PHPStan. Changes could affect the outcome.
- 'phpstan.neon'
# Changes to workflow files should always verify all workflows are successful.
- '.github/workflows/*.yml'
# Allows you to run this workflow manually from the Actions tab.
workflow_dispatch:

jobs:
# Runs PHPStan Static Analysis.
#
# Violations are reported inline with annotations.
#
# Performs the following steps:
# - Checks out the repository.
# - Sets up PHP.
# - Logs debug information.
# - Installs Composer dependencies (use cache if possible).
# - Make Composer packages available globally.
# - Runs PHPStan on the full codebase.
phpstan:
name: Static Analysis (PHP ${{ matrix.php-versions }})
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1'] # 5.6 and 7.0 not supported by PHPStan, 7.1 not supported by a PHPMD dependency.

steps:
- name: Checkout repository
uses: actions/[email protected]

- name: Set up PHP
uses: shivammathur/[email protected]
with:
php-version: ${{ matrix.php-versions }}
coverage: none
tools: cs2pr, phpstan
env:
fail-fast: false

- name: Log debug information
run: |
php --version
composer --version

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Install Composer dependencies
uses: ramsey/composer-install@v1

- name: Make Composer packages available globally
run: echo "${PWD}/vendor/bin" >> $GITHUB_PATH

- name: Run PHPStan static analysis (PHP ${{ matrix.php-versions }})
run: phpstan analyse -c phpstan.neon --error-format=checkstyle --memory-limit=1G | cs2pr
Loading