Skip to content

Commit

Permalink
Merge pull request rtCamp#58 from rtCamp/update/php-version-and-fix/p…
Browse files Browse the repository at this point in the history
…hpcsutils-no-sniff-found-error

Bump PHP version; Fix PHPCSUtils `ERROR: No sniffs were registered`
  • Loading branch information
mrrobot47 authored Mar 2, 2023
2 parents 68967fd + 6b138c0 commit 7527a68
Show file tree
Hide file tree
Showing 6 changed files with 418 additions and 139 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file is for unifying the coding style for different editors and IDEs.
# More information at http://editorconfig.org

root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
114 changes: 62 additions & 52 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,62 +1,72 @@
# ubuntu:latest at 2020-05-12T09:35:28IST
FROM ubuntu@sha256:3235326357dfb65f1781dbc4df3b834546d8bf914e82cce58e6e6b676e23ce8f
# ubuntu:latest as of 2023-02-27
FROM ubuntu@sha256:9a0bdde4188b896a372804be2384015e90e3f84906b750c1a53539b585fbbe7f

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

RUN echo "tzdata tzdata/Areas select Asia" | debconf-set-selections && \
echo "tzdata tzdata/Zones/Asia select Kolkata" | debconf-set-selections

RUN set -eux; \
apt-get update; \
apt install software-properties-common -y && \
add-apt-repository ppa:ondrej/php && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
cowsay \
git \
gosu \
jq \
php7.4-cli \
php7.4-common \
php7.4-curl \
php7.4-json \
php7.4-mbstring \
php7.4-mysql \
php7.4-xml \
php7.4-zip \
php-xml \
python \
python-pip \
rsync \
sudo \
tree \
vim \
zip \
unzip \
wget ; \
pip install shyaml; \
rm -rf /var/lib/apt/lists/*; \
# verify that the binary works
gosu nobody true

RUN useradd -m -s /bin/bash rtbot

RUN wget https://raw.githubusercontent.com/Automattic/vip-go-ci/main/tools-init.sh -O tools-init.sh && \
bash tools-init.sh && \
rm -f tools-init.sh

ENV VAULT_VERSION 1.4.3

# Setup Vault
RUN wget https://releases.hashicorp.com/vault/${VAULT_VERSION}/vault_${VAULT_VERSION}_linux_amd64.zip && \
unzip vault_${VAULT_VERSION}_linux_amd64.zip && \
rm vault_${VAULT_VERSION}_linux_amd64.zip && \
mv vault /usr/local/bin/vault
ARG VAULT_VERSION=1.12.3
ARG DEFAULT_PHP_VERSION=8.1
ARG PHP_BINARIES_TO_PREINSTALL='7.4 8.0 8.1 8.2'

ENV DOCKER_USER=rtbot
ENV ACTION_WORKDIR=/home/$DOCKER_USER
ENV DEBIAN_FRONTEND=noninteractive

RUN useradd -m -s /bin/bash $DOCKER_USER \
&& mkdir -p $ACTION_WORKDIR \
&& chown -R $DOCKER_USER $ACTION_WORKDIR

RUN set -ex \
&& savedAptMark="$(apt-mark showmanual)" \
&& apt-mark auto '.*' > /dev/null \
&& apt-get update && apt-get install -y --no-install-recommends git ca-certificates wget rsync gnupg jq software-properties-common unzip \
&& LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php \
&& apt-get update \
&& for v in $PHP_BINARIES_TO_PREINSTALL; do \
apt-get install -y --no-install-recommends \
php"$v" \
php"$v"-curl \
php"$v"-tokenizer \
php"$v"-simplexml \
php"$v"-xmlwriter; \
done \
&& update-alternatives --set php /usr/bin/php${DEFAULT_PHP_VERSION} \
&& wget https://releases.hashicorp.com/vault/${VAULT_VERSION}/vault_${VAULT_VERSION}_linux_amd64.zip \
&& unzip vault_${VAULT_VERSION}_linux_amd64.zip \
&& mv vault /usr/local/bin/vault \
# cleanup
&& rm -f vault_${VAULT_VERSION}_linux_amd64.zip \
&& apt-get remove software-properties-common unzip -y \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& { [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; } \
&& find /usr/local -type f -executable -exec ldd '{}' ';' \
| awk '/=>/ { print $(NF-1) }' \
| sort -u \
| xargs -r dpkg-query --search \
| cut -d: -f1 \
| sort -u \
| xargs -r apt-mark manual \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
# smoke test
&& for v in $PHP_BINARIES_TO_PREINSTALL; do \
php"$v" -v; \
done \
&& php -v \
&& vault -v;

COPY entrypoint.sh main.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/*.sh

RUN chmod +x /usr/local/bin/entrypoint.sh /usr/local/bin/main.sh

USER $DOCKER_USER

WORKDIR $ACTION_WORKDIR

RUN wget https://raw.githubusercontent.com/Automattic/vip-go-ci/latest/tools-init.sh -O tools-init.sh \
&& bash tools-init.sh \
&& rm -f tools-init.sh

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 rtCamp
Copyright (c) 2023 rtCamp

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
name: Run PHPCS inspection
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Run PHPCS inspection
Expand Down Expand Up @@ -71,6 +71,8 @@ Variable | Default | Possible Values | Purpose
`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](https://github.com/rtCamp/action-phpcs-code-review/wiki/How-to%3F#use-custom-coding-standards)
`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

Expand Down
19 changes: 16 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
#!/usr/bin/env bash

# Check required env variables
message=$(cat << "EOF"
PHPCS Code Review - GitHub Action by
_ ____
_ __| |_ / ___|__ _ _ __ ___ _ __
| '__| __| | / _` | '_ ` _ \| '_ \
| | | |_| |__| (_| | | | | | | |_) |
|_| \__|\____\__,_|_| |_| |_| .__/
|_|
EOF
)

echo -e "\e[0;32m\n$message\n\e[0m"

# If token are not set, exit with error.
if [[ -z "$GH_BOT_TOKEN" ]] && [[ -z "$VAULT_TOKEN" ]]; then
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"
exit 1
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"
exit 1
fi

# custom path for files to override default files
Expand Down
Loading

0 comments on commit 7527a68

Please sign in to comment.