Skip to content

Commit 36eba5a

Browse files
authored
Merge pull request #51 from rtCamp/update-action
Updates for allowing options from vip-go-ci.
2 parents 0d95fef + c877b57 commit 36eba5a

2 files changed

Lines changed: 103 additions & 5 deletions

File tree

README.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,51 @@ Variable | Default | Possible Values | Purpose
6969
`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.
7070
`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.
7171
`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`.
72+
`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'
73+
`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.
74+
75+
## Modifying the bot’s behavior
76+
77+
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.
78+
79+
i.e: You can update phpcs severity:
80+
```json
81+
{
82+
"phpcs-severity": 5
83+
}
84+
```
85+
86+
Allowed options:
87+
- `"skip-execution"`
88+
- `"skip-draft-prs"`
89+
- `"results-comments-sort"`
90+
- `"review-comments-include-severity"`
91+
- `"phpcs"`
92+
- `"phpcs-severity"`
93+
- `"post-generic-pr-support-comments"`
94+
- `"phpcs-sniffs-include"`
95+
- `"phpcs-sniffs-exclude"`
96+
- `"hashes-api"`
97+
- `"svg-checks"`
98+
- `"autoapprove"`
99+
- `"autoapprove-php-nonfunctional-changes`
100+
101+
For more details please check the documentation for [all options here](https://github.com/automattic/vip-go-ci#configuration-via-repository-config-file).
102+
## Skipping PHPCS scanning for specific folders
103+
104+
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.
105+
106+
List each folder to be skipped on individual lines within those files.
107+
108+
i.e:
109+
```
110+
foo
111+
tests/bar
112+
vendor
113+
node_modules
114+
```
115+
116+
For more details, please check the documentation [here](https://github.com/automattic/vip-go-ci#skipping-certain-folders).
72117

73118
## PHPCS Coding Standards
74119

@@ -97,12 +142,24 @@ By default, `WordPress-Core,WordPress-Docs` value is passed.
97142

98143
### Custom Sniffs
99144

100-
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.
145+
Default filename supported:
146+
- `.phpcs.xml`
147+
- `phpcs.xml`
148+
- `.phpcs.xml.dist`
149+
- `phpcs.xml.dist`
150+
151+
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.
101152

102153
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.
103154

155+
If your git repo has phpcs ruleset file other than default filename list, use `PHPCS_STANDARD_FILE_NAME` environment var to provide filename.
156+
104157
Here is a sample [phpcs.xml](https://github.com/rtCamp/github-actions-wordpress-skeleton/blob/master/phpcs.xml) you can use in case you want to use custom sniffs.
105158

159+
### Custom Coding Standards
160+
161+
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.
162+
106163
## Screenshot
107164

108165
**Automated Code Review in action**

main.sh

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,19 @@ if [[ $phpcsfilefound -ne 0 ]]; then
6868
fi
6969
fi
7070

71+
if [[ -n "$PHPCS_STANDARD_FILE_NAME" ]] && [[ -f "$RTBOT_WORKSPACE/$PHPCS_STANDARD_FILE_NAME" ]]; then
72+
phpcs_standard="--phpcs-standard=$RTBOT_WORKSPACE/$PHPCS_STANDARD_FILE_NAME"
73+
fi;
74+
75+
if [[ -n "$PHPCS_FILE_PATH" ]] && [[ -f "$RTBOT_WORKSPACE/$PHPCS_FILE_PATH" ]]; then
76+
phpcs_file_path="--phpcs-path='$RTBOT_WORKSPACE/$PHPCS_FILE_PATH'"
77+
else
78+
phpcs_file_path="--phpcs-path='/home/rtbot/vip-go-ci-tools/phpcs/bin/phpcs'"
79+
fi
80+
7181
[[ -z "$PHPCS_SNIFFS_EXCLUDE" ]] && phpcs_sniffs_exclude='' || phpcs_sniffs_exclude="--phpcs-sniffs-exclude='$PHPCS_SNIFFS_EXCLUDE'"
7282

73-
[[ -z "$SKIP_FOLDERS" ]] && skip_folders_option='' || skip_folders_option="--skip-folders='$SKIP_FOLDERS'"
83+
[[ -z "$SKIP_FOLDERS" ]] && skip_folders_option='' || skip_folders_option="--skip-folders='$SKIP_FOLDERS'"
7484

7585
/usr/games/cowsay "Running with the flag $phpcs_standard"
7686

@@ -80,6 +90,37 @@ if [[ "$(echo "$PHP_LINT" | tr '[:upper:]' '[:lower:]')" = 'false' ]]; then
8090
fi
8191

8292
echo "Running the following command"
83-
echo "/home/rtbot/vip-go-ci-tools/vip-go-ci/vip-go-ci.php --repo-owner=$GITHUB_REPO_OWNER --repo-name=$GITHUB_REPO_NAME --commit=$COMMIT_ID --token=\$GH_BOT_TOKEN --phpcs-path=/home/rtbot/vip-go-ci-tools/phpcs/bin/phpcs --local-git-repo=/home/rtbot/github-workspace --phpcs=true $phpcs_standard $phpcs_sniffs_exclude $skip_folders_option $php_lint_option --informational-url='https://github.com/rtCamp/action-phpcs-code-review/'"
84-
85-
gosu rtbot bash -c "/home/rtbot/vip-go-ci-tools/vip-go-ci/vip-go-ci.php --repo-owner=$GITHUB_REPO_OWNER --repo-name=$GITHUB_REPO_NAME --commit=$COMMIT_ID --token=$GH_BOT_TOKEN --phpcs-path=/home/rtbot/vip-go-ci-tools/phpcs/bin/phpcs --local-git-repo=/home/rtbot/github-workspace --phpcs=true $phpcs_standard $phpcs_sniffs_exclude $skip_folders_option $php_lint_option --informational-url='https://github.com/rtCamp/action-phpcs-code-review/'"
93+
echo "/home/rtbot/vip-go-ci-tools/vip-go-ci/vip-go-ci.php \
94+
--phpcs-skip-folders-in-repo-options-file=true \
95+
--lint-skip-folders-in-repo-options-file=true \
96+
--repo-options=true \
97+
--phpcs=true \
98+
--repo-owner=$GITHUB_REPO_OWNER \
99+
--repo-name=$GITHUB_REPO_NAME \
100+
--commit=$COMMIT_ID \
101+
--token=\$GH_BOT_TOKEN \
102+
--local-git-repo=$RTBOT_WORKSPACE \
103+
$phpcs_file_path \
104+
$phpcs_standard \
105+
$phpcs_sniffs_exclude \
106+
$skip_folders_option \
107+
$php_lint_option \
108+
--informational-url='https://github.com/rtCamp/action-phpcs-code-review/'"
109+
110+
gosu rtbot bash -c \
111+
"/home/rtbot/vip-go-ci-tools/vip-go-ci/vip-go-ci.php \
112+
--phpcs-skip-folders-in-repo-options-file=true \
113+
--lint-skip-folders-in-repo-options-file=true \
114+
--repo-options=true \
115+
--phpcs=true \
116+
--repo-owner=$GITHUB_REPO_OWNER \
117+
--repo-name=$GITHUB_REPO_NAME \
118+
--commit=$COMMIT_ID \
119+
--token=$GH_BOT_TOKEN \
120+
--local-git-repo=$RTBOT_WORKSPACE \
121+
$phpcs_file_path \
122+
$phpcs_standard \
123+
$phpcs_sniffs_exclude \
124+
$skip_folders_option \
125+
$php_lint_option \
126+
--informational-url='https://github.com/rtCamp/action-phpcs-code-review/'"

0 commit comments

Comments
 (0)