Skip to content

Commit 7527a68

Browse files
authored
Merge pull request #58 from rtCamp/update/php-version-and-fix/phpcsutils-no-sniff-found-error
Bump PHP version; Fix PHPCSUtils `ERROR: No sniffs were registered`
2 parents 68967fd + 6b138c0 commit 7527a68

File tree

6 files changed

+418
-139
lines changed

6 files changed

+418
-139
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This file is for unifying the coding style for different editors and IDEs.
2+
# More information at http://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
indent_style = space
8+
indent_size = 2
9+
end_of_line = lf
10+
charset = utf-8
11+
trim_trailing_whitespace = true
12+
insert_final_newline = true

Dockerfile

Lines changed: 62 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,72 @@
1-
# ubuntu:latest at 2020-05-12T09:35:28IST
2-
FROM ubuntu@sha256:3235326357dfb65f1781dbc4df3b834546d8bf914e82cce58e6e6b676e23ce8f
1+
# ubuntu:latest as of 2023-02-27
2+
FROM ubuntu@sha256:9a0bdde4188b896a372804be2384015e90e3f84906b750c1a53539b585fbbe7f
33

44
LABEL "com.github.actions.icon"="check-circle"
55
LABEL "com.github.actions.color"="green"
66
LABEL "com.github.actions.name"="PHPCS Code Review"
7-
LABEL "com.github.actions.description"="This will run phpcs on PRs"
7+
LABEL "com.github.actions.description"="Run automated code review using PHPCS on your pull requests."
88
LABEL "org.opencontainers.image.source"="https://github.com/rtCamp/action-phpcs-code-review"
99

10-
RUN echo "tzdata tzdata/Areas select Asia" | debconf-set-selections && \
11-
echo "tzdata tzdata/Zones/Asia select Kolkata" | debconf-set-selections
12-
13-
RUN set -eux; \
14-
apt-get update; \
15-
apt install software-properties-common -y && \
16-
add-apt-repository ppa:ondrej/php && \
17-
DEBIAN_FRONTEND=noninteractive apt-get install -y \
18-
cowsay \
19-
git \
20-
gosu \
21-
jq \
22-
php7.4-cli \
23-
php7.4-common \
24-
php7.4-curl \
25-
php7.4-json \
26-
php7.4-mbstring \
27-
php7.4-mysql \
28-
php7.4-xml \
29-
php7.4-zip \
30-
php-xml \
31-
python \
32-
python-pip \
33-
rsync \
34-
sudo \
35-
tree \
36-
vim \
37-
zip \
38-
unzip \
39-
wget ; \
40-
pip install shyaml; \
41-
rm -rf /var/lib/apt/lists/*; \
42-
# verify that the binary works
43-
gosu nobody true
44-
45-
RUN useradd -m -s /bin/bash rtbot
46-
47-
RUN wget https://raw.githubusercontent.com/Automattic/vip-go-ci/main/tools-init.sh -O tools-init.sh && \
48-
bash tools-init.sh && \
49-
rm -f tools-init.sh
50-
51-
ENV VAULT_VERSION 1.4.3
52-
53-
# Setup Vault
54-
RUN wget https://releases.hashicorp.com/vault/${VAULT_VERSION}/vault_${VAULT_VERSION}_linux_amd64.zip && \
55-
unzip vault_${VAULT_VERSION}_linux_amd64.zip && \
56-
rm vault_${VAULT_VERSION}_linux_amd64.zip && \
57-
mv vault /usr/local/bin/vault
10+
ARG VAULT_VERSION=1.12.3
11+
ARG DEFAULT_PHP_VERSION=8.1
12+
ARG PHP_BINARIES_TO_PREINSTALL='7.4 8.0 8.1 8.2'
13+
14+
ENV DOCKER_USER=rtbot
15+
ENV ACTION_WORKDIR=/home/$DOCKER_USER
16+
ENV DEBIAN_FRONTEND=noninteractive
17+
18+
RUN useradd -m -s /bin/bash $DOCKER_USER \
19+
&& mkdir -p $ACTION_WORKDIR \
20+
&& chown -R $DOCKER_USER $ACTION_WORKDIR
21+
22+
RUN set -ex \
23+
&& savedAptMark="$(apt-mark showmanual)" \
24+
&& apt-mark auto '.*' > /dev/null \
25+
&& apt-get update && apt-get install -y --no-install-recommends git ca-certificates wget rsync gnupg jq software-properties-common unzip \
26+
&& LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php \
27+
&& apt-get update \
28+
&& for v in $PHP_BINARIES_TO_PREINSTALL; do \
29+
apt-get install -y --no-install-recommends \
30+
php"$v" \
31+
php"$v"-curl \
32+
php"$v"-tokenizer \
33+
php"$v"-simplexml \
34+
php"$v"-xmlwriter; \
35+
done \
36+
&& update-alternatives --set php /usr/bin/php${DEFAULT_PHP_VERSION} \
37+
&& wget https://releases.hashicorp.com/vault/${VAULT_VERSION}/vault_${VAULT_VERSION}_linux_amd64.zip \
38+
&& unzip vault_${VAULT_VERSION}_linux_amd64.zip \
39+
&& mv vault /usr/local/bin/vault \
40+
# cleanup
41+
&& rm -f vault_${VAULT_VERSION}_linux_amd64.zip \
42+
&& apt-get remove software-properties-common unzip -y \
43+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
44+
&& { [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; } \
45+
&& find /usr/local -type f -executable -exec ldd '{}' ';' \
46+
| awk '/=>/ { print $(NF-1) }' \
47+
| sort -u \
48+
| xargs -r dpkg-query --search \
49+
| cut -d: -f1 \
50+
| sort -u \
51+
| xargs -r apt-mark manual \
52+
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
53+
# smoke test
54+
&& for v in $PHP_BINARIES_TO_PREINSTALL; do \
55+
php"$v" -v; \
56+
done \
57+
&& php -v \
58+
&& vault -v;
5859

5960
COPY entrypoint.sh main.sh /usr/local/bin/
60-
RUN chmod +x /usr/local/bin/*.sh
61+
62+
RUN chmod +x /usr/local/bin/entrypoint.sh /usr/local/bin/main.sh
63+
64+
USER $DOCKER_USER
65+
66+
WORKDIR $ACTION_WORKDIR
67+
68+
RUN wget https://raw.githubusercontent.com/Automattic/vip-go-ci/latest/tools-init.sh -O tools-init.sh \
69+
&& bash tools-init.sh \
70+
&& rm -f tools-init.sh
6171

6272
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 rtCamp
3+
Copyright (c) 2023 rtCamp
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
name: Run PHPCS inspection
2626
runs-on: ubuntu-latest
2727
steps:
28-
- uses: actions/checkout@v2
28+
- uses: actions/checkout@v3
2929
with:
3030
ref: ${{ github.event.pull_request.head.sha }}
3131
- name: Run PHPCS inspection
@@ -71,6 +71,8 @@ Variable | Default | Possible Values | Purpose
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`.
7272
`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'
7373
`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](https://github.com/rtCamp/action-phpcs-code-review/wiki/How-to%3F#use-custom-coding-standards)
74+
`SKIP_DRAFT_PRS` | false | `true`/`false` | Set it to true to skip PHPCS checks on draft PRs.
75+
`PHPCS_PHP_VERSION` | 8.1 | 7.4, 8.0, 8.1, or 8.2 | To use a different PHP interpreter than the system default.
7476

7577
## Modifying the bot’s behavior
7678

entrypoint.sh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
#!/usr/bin/env bash
22

3-
# Check required env variables
3+
message=$(cat << "EOF"
4+
PHPCS Code Review - GitHub Action by
5+
_ ____
6+
_ __| |_ / ___|__ _ _ __ ___ _ __
7+
| '__| __| | / _` | '_ ` _ \| '_ \
8+
| | | |_| |__| (_| | | | | | | |_) |
9+
|_| \__|\____\__,_|_| |_| |_| .__/
10+
|_|
11+
EOF
12+
)
13+
14+
echo -e "\e[0;32m\n$message\n\e[0m"
15+
16+
# If token are not set, exit with error.
417
if [[ -z "$GH_BOT_TOKEN" ]] && [[ -z "$VAULT_TOKEN" ]]; then
5-
printf "[\e[0;31mERROR\e[0m] Secret \`GH_BOT_TOKEN\` or \`VAULT_TOKEN\` is missing. Please add it to this action for proper execution.\nRefer https://github.com/rtCamp/action-phpcs-code-review#github-token-creation for more information.\n"
6-
exit 1
18+
printf "[\e[0;31mERROR\e[0m] Secret \`GH_BOT_TOKEN\` or \`VAULT_TOKEN\` is missing. Please add it to this action for proper execution.\nRefer https://github.com/rtCamp/action-phpcs-code-review#github-token-creation for more information.\n"
19+
exit 1
720
fi
821

922
# custom path for files to override default files

0 commit comments

Comments
 (0)