├── lib ├── entrypoint.sh ├── clj_kondo.js ├── request.js ├── spawnargs.js └── run.js ├── images ├── annotation.png └── check-run.png ├── Dockerfile ├── action.yml ├── README.md └── LICENSE /lib/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | set -e 4 | 5 | node /action/lib/run.js 6 | -------------------------------------------------------------------------------- /images/annotation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DeLaGuardo/clojure-lint-action/HEAD/images/annotation.png -------------------------------------------------------------------------------- /images/check-run.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DeLaGuardo/clojure-lint-action/HEAD/images/check-run.png -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM cljkondo/clj-kondo:latest AS binary 2 | 3 | FROM node:10-slim 4 | 5 | COPY lib /action/lib 6 | COPY --from=binary /usr/local/bin/clj-kondo /usr/local/bin/clj-kondo 7 | ENTRYPOINT ["/action/lib/entrypoint.sh"] 8 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'clj-kondo checks' 2 | description: 'Lint your clojure code with clj-kondo in parallel to your builds' 3 | author: 'DeLaGuardo' 4 | branding: 5 | icon: 'gift' 6 | color: 'blue' 7 | inputs: 8 | clj-kondo-args: 9 | description: 'Arguments to be passed to clj-kondo' 10 | required: true 11 | default: '--lint src' 12 | check-name: 13 | description: 'Check name will be visible in Github Checks list' 14 | default: 'clj-kondo check' 15 | github_token: 16 | description: 'Github token to report linter results back to check' 17 | required: true 18 | runs: 19 | using: 'docker' 20 | image: 'Dockerfile' 21 | env: 22 | CHECK_NAME: ${{ inputs.check-name }} 23 | LINT_ARGS: ${{ inputs.clj-kondo-args }} 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Clojure Lint Action (using clj-kondo) 2 | 3 | Run clj-kondo and annotate source code changes with results. 4 | 5 | # Usage 6 | 7 | ```yaml 8 | steps: 9 | - uses: actions/checkout@v1 10 | - uses: DeLaGuardo/clojure-lint-action@master 11 | with: 12 | clj-kondo-args: --lint src 13 | # check-name is optional 14 | check-name: This is a report name 15 | # secrets.GITHUB_TOKEN is needed here 16 | # to publish annotations back to github 17 | # this action is not storing or sending it anywhere 18 | github_token: ${{ secrets.GITHUB_TOKEN }} 19 | ``` 20 | 21 | ![Annotation example](images/annotation.png) 22 | 23 | ![Check Run example](images/check-run.png) 24 | 25 | # License 26 | 27 | The scripts and documentation in this project are released under the [MIT License](LICENSE) 28 | -------------------------------------------------------------------------------- /lib/clj_kondo.js: -------------------------------------------------------------------------------- 1 | const { spawn } = require( 'child_process' ); 2 | const spawnargs = require('./spawnargs'); 3 | 4 | async function cljKondo(argString) { 5 | let args = spawnargs(argString); 6 | return new Promise((resolve, reject) => { 7 | let result = { 8 | stdout: "", 9 | stderr: "", 10 | statusCode: null 11 | }; 12 | const kondo = spawn('clj-kondo', 13 | [...args, '--config', '"{:output {:format :json}}"'], 14 | { 15 | shell: true 16 | }); 17 | kondo.stdout.on('data', data => { 18 | result.stdout += data.toString(); 19 | }); 20 | kondo.stderr.on('data', data => { 21 | result.stderr += data.toString(); 22 | }); 23 | kondo.on('close', code => { 24 | result.exitCode = code; 25 | result.stdout = JSON.parse(result.stdout); 26 | resolve(result); 27 | }); 28 | }); 29 | } 30 | 31 | module.exports = cljKondo; 32 | -------------------------------------------------------------------------------- /lib/request.js: -------------------------------------------------------------------------------- 1 | const https = require('https'); 2 | 3 | module.exports = (url, options) => { 4 | return new Promise((resolve, reject) => { 5 | const req = https 6 | .request(url, options, res => { 7 | let data = ''; 8 | res.on('data', chunk => { 9 | data += chunk; 10 | }); 11 | res.on('end', () => { 12 | if (res.statusCode >= 400) { 13 | const err = new Error(`Received status code ${res.statusCode}`); 14 | err.response = res; 15 | err.data = data; 16 | reject(err); 17 | } else { 18 | resolve({ res, data: JSON.parse(data) }); 19 | } 20 | }); 21 | }) 22 | .on('error', reject); 23 | if (options.body) { 24 | req.end(JSON.stringify(options.body)); 25 | } else { 26 | req.end(); 27 | } 28 | }); 29 | }; 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 GitHub, Inc. and contributors 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 13 | all 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 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /lib/spawnargs.js: -------------------------------------------------------------------------------- 1 | // Copy from https://github.com/binocarlos/spawn-args 2 | 3 | module.exports = function(args, opts){ 4 | opts = opts || {}; 5 | args = args || ''; 6 | var arr = []; 7 | 8 | var current = null; 9 | var quoted = null; 10 | var quoteType = null; 11 | 12 | function addcurrent(){ 13 | if(current){ 14 | // trim extra whitespace on the current arg 15 | arr.push(current.trim()); 16 | current = null; 17 | } 18 | } 19 | 20 | // remove escaped newlines 21 | args = args.replace(/\\\n/g, ''); 22 | 23 | for(var i=0; i