• Stars
    star
    101
  • Rank 338,166 (Top 7 %)
  • Language
    Shell
  • License
    MIT License
  • Created over 5 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Github Action to perform automated code review on pull requests

This action is a part of GitHub Actions Library created by rtCamp.

PHPCS Code Review - GitHub Action

Project Status: Active – The project has reached a stable, usable state and is being actively developed.

A GitHub Action to perform automated pull request review. It is based on https://github.com/Automattic/vip-go-ci/ but can be used for any WordPress or even PHP projects.

The code review is performed using PHPCS.

Please note that, this action performs pull request review only. If you have an existing project, and you want entire project's code to be reviwed, you may need to do it manually.

Usage

  1. Create a .github/workflows/phpcs.yml in your GitHub repo, if one doesn't exist already.
  2. Add the following code to the phpcs.yml file.
on: pull_request

name: Inspections
jobs:
  runPHPCSInspection:
    name: Run PHPCS inspection
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
      with:
        ref: ${{ github.event.pull_request.head.sha }}
    - name: Run PHPCS inspection
      uses: rtCamp/action-phpcs-code-review@v3
      env:
        GH_BOT_TOKEN: ${{ secrets.GH_BOT_TOKEN }}
        SKIP_FOLDERS: "tests,.github"
        PHPCS_SNIFFS_EXCLUDE: "WordPress.Files.FileName"
      with:
        args: "WordPress,WordPress-Core,WordPress-Docs"
  1. Define GH_BOT_TOKEN using GitHub Action's Secret. See GitHub Token Creation section for more details.

Now, next time you create a pull request or commit on an existing pull request, this action will run.

By default, pull request will be reviwed using WordPress coding and documentation standards. You can change the default by passing different PHPCS Coding Standard(s) in line args = ["WordPress-Core,WordPress-Docs"].

  1. In case you want to skip PHPCS scanning in any pull request, add [do-not-scan] in the PR description. You can add it anywhere in the description and it will skip the action run for that pull request.

  2. In case you want to skip linting all files on every pull request, set PHP_LINT to false.

GitHub Token Creation

You can create GitHub Token from here.

It is necessary that you create this token from a bot user account. Please note that the bot account should have access to the repo in which action is being run, in case it is a private repo. It is compulsory to use a bot account because in GitHub it is forbidden to request changes on your own Pull Request by your own user. Additional benefit of using a bot account is that in a large team, if you use your human account token, you may get flooded with unncessary Github notifications.

Permissions required for this token differ according to which type of repo this workflow has been setup for.

Repo Type Permissions Required Screenshots
Public Under Repo section, only public_repo permission Screenshot Public Repo
Private Complete repo and write:discussion permissions Screenshot Private Repo

Environment Variables

Variable Default Possible Values Purpose
SKIP_FOLDERS - tests,tests,.github (Any other comma seprated top level directories in the repo) If any specific folders should be ignored when scanning, then a comma seprated list of values should be added to this env variable.
PHPCS_SNIFFS_EXCLUDE - WordPress.Files.FileName (Any other comma seprated list of valid sniffs) Single sniff or comma seprated list of sniffs to be excluded from the phpcs scan.
PHP_LINT true true or false, case insensitive (Any unknown value is the same as passing true) If the default automatic linting of all PHP files should be deactivated, then this env variable should be set to false.
PHPCS_STANDARD_FILE_NAME - phpcs ruleset file from project root dir. i.e phpcs.ruleset.xml PHP_CodeSniffer ruleset filename. Default filename available: '.phpcs.xml', 'phpcs.xml', '.phpcs.xml.dist', 'phpcs.xml.dist'
PHPCS_FILE_PATH - Custom phpcs execution file path from project. i.e Composer phpcs path. 'vendor/bin/phpcs' This is useful in case of needed to use any custom coding standards apart from pre-defined in VIP/WP Coding Standards. Wiki
SKIP_DRAFT_PRS false true/false Set it to true to skip PHPCS checks on draft PRs.
PHPCS_PHP_VERSION 8.1 7.4, 8.0, 8.1, or 8.2 To use a different PHP interpreter than the system default.

Modifying the bot’s behavior

You can change the bot’s behavior by placing a configuration file named .vipgoci_options at the root of the relevant repository. This file must contain a valid JSON string for this to work; if the file is not parsable, it will be ignored. This file is where you can add code to turn off support messages as well as adjust PHPCS severity levels.

i.e: You can update phpcs severity:

{
  "phpcs-severity": 5
}

Allowed options:

  • "skip-execution"
  • "skip-draft-prs"
  • "results-comments-sort"
  • "review-comments-include-severity"
  • "phpcs"
  • "phpcs-severity"
  • "post-generic-pr-support-comments"
  • "phpcs-sniffs-include"
  • "phpcs-sniffs-exclude"
  • "hashes-api"
  • "svg-checks"
  • "autoapprove"
  • "autoapprove-php-nonfunctional-changes

For more details please check the documentation for all options here.

Skipping PHPCS scanning for specific folders

You can add files to the root of the repository indicating folders that should not be scanned. For PHPCS, the file should be named .vipgoci_phpcs_skip_folders. For PHP Linting the file should be named .vipgoci_lint_skip_folders. Please ensure both files are located in the root of the repository.

This can be used as an alternate to SKIP_FOLDERS env variable.

Please note that the folders exlcuded in the PHPCS xml file do not work in this action, you can check the reason here. Instead you should add all the folders to be excluded in either SKIP_FOLDERS env or .vipgoci_phpcs_skip_folders file.

List each folder to be skipped on individual lines within those files.

i.e:

foo
tests/bar
vendor
node_modules

For more details, please check the documentation here.

PHPCS Coding Standards

Below is list of PHPCS sniffs available at runtime. You can pass more than one standard at a time by comma separated value.

By default, WordPress-Core,WordPress-Docs value is passed.

  • MySource
  • PEAR
  • PHPCompatibility
  • PHPCompatibilityParagonieRandomCompat
  • PHPCompatibilityParagonieSodiumCompat
  • PHPCompatibilityWP
  • PSR1
  • PSR12
  • PSR2
  • Squiz
  • WordPress (default)
  • WordPress-Core (default)
  • WordPress-Docs (default)
  • WordPress-Extra
  • WordPress-VIP
  • WordPress-VIP-Go
  • WordPressVIPMinimum
  • Zend

Custom Sniffs

Default filename supported:

  • .phpcs.xml
  • phpcs.xml
  • .phpcs.xml.dist
  • phpcs.xml.dist

If your git repo has a file named phpcs.xml in the root of the repository, then that will take precedence. In that case, value passed to args such as args = ["WordPress,WordPress-Core,WordPress-Docs"] will be ignored.

If your git repo doesn't have phpcs.xml and you do not specify args in main.workflow PHPCS action, then this actions will fallback to default.

If your git repo has phpcs ruleset file other than default filename list, use PHPCS_STANDARD_FILE_NAME environment var to provide filename.

Here is a sample phpcs.xml you can use in case you want to use custom sniffs.

Custom Coding Standards

If you have custom coding standards from your git repository, you can use composer and use phpcs from execution from your repository phpcs file with the help of PHPCS_FILE_PATH environment variable. Please refer this wiki page for more information.

Screenshot

Automated Code Review in action

Automated PHPCS Code Review

Limitations

Please note...

  1. This action runs only for PRs. It even runs on new commits pushed after a PR is created.
  2. This action doesn't run on code in the repository added before this action.
  3. This action doesn't run for code committed directly to a branch. We highly recommend that you disable direct commits to your main/master branch.

License

MIT Β© 2019 rtCamp

Does this interest you?

Join us at rtCamp, we specialize in providing high performance enterprise WordPress solutions

More Repositories

1

action-slack-notify

GitHub Action for sending a notification to a Slack channel
Go
1,071
star
2

wp-decoupled

Next.js app with WPGraphQL and WordPress at the backend.
JavaScript
267
star
3

nginx-helper

Nginx Helper for WordPress caching, permalinks & efficient file handling in multisite
PHP
229
star
4

VueTheme

WordPress theme using Rest API and Vue.js
CSS
220
star
5

gutenberg-fields-middleware

Register fields for Gutenberg blocks with less repetitive code
JavaScript
167
star
6

rtMedia

rtMedia (formerly Buddypress Media) adds advanced multimedia functionality to WordPress, BuddyPress and bbPress
PHP
121
star
7

action-deploy-wordpress

GitHub Action for deploying a WordPress site using using PHP's Deployer.org
Shell
120
star
8

Frappe-Manager

A CLI tool based on Docker Compose to easily manage Frappe based projects.
Python
111
star
9

github-actions-library

Collection of Github Actions useful for WordPress Deployments
93
star
10

wp-partytown

Add partytown support to WordPress sites.
JavaScript
75
star
11

login-with-google

Minimal plugin which allows WordPress user to login with google.
PHP
62
star
12

learn

rtCamp assignment and issue tracker
51
star
13

rtpanel

WordPress Theme Framework
PHP
43
star
14

gitbook-plugin-edit-link

GitBook Plugin to add "Edit with Github (or Gitlab)" link on every page
JavaScript
42
star
15

wordpress-skeleton

A base repository structure for rtCamp's WordPress sites, pre-configured to use Github Actions
PHP
41
star
16

gutenberg-supplements

JavaScript
28
star
17

rtsocial

rtSocial is lightest wordpress plugin for facebook & twitter social sharing
PHP
26
star
18

theme-elementary

A starter theme that facilitates a quick headstart for developing new block-based themes along with a bunch of developer-friendly features.
JavaScript
26
star
19

wpveda-book

We now have our own training module which has all the lessons that covers the core topics on WordPress and the various steps involved in WordPress development. Check it out
Shell
25
star
20

blank-theme

Customized Blank theme based on Underscore and Foundation
PHP
25
star
21

gitbook-plugin-collapsible-menu

GitBook Plugin to change sidebar menu's to collapsible menu. For gitbook with many pages, navigating long menus can get irritating.
JavaScript
24
star
22

woocommerce-to-easydigitaldownloads

A script to migrate products, orders, payments and other stuff from WooCommerce to EasyDigitalDownloads
PHP
21
star
23

rt-optimizer

A WordPress plugin that improves Core Web Vitals score by loading scripts via worker thread. Keeps the main thread idle for users to interact with page as quickly as possible.
PHP
19
star
24

rtpanel-child-theme

Example child theme for rtPanel wordpress theme framework
CSS
16
star
25

rtbiz

WordPress 4 Business!
PHP
16
star
26

web-story-creation-tool

Demo https://rtcamp.github.io/web-story-creation-tool
JavaScript
16
star
27

wp-menu-custom-fields

An example of custom fields for menu in WordPress 5.4+
TypeScript
16
star
28

woobench-woocommerce-load-testing

WooCommerce Benchmarking
Python
14
star
29

gitlab-to-github-migration

Migrate GitLab project to GitHub
PHP
12
star
30

rt-lib

rt-lib is (intended to be) collection of reusable PHP classes useful for WordPress plugin/theme projects
PHP
12
star
31

transcoder

This WordPress plugin, useful to transcode audio and video file from any format to mp3 and mp4 respectively. Also it will generate thumbnails of videos.
PHP
10
star
32

action-phpcs-inspection

GitHub Action for PHPCS inspection.
Dockerfile
10
star
33

rt-newrelic-browser

NewRelic Browser Monitoring (Real User Monitoring) WordPress
PHP
10
star
34

wordpress-preview-revisions

WordPress Preview Revisions Plugin help editors to preview the revisions with exact same content that would look like on the frontend.
PHP
9
star
35

wp-plugin-bootstrap

A skeleton wordpress plugin to bootstrap & standardize your development
Shell
9
star
36

rtsyntax

A lightweight syntax highlighter for WordPress
CSS
9
star
37

visual-automation-backstop

Visual automation with Backstop JS
JavaScript
9
star
38

media-node

A node.js wrapper for ffmpeg. Made for https://github.com/rtCamp/buddypress-media but can be used in any project which needs FFMPEG
Shell
9
star
39

docs.rtcamp.com

Documentation for rtCamp projects/products
CSS
8
star
40

gutenberg-plugin-boilerplate

Simple Gutenberg Boilerplate for plugin development
JavaScript
8
star
41

search-with-google

A plugin for replacing WordPress default search with Google Custom Search results.
TypeScript
8
star
42

ninja-to-gravity

PHP
7
star
43

pwa-wordpress-plugin

WordPress Plugin to enable PWA features.
PHP
7
star
44

httperf

httperf clone with fix for FD_SETSIZE (open file limit)
C
7
star
45

amp-admanager

Easy and hassle free Google Admanager amp-ad tags integration for all WordPress sites. (AMP and Non-AMP)
PHP
5
star
46

rtpanel-hooks-editor

rtPanel hooks editor plugin provides user-interface for rtPanel WordPress Theme Framework
PHP
5
star
47

my-comment-manager

Better comment management for wordpress
PHP
5
star
48

action-wordpress-org-plugin-deploy

Shell
4
star
49

web-stories-ad-tool

Ad creation tool for google web stories. https://rtcamp.github.io/web-stories-ad-tool
JavaScript
4
star
50

automate-slack-invite-gravityforms

GravityForms addon to invite a user on Slack automatically
PHP
4
star
51

blogger-to-wordpress

Blogger to WordPress Redirection Plugin
TypeScript
4
star
52

rtmedia-code-snippets

This is custom code library for rtMedia core and premium add-ons
PHP
4
star
53

gitlab-bulk-delete-users

Delete users in bulk from Gitlab setup using rake tasks
Ruby
4
star
54

wporg-api-client

WordPress.org API client built in node.js
JavaScript
3
star
55

dockerfiles

Various Dockerfiles in use by rtCamp.
Dockerfile
3
star
56

amp-onesignal-compat

A WordPress Plugin to add AMP compatibility to OneSignal – Web Push Notifications
PHP
3
star
57

pwa-extension

Enables PWA features such as add to homescreen, offline reading features.
PHP
3
star
58

api_playwright_utils

API Automation Testing with Playwright
JavaScript
3
star
59

frappe-dev-tools

App for frappe devs to go πŸš€
Python
3
star
60

integrate-woocommerce-gitlab

With this code users can connect GitLab to WooCommerce, users will get source code repositories access as a Guest, Reporter, Developer or Master
PHP
3
star
61

wp-cli-report-command

Lists the plugin and theme usage for a multisite
PHP
2
star
62

wercker-step-wordpress-svn

Wercker deploy step for wordpress.org plugin svn repo
Shell
2
star
63

rtbiz-helpdesk

PHP
2
star
64

migrate-wufoo-to-gravity-forms

Import content from wufoo to Gravity Form- Entries, Comments and attachments.
PHP
2
star
65

blocks-bento-variations

PHP
2
star
66

px-wp-insights

AMP Compatibility Database
JavaScript
2
star
67

amp-generic-compat

AMP plugin to provide generic compatibility for Elements with hide and show toggle feature
PHP
2
star
68

rtWidgets

Sidebar Widgets Collection for rtPanel Theme Framework mainly. Might work on other theme as well.
PHP
2
star
69

embed-google-drive

TypeScript
2
star
70

rtmoto

rtMoto Theme
PHP
2
star
71

mention-links

Plugin which brings Github style user @mentions and article #links to the WordPress
TypeScript
2
star
72

stripe-xero-csv

Export Stripe's balance affecting transactions in a CSV file, recognisable by Xero Import CSV Statement feature.
PHP
2
star
73

action-deploy-frappe

Shell
2
star
74

edit-flow-slack-integration

This plugin is to send slack notification when editotial comment added.
PHP
1
star
75

lando-wordpress-skeleton

PHP
1
star
76

action-deploy-on-managed-instance

Shell
1
star
77

amp-infinite-scroll

AMP plugin for infinite scroll
PHP
1
star
78

web-stories-playground

JavaScript
1
star
79

rtAdmin

PHP-CLI nginx vhost creation script. Succeeded by https://github.com/rtCamp/easyengine
PHP
1
star
80

rtAntiSpam

WordPress login/register sidebar widget with recaptcha support
PHP
1
star
81

wp-cls-terminator

Remove CLS from Block Editor Embeds
JavaScript
1
star
82

rt-google-analytics-scroll-tracking

Integrates jquery-scrolldepth with Google Analytics by Yoast
JavaScript
1
star
83

amp-colormag-compat

Adds Compatibility to WordPress ColorMag theme.
PHP
1
star
84

gitolite-setup

Setup scripts for Gitolite v3
Shell
1
star
85

AMP-Extensions-Mini-Plugins

Monorepo contains different AMP extension plugins
PHP
1
star
86

psat-demos

EJS
1
star
87

rtmedia-transcoding-service-old

rtmedia Transcoding Plugin for rtMedia and WordPress Media Library
PHP
1
star
88

rt-react-theme

JavaScript
1
star
89

gravityforms-sfmc-data-extension

Gravity Forms add-on to send entry data to a Salesforce Marketing Cloud Data Extension
PHP
1
star
90

amp-email-subscribers

AMP compatibility for Email Subscribers & Newsletters – Simple and Effective Email Marketing WordPress Plugin by icegram
PHP
1
star