├── style.sh ├── Dockerfile ├── action.yml └── README.md /style.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd "${GITHUB_WORKSPACE}" || exit 1 4 | 5 | # https://github.com/reviewdog/reviewdog/issues/1158 6 | git config --global --add safe.directory "$GITHUB_WORKSPACE" || exit 1 7 | 8 | export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" 9 | 10 | sources=$(find "${INPUT_PATH}" -not -path "${INPUT_EXCLUDE}" -type f -name "${INPUT_PATTERN}") 11 | 12 | echo "::group::Files to style" 13 | echo "${sources}" 14 | echo "::endgroup::" 15 | 16 | /usr/local/bin/cljstyle check 17 | | reviewdog \ 18 | -efm="%f:%l:%c: %m" \ 19 | -name="cljstyle" \ 20 | -reporter="${INPUT_REPORTER}" \ 21 | -filter-mode="${INPUT_FILTER_MODE}" \ 22 | -fail-on-error="${INPUT_FAIL_ON_ERROR}" \ 23 | -level="${INPUT_LEVEL}" \ 24 | "${INPUT_REVIEWDOG_FLAGS}" 25 | 26 | exit_code=$? 27 | 28 | exit $exit_code 29 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.14 2 | 3 | ## Install Reviewdog 4 | ENV REVIEWDOG_VERSION=v0.12.0 5 | RUN wget -O - -q https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b /usr/local/bin/ ${REVIEWDOG_VERSION} 6 | 7 | ## Install cljstyle 8 | ENV CLJSTYLE_VERSION=v0.15.0 9 | RUN apk --no-cache add wget curl git which 10 | # RUN curl -sLO https://raw.githubusercontent.com/greglook/cljstyle/main/script/install-cljstyle | sh -s -- --dir /usr/local/bin/ --version ${CLJSTYLE_VERSION} 11 | 12 | # Create install directory for cljstyle 13 | RUN mkdir -p /install 14 | 15 | # Set Docker working directory 16 | WORKDIR /install 17 | 18 | RUN wget https://github.com/greglook/cljstyle/releases/download/0.15.0/cljstyle_0.15.0_linux.tar.gz 19 | 20 | RUN tar zvxf cljstyle_0.15.0_linux.tar.gz -C /usr/local/bin/ 21 | 22 | RUN which cljstyle 23 | 24 | COPY style.sh /style.sh 25 | 26 | ENTRYPOINT ["sh", "/style.sh"] 27 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | # ref: https://help.github.com/en/actions/building-actions/metadata-syntax-for-github-actions 2 | name: Clojure Style Action 3 | description: A simple GitHub Actions to lint Clojure Code with clj-kondo 4 | 5 | author: Practicalli 6 | 7 | branding: 8 | color: purple 9 | icon: search 10 | 11 | runs: 12 | using: docker 13 | image: Dockerfile 14 | 15 | inputs: 16 | github_token: 17 | required: false 18 | description: 'GITHUB_TOKEN.' 19 | default: '${{ github.token }}' 20 | level: 21 | required: false 22 | description: 'Report level for reviewdog [info,warning,error]' 23 | default: 'error' 24 | reporter: 25 | required: false 26 | description: | 27 | Reporter of reviewdog command [github-pr-check,github-pr-review,github-check]. 28 | Default is github-pr-check. 29 | github-pr-review can use Markdown and add a link to rule page in reviewdog reports. 30 | default: 'github-pr-check' 31 | filter_mode: 32 | required: false 33 | description: | 34 | Filtering mode for the reviewdog command [added,diff_context,file,nofilter]. 35 | Default is added. 36 | default: 'added' 37 | fail_on_error: 38 | required: false 39 | description: | 40 | Exit code for reviewdog when errors are found [true,false] 41 | Default is `false`. 42 | default: 'false' 43 | reviewdog_flags: 44 | required: false 45 | description: 'Additional reviewdog flags' 46 | default: '' 47 | path: 48 | required: false 49 | description: "Base directory to run clj-kondo. Same as `[path]` of `find` command." 50 | default: '.' 51 | pattern: 52 | required: false 53 | description: "File patterns of target files. Same as `-name [pattern]` of `find` command." 54 | default: '*.clj*' 55 | exclude: 56 | required: false 57 | description: "Exclude patterns of target files. Same as `-not -path [exclude]` of `find` command." 58 | cljstyle_config: 59 | required: false 60 | description: "Flags to pass to cljstyle `--config` option, which may either be in-line options or a path to a config file." 61 | default: '' 62 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Clojure Style Action 2 | 3 | GitHub Action to format clojure using [cljstyle](https://github.com/greglook/cljstyle), adding comments to pull requests using [reviewdog](https://github.com/reviewdog/reviewdog) to simplify the code review experience. 4 | 5 | ## Configuration options 6 | 7 | ### `github_token` 8 | 9 | Optional. 10 | `${{ github.token }}` is used by default. 11 | 12 | ### `level` 13 | 14 | Optional. 15 | Report level for reviewdog- must be one of `[info, warning, error]`. 16 | It's same as `-level` flag of reviewdog. 17 | 18 | ### `reporter` 19 | 20 | Reporter of reviewdog command. 21 | Must be one of `[github-pr-check, github-pr-review, github-check]`. 22 | Default is github-pr-check. 23 | github-pr-review can use Markdown and add a link to rule page in reviewdog reports. 24 | 25 | ### `filter_mode` 26 | 27 | Optional. 28 | Filtering mode for the reviewdog command. 29 | Must be one of `[added, diff_context, file, nofilter]`. 30 | Default is added. 31 | 32 | ### `fail_on_error` 33 | 34 | Optional. 35 | Sets and exceptional exit code for reviewdog when errors are found. 36 | Must be one of `[true, false]`. 37 | Default is `false`. 38 | 39 | ### `reviewdog_flags` 40 | 41 | Optional. 42 | Additional reviewdog flags. 43 | 44 | ### `path` 45 | 46 | Optional. 47 | Base directory to run clj-kondo. 48 | Same as `[path]` of `find` command. 49 | Default: `.` 50 | 51 | ### `pattern` 52 | 53 | Optional. 54 | File patterns of target files. 55 | Same as `-name [pattern]` of `find` command. 56 | Default: `*.clj*` (To capture `*.clj`, `*.cljs`, `*.cljc`, and `*.cljx`) 57 | 58 | ### `exclude` 59 | 60 | Optional. 61 | Exclude patterns of target files. 62 | Same as `-not -path [exclude]` of `find` command. 63 | e.g. `./git/*` 64 | 65 | ### `cljstyle_config` 66 | 67 | Optional. 68 | Flags to pass to cljstye `--config` option, which may either be in-line options or a path to a config file. 69 | 70 | Default: `'{:output {:pattern "{{filename}}:{{row}}:{{col}}: {{message}}"}}'` 71 | 72 | ## Example usage 73 | 74 | ### [.github/workflows/reviewdog.yml](.github/workflows/reviewdog.yml) 75 | 76 | To receive automatic Pull Request comments with linter results: 77 | 78 | ```yml 79 | name: Style Clojure 80 | on: [pull_request] 81 | jobs: 82 | cljstyle: 83 | name: Workflow 84 | runs-on: ubuntu-latest 85 | steps: 86 | - uses: actions/checkout@v3.0.2 87 | - name: cljstyle 88 | uses: practicalli/clojure-style-action@v1 89 | with: 90 | github_token: ${{ secrets.github_token }} 91 | reporter: github-pr-review 92 | ``` 93 | 94 | ## Licensing 95 | 96 | Copyright © 2022 [Practicaqlli](https://practical.li/) 97 | 98 | Distributed under the [Creative Commons ShareAlike License](https://creativecommons.org) 99 | --------------------------------------------------------------------------------