Giter VIP home page Giter VIP logo

action-phpcs-code-review's Introduction

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@v2
      with:
        ref: ${{ github.event.pull_request.head.sha }}
    - name: Run PHPCS inspection
      uses: rtCamp/[email protected]
      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 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

If your git repo have 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.

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

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

action-phpcs-code-review's People

Contributors

kirtangajjar avatar maitreyie-chavan avatar mbtamuli avatar mikemarschall avatar mrrobot47 avatar patelutkarsh avatar pradeep910 avatar rahul286 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.