From f08e03b01d634d7d592f2c8535cda5f1f965a067 Mon Sep 17 00:00:00 2001 From: Mat Stares Date: Wed, 25 Mar 2020 14:15:34 +1000 Subject: [PATCH] Initial Commit --- Dockerfile | 12 ++++++++++++ README.md | 37 +++++++++++++++++++++++++++++++++++-- action.yml | 27 +++++++++++++++++++++++++++ entrypoint.sh | 19 +++++++++++++++++++ 4 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 Dockerfile create mode 100644 action.yml create mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0a78d4c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM php:7.4-cli + +RUN apt-get update && apt-get -y install zip unzip + +RUN curl -sS https://getcomposer.org/installer | php -- \ +--install-dir=/usr/bin --filename=composer && chmod +x /usr/bin/composer + +RUN mkdir /twigcs && cd /twigcs && composer require friendsoftwig/twigcs && ln -s /twigcs/vendor/bin/twigcs /usr/local/bin/twigcs + +COPY "entrypoint.sh" "/entrypoint.sh" +RUN chmod +x /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/README.md b/README.md index cedf970..98df492 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,35 @@ -# actions-twigcs - TwigCS Action for GitHub Actions +# GitHub Action for TwigCS +GitHub Action implementation of the TwigCS Package provided by [https://github.com/friendsoftwig/twigcs](@friendsoftwig/twigcs). + +## Inputs + +### `dir` + +The folder to run twigcs recursively from. + +Default `'.'`. + +### `severity_tolerance` + +The exit code of TwigCS is based on the severity of any violation found. By default, twigcs only tolerates notices, this input changes this. + +Available options: +`error` - Allows notices and warnings +`notice` - Disallows notices +`ignore` - Allows everything + +Default `notice`. + +### `ignore_folder` + +Optional: Name of a subfolder to exclude. + +## Example usage + +``` +uses: DirtDiglett/actions-twigcs@v1 +with: + dir: ./src/views + severity_tolerance: notice + ignore_folder: vendor +``` \ No newline at end of file diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..25d9d11 --- /dev/null +++ b/action.yml @@ -0,0 +1,27 @@ +name: 'Twigcs' +description: 'A GitHub Action that runs Twigcs on a repository.' +author: 'DirtDiglett' + +branding: + icon: 'eye' + color: 'orange' + +inputs: + dir: + description: 'Folder to check code style' + required: false + default: . + severity_tolerance: + description: 'What level of exit code should be tolerated' + required: false + ignore_folder: + description: 'Ignore subfolders that match name' + required: false + +runs: + using: 'docker' + image: 'Dockerfile' + args: + - ${{ inputs.dir }} + - ${{ inputs.severity_tolerance }} + - ${{ inputs.ignore_folder }} \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..b8b461a --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,19 @@ +#!/bin/bash -l +set -e + +PHP_FULL_VERSION=$(php -r 'echo phpversion();') + +echo "======================" +echo "= Running TwigCS =" +echo "======================" +echo "PHP Version : ${PHP_FULL_VERSION}" + +if [[ -n "$INPUT_SEVERITY_TOLERANCE" ]]; then + options+=(-c "$INPUT_SEVERITY_TOLERANCE") +fi + +if [[ -n "$INPUT_IGNORE_FOLDER" ]]; then + options+=(-c "$INPUT_IGNORE_FOLDER") +fi + +twigcs $INPUT_DIR "${options[@]}" \ No newline at end of file