Giter VIP home page Giter VIP logo

lint-action's Introduction

✨ Lint Action

Note: The behavior of actions like this one is currently limited in the context of forks. See Limitations.

Screenshots

  • Checks on pull requests:

    Screenshot of check runs
  • Commit annotations:

    Screenshot of ESLint annotations

Supported tools

Usage

Create a new GitHub Actions workflow in your project, e.g. at .github/workflows/lint.yml. The content of the file should be in the following format:

name: Lint

on:
  # Trigger the workflow on push or pull request,
  # but only for the main branch
  push:
    branches:
      - main
  # Replace pull_request with pull_request_target if you
  # plan to use this action with forks, see the Limitations section
  pull_request:
    branches:
      - main

# Down scope as necessary via https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token
permissions:
  checks: write
  contents: write

jobs:
  run-linters:
    name: Run linters
    runs-on: ubuntu-latest

    steps:
      - name: Check out Git repository
        uses: actions/checkout@v3

      # Install your linters here

      - name: Run linters
        uses: wearerequired/lint-action@v2
        with:
          # Enable your linters here

Examples

All linters are disabled by default. To enable a linter, simply set the option with its name to true, e.g. eslint: true.

The action doesn't install the linters for you; you are responsible for installing them in your CI environment.

JavaScript example (ESLint and Prettier)

name: Lint

on:
  # Trigger the workflow on push or pull request,
  # but only for the main branch
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  run-linters:
    name: Run linters
    runs-on: ubuntu-latest

    steps:
      - name: Check out Git repository
        uses: actions/checkout@v3

      - name: Set up Node.js
        uses: actions/setup-node@v1
        with:
          node-version: 12

      # ESLint and Prettier must be in `package.json`
      - name: Install Node.js dependencies
        run: npm ci

      - name: Run linters
        uses: wearerequired/lint-action@v2
        with:
          eslint: true
          prettier: true

Important: Make sure to exclude the .github directory in your ESLint and Prettier configs as the default GITHUB_TOKEN cannot be used to update workflow files due to the missing workflow permission. See Limitations.

PHP example (PHP_CodeSniffer)

name: Lint

on:
  # Trigger the workflow on push or pull request,
  # but only for the main branch
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  run-linters:
    name: Run linters
    runs-on: ubuntu-latest

    steps:
      - name: Check out Git repository
        uses: actions/checkout@v3

      - name: Set up PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: "7.4"
          coverage: none
          tools: phpcs

      - name: Run linters
        uses: wearerequired/lint-action@v2
        with:
          php_codesniffer: true
          # Optional: Ignore warnings
          php_codesniffer_args: "-n"

If you prefer to use Composer you can also use this:

name: Lint

on:
  # Trigger the workflow on push or pull request,
  # but only for the main branch
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  run-linters:
    name: Run linters
    runs-on: ubuntu-latest

    steps:
      - name: Check out Git repository
        uses: actions/checkout@v3

      - name: Set up PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: "7.4"
          coverage: none
          tools: composer

      - name: Install PHP dependencies
        run: |
          composer install --prefer-dist --no-progress --no-ansi --no-interaction
          echo "${PWD}/vendor/bin" >> $GITHUB_PATH

      - name: Run linters
        uses: wearerequired/lint-action@v2
        with:
          php_codesniffer: true

Python example (Flake8 and Black)

name: Lint

on:
  # Trigger the workflow on push or pull request,
  # but only for the main branch
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  run-linters:
    name: Run linters
    runs-on: ubuntu-latest

    steps:
      - name: Check out Git repository
        uses: actions/checkout@v3

      - name: Set up Python
        uses: actions/setup-python@v1
        with:
          python-version: 3.8

      - name: Install Python dependencies
        run: pip install black flake8

      - name: Run linters
        uses: wearerequired/lint-action@v2
        with:
          black: true
          flake8: true

C, C++, Objective-C and Objective-C++ example (clang_format)

name: Lint

on:
  # Trigger the workflow on push or pull request,
  # but only for the main branch
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  run-linters:
    name: Run linters
    runs-on: ubuntu-latest

    steps:
      - name: Check out Git repository
        uses: actions/checkout@v3

      - name: Install ClangFormat
        run: sudo apt-get install -y clang-format

      - name: Run linters
        uses: wearerequired/lint-action@v2
        with:
          clang_format: true

C# and VB.NET example (dotnet_format)

name: Lint

on:
  # Trigger the workflow on push or pull request,
  # but only for the main branch
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  run-linters:
    name: Run linters
    runs-on: ubuntu-latest

    steps:
      - name: Check out Git repository
        uses: actions/checkout@v3

      - name: Set up .NET
        uses: actions/setup-dotnet@v1
        with:
          dotnet-version: "6.0.x"

      - name: Run linters
        uses: wearerequired/lint-action@v2
        with:
          dotnet_format: true

AutoFix example

name: Lint

on:
  # Trigger the workflow on push or pull request,
  # but only for the main branch
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  run-linters:
    name: Run linters
    runs-on: ubuntu-latest

    steps:
      - name: Check out Git repository
        uses: actions/checkout@v3

      - name: Set up Python
        uses: actions/setup-python@v1
        with:
          python-version: 3.8

      - name: Install Python dependencies
        run: pip install black flake8

      - name: Run linters
        uses: wearerequired/lint-action@v2
        with:
          auto_fix: true
          black: true
          black_auto_fix: true
          flake8: true
          flake8_auto_fix: false

With auto_fix set to true, by default the action will try and fix code issues automatically and commit and push them automatically. Here however, flake8 linter does not support auto-fixing, so setting flake8_auto_fix to false will prevent any unnecessary warnings.

Configuration

Linter-specific options

[linter] can be one of autopep8, black, clang_format, dotnet_format, erblint, eslint, flake8, gofmt, golint, mypy, oitnb, php_codesniffer, prettier, pylint, rubocop, stylelint, swift_format_official, swift_format_lockwood, swiftlint and xo:

  • [linter]: Enables the linter in your repository. Default: false
  • [linter]_args: Additional arguments to pass to the linter. Example: eslint_args: "--max-warnings 0" if ESLint checks should fail even if there are no errors and only warnings. Default: ""
  • [linter]_dir: Directory where the linting command should be run. Example: eslint_dir: server/ if ESLint is installed in the server subdirectory. Default: Repository root
  • [linter]_extensions: Extensions of files to check with the linter. Example: eslint_extensions: js,ts to lint JavaScript and TypeScript files with ESLint. Default: Varies by linter, see action.yml
  • [linter]_command_prefix: Command prefix to be run before the linter command. Default: "".
  • [linter]_auto_fix: Whether the linter should try to fix code style issues automatically. This option is useful to commit and push changes only for specific linters and not all of them when auto_fix option is set. Default: true if linter supports auto-fixing, false if not.

General options

  • github_token: The GITHUB_TOKEN to authenticate on behalf of GitHub Actions. Defaults to the GitHub token.

  • continue_on_error: Whether the workflow run should also fail when linter failures are detected. Default: true

  • auto_fix: Whether linters should try to fix code style issues automatically. If some issues can be fixed, the action will apply the needed changes. Default: false

    Screenshot of auto-fix commit

  • commit: Whether to commit and push the changes made by auto_fix. Default: true

  • git_name: Username for auto-fix commits. Default: "Lint Action"

  • git_email: Email address for auto-fix commits. Default: "[email protected]"

  • git_no_verify: Bypass the pre-commit and pre-push git hooks. Default: false

  • commit_message: Template for auto-fix commit messages. The ${linter} variable can be used to insert the name of the linter. Default: "Fix code style issues with ${linter}"

  • check_name: Template for the name of the check run. Use this to ensure unique names when the action is used more than once in a workflow. The ${linter} and ${dir} variables can be used to insert the name and directory of the linter. Default: "${linter}"

  • neutral_check_on_warning: Whether the check run should conclude with a neutral status instead of success when the linter finds only warnings. Default: false

Linter support

Some options are not available for specific linters:

Linter auto-fixing extensions
autopep8 ❌ (py)
black
clang_format
clippy ❌ (rs)
dotnet_format ❌ (cs)
erblint ❌ (erb)
eslint
flake8
gofmt ❌ (go)
golint ❌ (go)
mypy ❌ (py)
oitnb
php_codesniffer
prettier
pylint ❌ (py)
rubocop ❌ (rb)
rustfmt ❌ (rs)
stylelint
swift_format_official
swift_format_lockwood ❌ (swift)
swiftlint ❌ (swift)
tsc ❌ (ts)
xo

Limitations

Pull requests

There are currently some limitations as to how this action (or any other action) can be used in the context of pull_request events from forks:

  • The action doesn't have permission to push auto-fix changes to the fork. This is because the pull_request event runs on the upstream repo, where the github_token is lacking permissions for the fork. Source
  • The action doesn't have permission to create annotations for commits on forks unless you use the pull_request_target event. You can modify the default permissions granted to the GITHUB_TOKEN by using the permissions key and set the checks scope to write. See GitHub documentation for more.

Auto-fixing workflow files

If auto_fix is enabled and the default GITHUB_TOKEN is used, none of the linters should be allowed to change files in .github/workflows as the token doesn't have the necessary workflow permission. This can be achieved by adding the directory to the ignore config of the used linter. Source

For details and comments, please refer to #65 and #74.


a required open source product - let's get in touch

lint-action's People

Contributors

andrewbabbitt97 avatar ascandella avatar codeman1o1 avatar compnerd avatar dependabot[bot] avatar devyntk avatar emerzh avatar gismo359 avatar github-actions[bot] avatar grahamotte avatar imunlikely avatar inket avatar manicmaniac avatar mstssk avatar nedlinin avatar nick-mobilecoin avatar nopeless avatar ocean90 avatar phamelink avatar raghav-bell avatar ryanseamless avatar samuelmeuli avatar tomfuertes avatar zacharyburnett avatar zirkelc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lint-action's Issues

Auto-fixing on pull requests is not committing

After upgrading from 0.7.9 to 1.1.0 our team noticed that some lint violations had crept in. They were all autofixable so I'm wondering if the diff detection is not working?

0.7.9:

Verifying setup for RuboCop…
Verified RuboCop setup
Will use RuboCop to check the files with extensions rb
Linting and auto-fixing files in /home/runner/work/project/project with RuboCop…
RuboCop found no issues (success)
Committing changes
Pushing changes to ***github.com/company/project.git
To https://github.com/company/project.git

It's not obvious from the log in 0.7.9 but it did push an autofix commit.

1.1.0:

Verifying setup for RuboCop…
Verified RuboCop setup
Will use RuboCop to check the files with extensions rb
Linting and auto-fixing files in /home/runner/work/project/project with RuboCop…
RuboCop found no issues (success)

In 1.1.0 no autofix commit was pushed

422 from Github API and Lint task fails

FIrst Thanks for the action, it works great for stylelint but somehow i canoot get it to work with ESLINT.

The task always fails (also tried to run only this task for ESLINT)

This is the error i get in the console of github actions.

Thanks for looking into this

data:{"message":"Invalid request.\n\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.\n\"end_line\", \"start_line\" weren't supplied.","documentation_url":"https://developer.github.com/v3/checks/runs/#create-a-check-run"}`
}
Error: Error trying to create GitHub check for ESLint: Received status code 422
at Object.createCheck (/home/runner/work/_actions/samuelmeuli/lint-action/v1.2.0/src/github.js:113:9)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
/home/runner/work/_actions/samuelmeuli/lint-action/v1.2.0/src/index.js:15
throw new Error(Exiting because of unhandled promise rejection);
^

Error: Exiting because of unhandled promise rejection
at process. (/home/runner/work/_actions/samuelmeuli/lint-action/v1.2.0/src/index.js:15:8)
at process.emit (events.js:210:5)
at processPromiseRejections (internal/process/promises.js:201:33)
at processTicksAndRejections (internal/process/task_queues.js:94:32)
`

Lint tasks run in wrong workflow?

Following the example from the documentation, I created a new workflow file for linting, called lint.yml. I have another workflow file named ci.yml that handles running tests (and, previously, running yarn lint on the project). Maybe this is intended behavior, but when the "Run linters" job runs, it creates new jobs for each linter in the "CI" workflow, rather than the "Lint" workflow. Consequently, it's a bit confusing in the UI. The "Lint" workflow is missing jobs our team thinks it should have while "CI" has jobs that it shouldn't.

Checks overwritten when action is used in different folders

Hello.

First of all, thanks for the project!

I have a monorepo with two folders: app and server. I have a workflow for the app and another one for the server because the config is different.

When running the workflows, I noticed the following:

  • The app one has an output with errors but is successful (neither ESLint nor Prettier cjecks are created).
  • The server one doesn't have errors but fails (both ESLint and Prettier checks are created).
  • All errors listed in the ESLint check (created when running the server one) belong to the app folder.

image

Because running only one of the workflows behaves as expected, I know that the workflows are properly set.

The server workflow is running first, so I think the issue is that, when the app workflow runs, ESLint and Prettier checks get overwritten.

Is there any workaround?

I think a way of solving it could be accepting an optional input to set the name for the created checks. Let me know if this sounds good and I can open a PR.

Thanks!

Does not seem to handle js config files

we run eslint --config .eslint-config.js but i get an error:

Error: Error parsing ESLint JSON output: Unexpected end of JSON input. Output: ""
    at Function.parseOutput (/home/runner/work/_actions/samuelmeuli/lint-action/v1.5.2/src/linters/eslint.js:72:10)
    at runAction (/home/runner/work/_actions/samuelmeuli/lint-action/v1.5.2/src/index.js:85:30)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
/home/runner/work/_actions/samuelmeuli/lint-action/v1.5.2/src/index.js:13
	throw new Error(`Exiting because of unhandled promise rejection`);
	^

Error: Exiting because of unhandled promise rejection
    at process.<anonymous> (/home/runner/work/_actions/samuelmeuli/lint-action/v1.5.2/src/index.js:13:8)
    at process.emit (events.js:210:5)
    at processPromiseRejections (internal/process/promises.js:201:33)
    at processTicksAndRejections (internal/process/task_queues.js:94:32)

Add Pylint Support

Pylint is currently the most popular Python linter out there. Is there any chance that you will add support for it?

Incompatible with default Gatsby ESLint setup

Hi there,

I'm trialling this action with the default ESLint setup that comes with GatsbyJS, and i'm receiving the below error. Any idea's or is this a bug?

Screenshot 2020-03-16 at 11 28 24

Here is a link to their eslint file

Thanks!

Select a list of Directories / files

Hello,

thanks for this action

I wanted to run flake8 and black but it seems that for some reason he try to lint/format all my deps in a folder called "/lib/python....." not sure why....

to avoid that i looked at a way to select the list of directories and files to run on but seems the _dir does not do the job with multiple input

is there a better way?

Assuming path starts with ./ causes annotations to fail

https://github.com/samuelmeuli/lint-action/blob/e92161e1607518185cb000036d625fb32b7bd4e9/src/linters/flake8.js#L72

Annotations are correctly created by are missing the first two characters of the path (in this situation hardware_ordering):
Selection_353
This causes the annotations to not appear on the pull request.
I am using file-changes-action to detect changed files and passing the results to flake8_args like flake8_args: ${{ steps.get_file_changes.outputs.files}}

ESLint error: "The keyword 'const' is reserved"

Error: ESLint error: Parsing error: The keyword 'const' is reserved
at Function.parseOutput (/home/runner/work/_actions/samuelmeuli/lint-action/v1/src/linters/eslint.js:86:12)
at runAction (/home/runner/work/_actions/samuelmeuli/lint-action/v1/src/index.js:86:30)

Only lint modified files

Currently, all files in a repository are being linted. The action should detect which files are part of the relevant commit/PR and only check these files.

Auto-fix code style issues

Tools like ESLint and Prettier offer commands to automatically fix (some of) the detected linting/formatting issues. This action should allow users to run these commands on their commits/PRs.

Not able to get the lint action working on python

Hi,

I followed up the configuration for Python Setup but it breaks when it starts linting process.
PFB Error trace

Adding auth information to Git remote URL
/bin/sh: 1: Syntax error: "(" unexpected
Error: Command failed: git remote set-url origin https://jayanthchandra:***@github.com/jayanthchandra/boilerPlate-flask.git
/bin/sh: 1: Syntax error: "(" unexpected

at checkExecSyncError (child_process.js:621:11)
at execSync (child_process.js:657:15)
at run (/home/runner/work/_actions/samuelmeuli/lint-action/v1/src/utils/action.js:69:18)
at Object.checkOutRemoteBranch (/home/runner/work/_actions/samuelmeuli/lint-action/v1/src/git.js:17:3)
at runAction (/home/runner/work/_actions/samuelmeuli/lint-action/v1/src/index.js:54:7)
at Object.<anonymous> (/home/runner/work/_actions/samuelmeuli/lint-action/v1/src/index.js:113:1)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14) {

status: 2,
signal: null,
output: [ null, '', '/bin/sh: 1: Syntax error: "(" unexpected\n' ],
pid: 2555,
stdout: '',
stderr: '/bin/sh: 1: Syntax error: "(" unexpected\n'
}
/home/runner/work/_actions/samuelmeuli/lint-action/v1/src/index.js:13
throw new Error(Exiting because of unhandled promise rejection);

Error: Exiting because of unhandled promise rejection
at process. (/home/runner/work/_actions/samuelmeuli/lint-action/v1/src/index.js:13:8)
at process.emit (events.js:210:5)
at processPromiseRejections (internal/process/promises.js:201:33)
at processTicksAndRejections (internal/process/task_queues.js:94:32)

Is there any workaround for this ?

I tried both v1 and v1.5 but still has the same error.

Add Dart/Flutter support

This project is so cool 👍

I would like to support Dart and with that also Flutter linting :)
Is this something that makes sense for this project?

Warning: "Unexpected input 'github_token'"

I'm using following the README.md example for javascript-example-eslint-and-prettier, but the workflow shows unexpected input, checking the inputs that's correct that input is not expected. Also it's trying to push changes to .github folder but not sure why. It's a private repo

Here is the error:

! [remote rejected] master -> master (refusing to allow a GitHub App to create or update workflow `.github/workflows/Lint.yml` without `workflows` permission)

This is my lint.yml file:

name: Lint
on: [push, pull_request]
jobs:
  node-lint-tests:
    runs-on: ${{ matrix.os }}
    if: "!contains(github.event.head_commit.message, 'ci skip')"

    strategy:
      matrix:
        os: [ 'ubuntu-latest']
        node: [10, 12]

    steps:
      - name: Check out Git repository
        uses: actions/checkout@v2

      - name: Set up Node.js
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node }}

      - name: install node_modules
        run: yarn install --frozen-lockfile

      - name: Run linters
        uses: samuelmeuli/lint-action@v1
        with:
          github_token: ${{ secrets.github_token }}
          eslint: true
          prettier: true
          auto_fix: true

Example how to prevent release

Hi,

Related to #31 and #50. I understand not failing main job is by design of this action. However, I could not figure out how to prevent next release step if there are lint errors.

Could you provide a basic example how to prevent next step if there are lint errors?

Thanks,

"Run linters" check passes despite linting errors

Hi, I'm trying to use a workflow with a lint job and a build job. The build job is set to need the lint to complete successfully to begin so that I don't waste time building if linting returned issues. When linting though, that step is marked successfully completed even if the linters found issues. Is this expected behaviour? Shouldn't the step be marked fail if the linter returns issues?

firefox_8CXddMBi8n

name: STAGING - Lint and Build

on:
  push:
    branches-ignore:
      - master
jobs:
  Lint:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: "Setup Node.js"
        uses: actions/setup-node@v1
        with:
          node-version: 12.x
      
      - name: "Install Node Packages"
        run: npm ci

      - name: "Lint - Sass & Javascript"
        uses: samuelmeuli/[email protected]
        with:
          github_token: ${{ secrets.github_token }}
          eslint: true
          stylelint: true

  Build:
    runs-on: ubuntu-latest
    needs: Lint # Only run the build if linting suceeded.

    steps:
      - name: Test
        run: ls -la

swift-format official treats lint warnings as success

It seems lint-action doesn't relay lint warnings generated by swift-format official.

Run log:

Verifying setup for swift-format…
Verified swift-format setup
Will use swift-format to check the files with extensions swift
Linting files in /__w/repo/repo with swift-format…
/__w/repo/repo/ThumbnailContainerViewController.swift:15:1: warning: [BeginDocumentationCommentWithOneLineSummary]: terminate this sentence with a period: "Adopted by inner/child view controllers to specify  positioning of the thumnail overlay"
/__w/repo/repo/ThumbnailContainerViewController.swift:47:39: warning: [NeverUseImplicitlyUnwrappedOptionals]: use ThumbnailContainerView or ThumbnailContainerView? instead of ThumbnailContainerView!
swift-format found no issues (success)

SHA of last commit is "b979..."
Creating GitHub check with 0 annotations for swift-format…
swift-format check created successfully

And the parameters to configure the action:

github_token: ***
    auto_fix: false
    swift_format_official: true
    git_name: Lint Action
    commit_message: Fix code style issues with ${linter}
    stylelint: false
    stylelint_extensions: css,sass,scss
    gofmt: false
    gofmt_extensions: go
    golint: false
    golint_extensions: go
    eslint: false
    eslint_extensions: js
    prettier: false
    prettier_extensions: css,html,js,json,jsx,md,sass,scss,ts,tsx,vue,yaml,yml
    xo: false
    xo_extensions: js
    black: false
    black_extensions: py
    flake8: false
    flake8_extensions: py
    mypy: false
    mypy_extensions: py
    rubocop: false
    rubocop_extensions: rb
    swiftformat: false
    swiftformat_extensions: swift
    swift_format_lockwood: false
    swift_format_lockwood_extensions: swift
    swift_format_official_extensions: swift
    swiftlint: false
    swiftlint_extensions: swift

Action should only run `git push` if an auto-fix commit was created

In this code pushChanges is triggered even if there are no new commits. I've noticed a couple of issues with this:

  • it re-creates deleted branches
  • it can cause an error if the branch has been updated since the build started, even if there is no autofix

Would be nice to trigger a git push only if there are new commits. And ideally the git push would quietly fail if the branch has been updated since presumably a new run will be triggered.

Sample log of ESLint bombing on push without any changes:
Screen Shot 2020-01-24 at 11 38 39 AM

Overview of result in the Check output title

Right now the linter Check is re-using the linter name for the output title which results in a view like this:
Screen Shot 2020-01-08 at 3 39 44 PM

A more typical title would include a summary of the results:
Screen Shot 2020-01-08 at 3 36 35 PM

I'd suggest something like "No errors found" or "1 error and 2 warnings" etc as the Check title. Might work to use the same value you're using for summary now.

ESLint parsing error

I just got this error on an action and I'm not sure what's causing it, running eslint --no-color --format json "." outputs no error.

 Error: ESLint error: Parsing error: Unexpected token ...
    at Function.parseOutput (/home/runner/work/_actions/samuelmeuli/lint-action/v1/src/linters/eslint.js:86:12)
    at runAction (/home/runner/work/_actions/samuelmeuli/lint-action/v1/src/index.js:86:30)
/home/runner/work/_actions/samuelmeuli/lint-action/v1/src/index.js:16
	throw new Error(`Exiting because of unhandled promise rejection`);
	^

Error: Exiting because of unhandled promise rejection
    at process.<anonymous> (/home/runner/work/_actions/samuelmeuli/lint-action/v1/src/index.js:16:8)
    at process.emit (events.js:210:5)
    at processPromiseRejections (internal/process/promises.js:201:33)
    at processTicksAndRejections (internal/process/task_queues.js:94:32)

Exit Code and Status

Most probably, I'm missing something, but ESLint and Prettier does not stop workflow and have green checkmark even with errors.

As a result code with lint errors get published.

This is my config:

      - name: Run linters
        uses: samuelmeuli/lint-action@v1
        with:
          github_token: ${{ secrets.github_token }}
          eslint: true
          eslint_extensions: js,jsx,ts,tsx,vue
          eslint_args: --max-warnings 0
          prettier: true
          prettier_extensions: json,less,css,md,gql,graphql,html,yaml
          prettier_args: --ignore-path .eslintignore

image

By the way, this workflow is for push event.

Add shfmt

shfmt is a great linter for shell scripts to ensure a coding style.

Fails with "unhandled promise rejection" when using SwiftLint

I just tried to use this action for SwiftLint, but I'm getting this error:

null
/home/runner/work/_actions/samuelmeuli/lint-action/v1.5.0/src/index.js:13
	throw new Error(`Exiting because of unhandled promise rejection`);
	^

Error: Exiting because of unhandled promise rejection
    at process.<anonymous> (/home/runner/work/_actions/samuelmeuli/lint-action/v1.5.0/src/index.js:13:8)
    at process.emit (events.js:210:5)
    at processPromiseRejections (internal/process/promises.js:201:33)
    at processTicksAndRejections (internal/process/task_queues.js:94:32)

Here's my job configuration:

  swiftlint:
    runs-on: ubuntu-latest
    steps:
    - name: Lint Action
      uses: samuelmeuli/[email protected]
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        swiftlint: true

Not working with forks

Run samuelmeuli/[email protected]
Fetching all remote Git branches
From https://github.com/Netflix/dispatch
Checking out the "remove_unused_args" branch
 * [new branch]      bugfix/stable-time -> origin/bugfix/stable-time
 * [new branch]      develop            -> origin/develop
 * [new branch]      docs               -> origin/docs
 * [new branch]      feature/dashboard  -> origin/feature/dashboard
 * [new branch]      feature/update-incident-document -> origin/feature/update-incident-document
 * [new branch]      master             -> origin/master
error: pathspec 'remove_unused_args' did not match any file(s) known to git
Error: Command failed: git checkout remove_unused_args
error: pathspec 'remove_unused_args' did not match any file(s) known to git

    at checkExecSyncError (child_process.js:621:11)
    at execSync (child_process.js:657:15)
    at run (/home/runner/work/_actions/samuelmeuli/lint-action/v1.2.0/src/utils/action.js:69:18)
    at Object.checkOutBranch (/home/runner/work/_actions/samuelmeuli/lint-action/v1.2.0/src/git.js:9:2)
    at runAction (/home/runner/work/_actions/samuelmeuli/lint-action/v1.2.0/src/index.js:35:7)
    at Object.<anonymous> (/home/runner/work/_actions/samuelmeuli/lint-action/v1.2.0/src/index.js:93:1)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14) {
  status: 1,
  signal: null,
  output: [
    null,
    '',
    "error: pathspec 'remove_unused_args' did not match any file(s) known to git\n"
  ],
  pid: 3775,
  stdout: '',
  stderr: "error: pathspec 'remove_unused_args' did not match any file(s) known to git\n"
}
/home/runner/work/_actions/samuelmeuli/lint-action/v1.2.0/src/index.js:15
	throw new Error(`Exiting because of unhandled promise rejection`);
	^

Workflow file here: https://github.com/Netflix/dispatch/blob/develop/.github/workflows/list_and_test.yml

Rejected Remote Issue

Hi,

I've been using lint-action for a while now and most of the time it's been fine, however, I've noticed after creating a new "feature" and my linitng task is failing. I get the following output:

image

Im not entirely sure what I can do to solve this issue, is there a way to get a new github token for the current branch or is this related to the token scoping Github has put in place ?

I really want to add this to our Github flow at work, I've used in all my personal projects and I love it, but I keep getting errors like this and I don't understand them fully or how to fix them.

Any help would greatly be appreciated 👍

Project Link: https://github.com/AlexMachin1997/TheOpenMovieDB-React-Example/actions

Only lint modified files

I was going through the codebase to see how feasible to add this feature because we currently need it.

Suggestion

I was thinking of adding an extra param [linter]_only_changed_files: boolean (we can decide on the best name to go with).

Then checking doing a quick diff of the current branch with

FILES = git diff --diff-filter=$filter --name-only $baseBranch | grep -E $extensions

where:

I see you already swap branch for hasFork here: https://github.com/samuelmeuli/lint-action/blob/a820202c34156c11c68a7c534178ac66e12758b9/src/git.js#L22

We just need to do the same thing with the base repository:

  • check if it's a fork, if so fetch it and add it to maybe base-fork remote locally
  • else if it's not a fork, we don't need to fetch
  • with the above steps, we can easily infer the base remote and branch name

Don't know if this is what you want to support @samuelmeuli else I can spin up a PR for this.

@samuelmeuli wdyt?

Custom repository path

When creating a github workflow, it is sometimes useful to clone the repository (or multiple repositories) a level or two down from the default. e.g. to build and install a linter.

It would be useful to have a `repo-dir' option (defaulting to '.') from within which lint-action would run.

⚠️ Not working with forks

Creating annotations and auto-fixes works as expected when the code is on a branch in the same repository.

Unfortunately, it currently doesn't seem work with pull requests from forks: The action has no permission to push auto-fix changes or create annotations.

Use linter exit code to determine check result

I tried out the rubocop linter in my project and I noticed that when I have warnings:
Screen Shot 2020-01-06 at 4 14 32 PM

I still get a green check:
Screen Shot 2020-01-06 at 4 14 24 PM

That's not the way that the typical rubocop setup works, usually those errors would return a non-zero exit code and fail the build. I wouldn't even know I needed to look for errors unless I click into the Detail screen.

I noticed that here you're only considering errors in the Check status:
https://github.com/samuelmeuli/lint-action/blob/a838ab16415bb1752bb9d77b4ce13fa80bfcaef6/src/github.js#L75

Would you consider failing on warnings as well? Or make that configurable?

Auto-fixing on pull requests is not committing

I'm attempting to run an auto-fixing Black linter, and it changes files but then fails to actually commit them.

name: Run Linters

on:
  pull_request:
    paths:
      - 'c***p/**.py'

jobs:
  run-python-linter:
    name: Run Python Linter
    runs-on: ubuntu-latest

    steps:
      - name: Check out Git repository
        uses: actions/checkout@v2

      - name: Set up Python
        uses: actions/setup-python@v1
        with:
          python-version: 3.7

      - name: Install Python dependencies
        run: pip install black

      - name: Run linters
        uses: samuelmeuli/lint-action@v1
        with:
          github_token: ${{ secrets.github_token }}

          black: true
          black_args: -t py37 -l 120 --exclude "/*scripts*"
          black_dir: c****d
          auto_fix: true
          commit_message: Fix code style issues with ${linter}

When I push to a branch that is in pull request, I get the following:

Will use Black to check the files with extensions py
Linting and auto-fixing files in /home/runner/work/Base/B***ad with Black…
reformatted /home/runner/work/Base/Base/c***views.py
All done! ✨ 🍰 ✨
1 file reformatted, 170 files left unchanged.
Black found no issues (success)

SHA of last commit is "704312c7d00bc047a4a552f56760a3f6f8e7dd2a"
Creating GitHub check with 0 annotations for Flake8…
Creating GitHub check with 0 annotations for Black…

I've starred out some file names and directories, sorry for the silly paranoia but it is a private corporate repository. Nonetheless, everything seems to be operating fine, it's finding a file that is indeed out of whack and is reformatting it - it just doesn't seem to recognize that there have been Git changes. I'm guessing this is because of the change to check for changes before committing? When I run Black and then "git diff-index --cached HEAD" on my own machine, it tells me there aren't changes even though there are. Is it possible that the "--cached" option is causing problems?

A potential confounding issue is that the pull request is the one that actually includes the linter workflow.

Advantage over run yarn lint ?

Hi,

I'm sorry for posting the question here.
I'm getting to know github actions. I wonder what is the advantage of this action over simple run: yarn lint ?

Allow passing files to check into linters

We've got a large legacy repo and I'd like to implement a Github Action to only lint changed files. Running a linter on the entire repo is not currently a possibility.

I'm using https://github.com/trilom/file-changes-action to detect these files, but it looks like the lint action has no way of passing them into the linters.

E.g. for Rubocop, it automatically adds a "." to the command which forces all files under the directory to be linted.

It'd be great if we could make this a general feature. Failing that I can look at fixing rubocop so it allows for passed-in files (the "." should be redundant).

ESLint error when running in subdirectory

When trying to run ESLint I always end up with this error

Verifying setup for ESLint…
Verified ESLint setup
Will use ESLint to check the files with extensions js
Linting files in /home/runner/work/aftershokz/aftershokz/scripts/ with ESLint…
Error: Error parsing ESLint JSON output: Unexpected end of JSON input.

Running ESLint locally with the cli works so I'm not sure what's causing this error.

Here's my yml file

name: Lint

on: pull_request

jobs:
  run-linters:
    name: Run linters
    runs-on: ubuntu-latest

    steps:
      - name: Check out Git repository
        uses: actions/checkout@v2

      - name: Set up Node.js
        uses: actions/setup-node@v1
        with:
          node-version: 12

      - name: Install Node.js dependencies
        run: npm install

      - name: Run linters
        uses: samuelmeuli/lint-action@v1
        with:
          github_token: ${{ secrets.github_token }}
          eslint: true
          eslint_dir: scripts/
          stylelint: true
          stylelint_dir: styles/

Add `[linter]_args` option

This option could allow users to pass additional command-line arguments to the linting command. E.g. useful if users want GitHub checks to fail if there are warnings (see #10).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.