diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..27eac86 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,18 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false + +[*.{yml,yaml,json}] +indent_size = 2 + +[Makefile] +indent_style = tab diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..0b1d1b5 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,3 @@ +# These are supported funding model platforms + +github: nnichols diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..c88cd70 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,34 @@ +--- +name: Bug report +about: Create a report to help us improve + +--- + +# Bug Report + +## Describe the Bug + +A clear and concise description of what the bug is. + +### Steps to Reproduce + +Steps to reproduce the behavior: + +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +### Expected Behavior + +A clear and concise description of what you expected to happen. + +### User Information + +- OS: [e.g. iOS] +- Browser [e.g. chrome, safari] +- Version [e.g. 22] + +### Additional Context + +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..b2b973c --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,23 @@ +--- +name: Feature request +about: Suggest an idea for this project + +--- + +# Feature Request + +## Problem Statement + +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +## Ideal Solution + +A clear and concise description of what you want to happen. + +### Alternative solutions + +A clear and concise description of any alternative solutions or features you've considered. + +## Additional Context + +Add any other context or screenshots about the feature request here. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..50e6203 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,11 @@ +# Proposed Changes + +- Additions: +- Updates: +- Deletions: + +## Pre-merge Checklist + +- [ ] Write + run tests +- [ ] Update CHANGELOG and increment version +- [ ] Update README and relevant documentation diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..657f013 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +# Changelog + +## v1 - 2021-07-07 + +- Initial Implementation diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..992f182 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,52 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. +Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. +Representation of a project may be further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at nichols1991@gmail.com. +All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. +The project team is obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..26cd6c6 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,32 @@ +# Contributing + +When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change. + +Please note we have a code of conduct, please follow it in all your interactions with the project. + +## Pull Requests + +1. Update the [CHANGELOG.md](https://github.com/nnichols/clojure-lint-action/blob/master/CHANGELOG.md) with details of all changes. +2. If any changes impact the external interface or use of **clojure-lint-action**, please update the [README](https://github.com/nnichols/clojure-lint-action/blob/master/README.md) to reflect any relevant differences. +3. Update all version numbers to the new version that this Pull Request would represent. + The versioning scheme we use is [SemVer](http://semver.org/). + +### Read the Documentation + +Familiarize yourself with the documentation before you submit a Pull Request. +If you have questions which aren't in the documentation, open a ticket or submit a Pull Request to update the documentation. + +### How to Contribute + +If you're looking for ways to contribute, try adding/fixing tests. +Additionally improving documentation or adding examples as you learn a new project can is an easy way to pitch in. +If you're looking to pitch in more extensively, check out the open [issues and feature requests](https://github.com/nnichols/clojure-lint-action/issues) and take a crack at one of them. + +## Code of Conduct + +### Our Pledge + +In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. + +A full copy of our [code of conduct may be found here.](https://github.com/nnichols/clojure-lint-action/blob/master/CODE_OF_CONDUCT.md) diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..180809b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM nnichols/clojure-lint-action + +ENV REVIEWDOG_VERSION=v0.12.0 + +RUN wget -O - -q https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b /usr/local/bin/ ${REVIEWDOG_VERSION} + +COPY lint.sh /lint.sh + +ENTRYPOINT ["bash", "/lint.sh"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..4543feb --- /dev/null +++ b/README.md @@ -0,0 +1,95 @@ +# Clojure Lint Action + +A simple GitHub Action to lint clojure files with [clj-kondo](https://github.com/clj-kondo/clj-kondo) and [reviewdog](https://github.com/reviewdog/reviewdog) on pull requests to improve the code review experience. + +## Inputs + +### `github_token` + +Optional. +`${{ github.token }}` is used by default. + +### `level` + +Optional. +Report level for reviewdog- must be one of `[info, warning, error]`. +It's same as `-level` flag of reviewdog. + +### `reporter` + +Reporter of reviewdog command. +Must be one of `[github-pr-check, github-pr-review, github-check]`. +Default is github-pr-check. +github-pr-review can use Markdown and add a link to rule page in reviewdog reports. + +### `filter_mode` + +Optional. +Filtering mode for the reviewdog command. +Must be one of `[added, diff_context, file, nofilter]`. +Default is added. + +### `fail_on_error` + +Optional. +Sets and exceptional exit code for reviewdog when errors are found. +Must be one of `[true, false]`. +Default is `false`. + +### `reviewdog_flags` + +Optional. +Additional reviewdog flags. + +### `path` + +Optional. +Base directory to run clj-kondo. +Same as `[path]` of `find` command. +Default: `.` + +### `pattern` + +Optional. +File patterns of target files. +Same as `-name [pattern]` of `find` command. +Default: `*.clj,*.cljc,*.cljs,*.cljx` + +### `exclude` + +Optional. +Exclude patterns of target files. +Same as `-not -path [exclude]` of `find` command. +e.g. `./git/*` + +### `clj_kondo_config` + +Optional. +Flags to pass to clj-kondo's `--config` option, which may either be in-line options or a path to a config file. +Default: `'{:output {:pattern "{{filename}}:{{row}}:{{col}}: {{message}}"}}'` + +## Example usage + +### [.github/workflows/reviewdog.yml](.github/workflows/reviewdog.yml) + +```yml +name: Lint Clojure +on: [pull_request] +jobs: + clj-kondo: + name: runner / clj-kondo + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: clj-kondo + uses: nnichols/clojure-lint-action@v1 + with: + github_token: ${{ secrets.github_token }} + reporter: github-pr-review # Change reporter. +``` + +## Licensing + +Copyright © 2021 [Nick Nichols](https://nnichols.github.io/) + +Distributed under the [MIT License](https://github.com/nnichols/clojure-vulnerability-check-action/blob/master/LICENSE) diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..c482538 --- /dev/null +++ b/action.yml @@ -0,0 +1,61 @@ +# ref: https://help.github.com/en/actions/building-actions/metadata-syntax-for-github-actions +name: Clojure Lint Action +description: A simple GitHub Actions to lint Clojure Code with clj-kondo + +author: Nick Nichols + +branding: + color: purple + icon: search + +runs: + using: docker + image: Dockerfile + +inputs: + github_token: + required: false + description: 'GITHUB_TOKEN.' + default: '${{ github.token }}' + level: + required: false + description: 'Report level for reviewdog [info,warning,error]' + default: 'error' + reporter: + required: false + description: | + Reporter of reviewdog command [github-pr-check,github-pr-review,github-check]. + Default is github-pr-check. + github-pr-review can use Markdown and add a link to rule page in reviewdog reports. + default: 'github-pr-check' + filter_mode: + required: false + description: | + Filtering mode for the reviewdog command [added,diff_context,file,nofilter]. + Default is added. + default: 'added' + fail_on_error: + required: false + description: | + Exit code for reviewdog when errors are found [true,false] + Default is `false`. + default: 'false' + reviewdog_flags: + required: false + description: 'Additional reviewdog flags' + default: '' + path: + required: false + description: "Base directory to run clj-kondo. Same as `[path]` of `find` command." + default: '.' + pattern: + required: false + description: "File patterns of target files. Same as `-name [pattern]` of `find` command." + default: '*.clj' + exclude: + required: false + description: "Exclude patterns of target files. Same as `-not -path [exclude]` of `find` command." + clj_kondo_config: + required: false + description: "Flags to pass to clj-kondo's `--config` option, which may either be in-line options or a path to a config file." + default: '{:output {:pattern "{{filename}}:{{row}}:{{col}}: {{message}}"}}' diff --git a/lint.sh b/lint.sh new file mode 100755 index 0000000..42880d0 --- /dev/null +++ b/lint.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +cd "${GITHUB_WORKSPACE}" || exit + +export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" + +clj-kondo --lint $(find "${INPUT_PATH}" -not -path "${INPUT_EXCLUDE}" -type f -name "${INPUT_PATTERN}") \ + --config "${INPUT_CLJ_KONDO_CONFIG}" \ + --config '{:output {:pattern "{{filename}}:{{row}}:{{col}}: {{message}}"}}' \ + | reviewdog \ + -efm="%f:%l:%c: %m" \ + -name="clj-kondo" \ + -reporter="${INPUT_REPORTER}" \ + -filter-mode="${INPUT_FILTER_MODE}" \ + -fail-on-error="${INPUT_FAIL_ON_ERROR}" \ + -level="${INPUT_LEVEL}" \ + ${INPUT_REVIEWDOG_FLAGS}