├── .github └── workflows │ ├── dockerimage.yml │ └── main.yml ├── Dockerfile ├── LICENSE ├── README.md ├── action.yml └── entrypoint.sh /.github/workflows/dockerimage.yml: -------------------------------------------------------------------------------- 1 | name: Build docker image 2 | on: 3 | push: 4 | branches: [ master ] 5 | pull_request: 6 | branches: [ master ] 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: actions/checkout@v2 14 | - name: Build the Docker image 15 | run: docker build . --file Dockerfile --tag checkstyle-action:$(date +%s) 16 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | on: pull_request 2 | 3 | jobs: 4 | checkstyle_job: 5 | runs-on: ubuntu-latest 6 | name: Checkstyle job 7 | steps: 8 | - name: Checkout 9 | uses: actions/checkout@v2 10 | - name: Run check style 11 | uses: nikitasavinov/checkstyle-action@master 12 | with: 13 | github_token: ${{ secrets.GITHUB_TOKEN }} 14 | reporter: 'github-pr-check' 15 | tool_name: 'testtool' 16 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:17-alpine 2 | 3 | ENV REVIEWDOG_VERSION=v0.14.0 4 | 5 | RUN wget -O - -q https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s -- -b /usr/local/bin/ ${REVIEWDOG_VERSION} 6 | RUN apk add --no-cache git 7 | COPY entrypoint.sh /entrypoint.sh 8 | 9 | ENTRYPOINT ["/entrypoint.sh"] 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Nikita 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. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Checkstyle GitHub Action 2 | 3 | Runs [checkstyle](https://github.com/checkstyle/checkstyle) with [reviewdog](https://github.com/reviewdog/reviewdog) on pull requests. 4 | 5 | Example: 6 | 7 | [![github-pr-check sample](https://user-images.githubusercontent.com/6826684/107879090-1a1c0500-6ed7-11eb-9260-14acdc94ad36.png)](https://github.com/nikitasavinov/checkstyle-action/pull/2/files) 8 | 9 | 10 | ## Input 11 | 12 | ### `checkstyle_config` 13 | 14 | Required. [Checkstyle config](https://checkstyle.sourceforge.io/config.html) 15 | Default is `google_checks.xml` (`sun_checks.xml` is also built in and available). 16 | 17 | ### `level` 18 | 19 | Optional. Report level for reviewdog [info,warning,error]. 20 | It's same as `-level` flag of reviewdog. 21 | 22 | ### `reporter` 23 | 24 | Optional. Reporter of reviewdog command [github-pr-check,github-pr-review]. 25 | It's same as `-reporter` flag of reviewdog. 26 | 27 | ### `filter_mode` 28 | 29 | Optional. Filtering mode for the reviewdog command [added,diff_context,file,nofilter]. 30 | Default is `added`. 31 | 32 | ### `fail_on_error` 33 | 34 | Optional. Exit code for reviewdog when errors are found [true,false]. 35 | Default is `false`. 36 | 37 | **Important**: this feature only works when `level` is set to `error`. 38 | 39 | ### `tool_name` 40 | 41 | Optional. Tool name to use for reviewdog reporter. 42 | Default is 'reviewdog'. 43 | 44 | ### `workdir` 45 | Optional. Working directory relative to the root directory. 46 | 47 | ### `checkstyle_version` 48 | Optional. Checkstyle version to use. 49 | Default is `10.3` 50 | 51 | ### `properties_file` 52 | Optional. Properties file relative to the root directory. 53 | 54 | ## Example usage 55 | 56 | ``` yml 57 | on: pull_request 58 | 59 | jobs: 60 | checkstyle_job: 61 | runs-on: ubuntu-latest 62 | name: Checkstyle job 63 | steps: 64 | - name: Checkout 65 | uses: actions/checkout@v2 66 | - name: Run check style 67 | uses: nikitasavinov/checkstyle-action@master 68 | with: 69 | github_token: ${{ secrets.GITHUB_TOKEN }} 70 | reporter: 'github-pr-check' 71 | tool_name: 'testtool' 72 | ``` 73 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | # action.yml 2 | name: 'Run java checkstyle' 3 | description: 'Run java checkstyle with reviewdog' 4 | branding: 5 | icon: 'code' 6 | color: 'red' 7 | inputs: 8 | github_token: 9 | description: 'GITHUB_TOKEN.' 10 | default: '${{ github.token }}' 11 | level: 12 | description: 'Report level for reviewdog [info,warning,error]' 13 | default: 'info' 14 | reporter: 15 | description: 'Reporter of reviewdog command [github-pr-check,github-pr-review]' 16 | default: 'github-pr-check' 17 | filter_mode: 18 | description: | 19 | Filtering for the reviewdog command [added,diff_context,file,nofilter]. 20 | Default is `added`. 21 | default: 'added' 22 | fail_on_error: 23 | description: | 24 | Exit code for reviewdog when errors are found [true,false] 25 | Default is `false`. 26 | default: 'false' 27 | checkstyle_config: 28 | description: 'Checkstyle config file' 29 | required: true 30 | default: 'google_checks.xml' 31 | checkstyle_version: 32 | description: 'Checkstyle version' 33 | default: '10.3' 34 | workdir: 35 | description: 'Working directory relative to the root directory.' 36 | default: '.' 37 | tool_name: 38 | description: 'Tool name to use for reviewdog reporter' 39 | default: 'reviewdog' 40 | properties_file: 41 | description: 'Properties file relative to the root directory.' 42 | default: '' 43 | runs: 44 | using: 'docker' 45 | image: 'Dockerfile' 46 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "Running check" 4 | 5 | cd "${GITHUB_WORKSPACE}" || exit 1 6 | 7 | git config --global --add safe.directory $GITHUB_WORKSPACE 8 | 9 | export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" 10 | 11 | if [ -n "${INPUT_PROPERTIES_FILE}" ]; then 12 | OPT_PROPERTIES_FILE="-p ${INPUT_PROPERTIES_FILE}" 13 | fi 14 | 15 | wget -O - -q https://github.com/checkstyle/checkstyle/releases/download/checkstyle-${INPUT_CHECKSTYLE_VERSION}/checkstyle-${INPUT_CHECKSTYLE_VERSION}-all.jar > /checkstyle.jar 16 | 17 | exec java -jar /checkstyle.jar "${INPUT_WORKDIR}" -c "${INPUT_CHECKSTYLE_CONFIG}" ${OPT_PROPERTIES_FILE} -f xml \ 18 | | reviewdog -f=checkstyle \ 19 | -name="${INPUT_TOOL_NAME}" \ 20 | -reporter="${INPUT_REPORTER:-github-pr-check}" \ 21 | -filter-mode="${INPUT_FILTER_MODE:-added}" \ 22 | -fail-on-error="${INPUT_FAIL_ON_ERROR:-false}" \ 23 | -level="${INPUT_LEVEL}" 24 | --------------------------------------------------------------------------------