Skip to content

Commit cc9e2b9

Browse files
committed
first commit
0 parents  commit cc9e2b9

File tree

5 files changed

+152
-0
lines changed

5 files changed

+152
-0
lines changed

Dockerfile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# ubuntu:latest at 2019-02-12T19:22:56IST
2+
FROM ubuntu@sha256:7a47ccc3bbe8a451b500d2b53104868b46d60ee8f5b35a24b41a86077c650210
3+
4+
LABEL "com.github.actions.icon"="code"
5+
LABEL "com.github.actions.color"="purple"
6+
LABEL "com.github.actions.name"="PHPCS Inspection"
7+
LABEL "com.github.actions.description"="This will run phpcs on PRs"
8+
9+
RUN echo "tzdata tzdata/Areas select Asia" | debconf-set-selections && \
10+
echo "tzdata tzdata/Zones/Asia select Kolkata" | debconf-set-selections
11+
12+
RUN set -eux; \
13+
apt-get update; \
14+
DEBIAN_FRONTEND=noninteractive apt-get install -y \
15+
git \
16+
gosu \
17+
php7.2-cli \
18+
php7.2-curl \
19+
php-xml \
20+
python \
21+
python-pip \
22+
rsync \
23+
sudo \
24+
tree \
25+
vim \
26+
wget ; \
27+
pip install shyaml; \
28+
rm -rf /var/lib/apt/lists/*; \
29+
# verify that the binary works
30+
gosu nobody true
31+
32+
RUN useradd -m -s /bin/bash rtbot
33+
34+
RUN wget https://raw.githubusercontent.com/Automattic/vip-go-ci/master/tools-init.sh -O tools-init.sh && \
35+
bash tools-init.sh && \
36+
rm -f tools-init.sh
37+
38+
COPY entrypoint.sh main.sh /usr/local/bin/
39+
RUN chmod +x /usr/local/bin/*.sh
40+
41+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 rtCamp
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# PHPCS Inspections - GitHub Action
2+
3+
A [GitHub Action](https://github.com/features/actions) for running code inspections. It is based on https://github.com/Automattic/vip-go-ci/
4+
5+
You can use this action to work on latest commits pushed to Pull-Requests on GitHub, looking for problems in the code using PHP lint and PHPCS, and posting back to GitHub comments and reviews, detailing the issues found.
6+
7+
* This action by default respects standards specified in [phpcs.xml](https://github.com/rtCamp/github-actions-wordpress-skeleton/blob/master/phpcs.xml) file.
8+
9+
* If no `phpcs.xml` file is found in the root of the repository then by default inspection is carried out using: `WordPress-Core and WordPress-Docs` standards.
10+
11+
This action is a part of [GitHub action library](https://github.com/rtCamp/github-actions-library/) created by [rtCamp](https://github.com/rtCamp/).
12+
13+
## Installation
14+
15+
> Note: To use this GitHub Action, you must have access to GitHub Actions. GitHub Actions are currently only available in public beta (you must [apply for access](https://github.com/features/actions)).
16+
17+
Here is an example setup of this action:
18+
19+
1. Create a `.github/main.workflow` in your GitHub repo.
20+
2. Add the following code to the `main.workflow` file and commit it to the repo's `master` branch.
21+
3. Define `USER_GITHUB_TOKEN` as a [GitHub Actions Secret](https://developer.github.com/actions/creating-workflows/storing-secrets). (You can add secrets using the visual workflow editor or the repository settings.)
22+
[Read here](#environment-variables) for more info on how to setup this variable.
23+
24+
```bash
25+
workflow "Run Inspections" {
26+
resolves = ["PHPCS Inspections"]
27+
on = "pull_request"
28+
}
29+
30+
action "PHPCS Inspections" {
31+
uses = "rtCamp/action-vip-go-ci@master"
32+
secrets = ["USER_GITHUB_TOKEN"]
33+
}
34+
```
35+
36+
4. Whenever you create a pull request or commit on an existing pull request, this action will run.
37+
38+
## Environment Variables
39+
40+
`USER_GITHUB_TOKEN`: [GitHub token](https://github.com/settings/tokens), that will be used to post review comments on opened pull requests if any issue is found during the inspections run.
41+
42+
1. It is recommended to create this token from a bot user account.
43+
2. Permissions required for this token differ according to which type of repo this workflow has been setup for.
44+
1. Private Repo: Complete `repo` as well as `write:discussion` permission.
45+
2. Public Repo: Only `public_repo` permission.
46+
47+
## License
48+
49+
[MIT](LICENSE) © 2019 rtCamp

entrypoint.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
# custom path for files to override default files
4+
custom_path="$GITHUB_WORKSPACE/.github/inspections/vip-go-ci/"
5+
main_script="/usr/local/bin/main.sh"
6+
7+
if [[ -d "$custom_path" ]]; then
8+
rsync -a "$custom_path" /usr/local/bin/
9+
fi
10+
11+
bash "$main_script" "$@"

main.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
3+
stars=$(printf "%-30s" "*")
4+
5+
export CI_SCRIPT_OPTIONS="ci_script_options"
6+
export RTBOT_WORKSPACE="/home/rtbot/github-workspace"
7+
hosts_file="$GITHUB_WORKSPACE/.github/hosts.yml"
8+
9+
rsync -a "$GITHUB_WORKSPACE/" "$RTBOT_WORKSPACE"
10+
rsync -a /root/vip-go-ci-tools/ /home/rtbot/vip-go-ci-tools
11+
chown -R rtbot:rtbot /home/rtbot/
12+
13+
GITHUB_REPO_NAME=${GITHUB_REPOSITORY##*/}
14+
GITHUB_REPO_OWNER=${GITHUB_REPOSITORY%%/*}
15+
16+
phpcs_standard=''
17+
VIP="false"
18+
if [[ -f "$hosts_file" ]]; then
19+
VIP=$(cat "$hosts_file" | shyaml get-value "$CI_SCRIPT_OPTIONS.vip" | tr '[:upper:]' '[:lower:]')
20+
fi
21+
22+
if [[ -f "$RTBOT_WORKSPACE/phpcs.xml" ]]; then
23+
phpcs_standard="--phpcs-standard=$RTBOT_WORKSPACE/phpcs.xml"
24+
elif [[ "$VIP" = "true" ]]; then
25+
phpcs_standard="--phpcs-standard=WordPress-VIP-Go --phpcs-severity=1"
26+
else
27+
phpcs_standard="--phpcs-standard=WordPress-Core,WordPress-Docs"
28+
fi
29+
30+
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=$GITHUB_SHA --token=$USER_GITHUB_TOKEN --phpcs-path=/home/rtbot/vip-go-ci-tools/phpcs/bin/phpcs --local-git-repo=/home/rtbot/github-workspace --phpcs=true $phpcs_standard --lint=true"

0 commit comments

Comments
 (0)