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

Added CI workflow with a job to format the code on the PR #50

Merged
merged 13 commits into from
Feb 14, 2024
Merged
8 changes: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
parserOptions: {
parser: "@babel/eslint-parser",
requireConfigFile: false,
ecmaVersion: "latest",
},
extends: ["plugin:prettier/recommended"],
};
Empty file.
100 changes: 100 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Draw Attention CI workflow

on:
pull_request:

concurrency:
group: da-ci-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true

env:
EVENT: ${{ toJSON(github.event) }}

jobs:
# =====================================================================================#
# Run code through PHPCodeSniffer to conform to standards =============================#
# =====================================================================================#
# The installed coding standards are Zend, PEAR, PSR2, Squiz, PSR12, MySource, PSR1, PHPCompatibility, PHPCompatibilityParagonieRandomCompat, PHPCompatibilityParagonieSodiumCompat, PHPCompatibilityWP, WordPress, WordPress-Extra, WordPress-Core and WordPress-Docs
static-code-analysis:
name: Static Code Analysis
if: ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
env:
phpcs_config_flags: --standard=WordPress --ignore=vendor,node_modules,*min.* --extensions=php --runtime-set testVersion 7.2
steps:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.2
coverage: none

- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}

- name: Set git user information
run: |
git config --global user.email "otto@nsquared.io"
git config --global user.name "otto-bot-git"

- name: Prepare environment
run: |
composer init --name nsquared-team/draw-attention --no-interaction
composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer require --with-all-dependencies --dev dealerdirect/phpcodesniffer-composer-installer:"*" phpcompatibility/phpcompatibility-wp:"*"
composer require --with-all-dependencies --dev wp-coding-standards/wpcs
vendor/bin/phpcs --version
vendor/bin/phpcs -i
vendor/bin/phpcs --config-set colors 1

- name: Install dependencies
run: |
npm install
npm install -g prettier
npm install -g eslint

# =================================================================================================#
# Run code through PHPCodeSniffer to conform to standards ========================================#
# =================================================================================================#

- name: Fix code with PHP Code Sniffer
if: always()
continue-on-error: true
run: |
vendor/bin/phpcbf -p "." ${{ env.phpcs_config_flags }}

- name: Check any remaining errors with PHP Code Sniffer
if: always()
continue-on-error: true
run: |
vendor/bin/phpcs -p "." ${{ env.phpcs_config_flags }}

# =================================================================================================#
# Run code through Prettier and ESLint to conform to standards ====================================#
# =================================================================================================#

- name: Format JS files
run: prettier --write "**/*.js"

# No Vue files in this project at the moment
# - name: Format Vue files
# run: prettier --write "**/*.vue"

- name: Lint JS files
run: eslint --fix "**/*.js" --ignore-pattern "**/vendor/**/*" --ignore-pattern "**/node_modules/**/*" --ignore-pattern "**/*min.*"

# No Vue files in this project at the moment
# - name: Lint Vue files
# run: eslint --fix "**/*.vue" --ignore-pattern "**/vendor/**/*" --ignore-pattern "**/node_modules/**/*"

- name: Revert unwanted composer changes
run: |
git checkout composer.json
git checkout composer.lock

# The push below will not trigger a new workflow because it uses the default GITHUB_TOKEN
- name: Commit and push changes
run: |
# just a guard, we also should keep on excluding the minified files
git restore "*min.*"
`git add -A && git commit -m "Automated code formatting on branch done." > /dev/null && git push` || true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ wp-config.php
wp-content/plugins/akismet/.htaccess
public/assets/config.codekit3

vendor/
# Needed for WP release
node_modules/
release/
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*min.*
public/assets/js/leaflet.js
Loading
Loading