GithubHelp home page GithubHelp logo

norio-nomura / action-swiftlint Goto Github PK

View Code? Open in Web Editor NEW
357.0 8.0 52.0 171 KB

GitHub Action for SwiftLint

License: MIT License

Swift 70.55% Dockerfile 10.81% Shell 18.63%
github-actions- github-checks-api swiftlint swift docker

action-swiftlint's Introduction

GitHub Action for SwiftLint

This Action executes SwiftLint and generates annotations from SwiftLint Violations.

Usage

An example workflow(.github/workflows/swiftlint.yml) to executing SwiftLint follows:

name: SwiftLint

on:
  pull_request:
    paths:
      - '.github/workflows/swiftlint.yml'
      - '.swiftlint.yml'
      - '**/*.swift'

jobs:
  SwiftLint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - name: GitHub Action for SwiftLint
        uses: norio-nomura/[email protected]
      - name: GitHub Action for SwiftLint with --strict
        uses: norio-nomura/[email protected]
        with:
          args: --strict
      - name: GitHub Action for SwiftLint (Only files changed in the PR)
        uses: norio-nomura/[email protected]
        env:
          DIFF_BASE: ${{ github.base_ref }}
      - name: GitHub Action for SwiftLint (Different working directory)
        uses: norio-nomura/[email protected]
        env:
          WORKING_DIRECTORY: Source

Secrets

  • Specifying GITHUB_TOKEN to secrets is required to using Check Run APIs for generating annotations from SwiftLint Violations.
  • Since 3.0.0, GITHUB_TOKEN is no longer needed.

Example

Here is an example that actually works. screenshot

Author

Norio Nomura

License

MIT

action-swiftlint's People

Contributors

axelguilmin avatar m-herold avatar norio-nomura 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

action-swiftlint's Issues

Support for paths or filenames with spaces

When using the DIFF_BASE to only lint files changed in a PR, file paths containing spaces will be ignored. I've tried playing around with it myself but wasn't able to get bash to escape/pass the strings to swift lint correctly.

Ideally, both of the cases below should be supported:

Sources/Supporting Files/Test.swift
Sources/My File.swift

Option to run swiftlint only on changed files regression?

Hi!
I'm using this action with the latest update that lints only files that have been changed in the PR.

This is great and it's a very nice addition!

However, if now a PR has changes in files within an excluded folder, for example a tests folder, those files will also be linted, regardless of the .swiftlint.yml configuration.

Is this the expected behaviour?

Thank you in advance,
Federico

(cc @axelguilmin)

Swiftlint is still checking unchanged files

SwiftLint is still checking unchanged files in my pull-requests even though I'm using the following swiftlint.yml config

name: SwiftLint

on:
  pull_request:
    paths:
      - '.github/workflows/swiftlint.yml'
      - '.swiftlint.yml'
      - '**/*.swift'
      - '!Pods/**'

jobs:
  SwiftLint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - name: GitHub Action for SwiftLint (Only files changed in the PR)
        uses: norio-nomura/[email protected]
        env:
          DIFF_BASE: ${{ github.base_ref }}

Support PR reviews

Hi! Awesome action, thanks!

Have you considered also supporting PR reviews?

Instead of hiding the comment in the "Changed files" section, this also starts a review and posts it in the conversation, e.g.:

image

Action posts only 10 Warnings

For some reason, action-swiftlint posts only 10 Warnings, all other warnings are not posted into PR even I can see them in log output during execution.

Done linting! Found 47 violations, 0 serious in 331 files.

Screenshot 2019-11-21 at 11 33 35

PS: thanks for this action the idea is very helpful!

Action fails after running swiftlint

The action seems to run SwiftLint with no issues, but then fails with this error:

Docker run failed with exit code 2

image

I have a .swiftlint.yml file that includes some disabled rules, excluded paths. Other than that nothing odd about my repo.

I can run SwiftLint successfully on my local machine (macOS).

SwiftLint checking Pods even though .swiftlint.yml excludes them.

my .swiftlint.yml file:

disabled_rules: # rule identifiers to exclude from running
opt_in_rules: # some rules are only opt-in
  - missing_docs
  # Find all the available rules by running:
  # swiftlint rules
 
excluded: # paths to ignore during linting. Takes precedence over `included`.
  - Carthage
  - Pods
analyzer_rules: # Rules run by `swiftlint analyze` (experimental)

# configurable rules can be customized from this configuration file
# binary rules can set their severity level
force_cast: warning # implicitly
force_try:
  severity: warning # explicitly
# rules that have both warning and error levels, can set just the warning level
# implicitly
missing_docs:
  error:
  - public
  warning:
  - internal
  - private
line_length: 
  warning: 230
  error: 500
  ignores_comments: true
# they can set both implicitly with an array
type_body_length:
  - 300 # warning
  - 400 # error
# or they can set both explicitly
file_length:
  warning: 500
  error: 1200
# naming rules can set warnings/errors for min_length and max_length
# additionally they can set excluded names
type_name:
  min_length: 4 # only warning
  max_length: # warning and error
    warning: 40
    error: 50
  excluded: iPhone # excluded via string
  allowed_symbols: ["_"] # these are allowed in type names
identifier_name:
  min_length: # only min_length
    error: 4 # only error
  excluded: # excluded via string array
    - id
    - vc
    - URL
    - GlobalAPIKey
    - i
    - db
    - url
    - row
    - key
reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit, html, emoji, sonarqube, markdown)

my GitHub action

name: SwiftLint

on:
  pull_request:
    paths:
      - '.github/workflows/swiftlint.yml'
      - '.swiftlint.yml'
      - '**/*.swift'

jobs:
  SwiftLint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - name: GitHub Action for SwiftLint
        uses: norio-nomura/[email protected]
      - name: GitHub Action for SwiftLint with --strict
        uses: norio-nomura/[email protected]
        with:
          args: 
      - name: GitHub Action for SwiftLint (Only files changed in the PR)
        uses: norio-nomura/[email protected]
        env:
          DIFF_BASE: ${{ github.base_ref }}

Won't work on Github CI

I tried to use the action on Github CI, but it won't work. Here is my workflow:

on: pull_request
name: Lint
jobs:
  lint:
    name: Lint
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
    - uses: norio-nomura/action-swiftlint@master
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

In log I see the error message: Current Action `norio-nomuraaction-swiftlint` not found!

SwiftLint has changed calculation of the root path

With SwiftLint version 0.41.0 which has been release yesterday, SwiftLint has changed the calculation of the root path when a directory in the tree is passed as a path argument.

Prior to this version it was possible to define a path argument, whereas SwiftLint then took the config file and all excluded files relative to this path argument. This seems to have changed, whereas this awesome GitHub action does not work properly anymore in the case (a) your source code is not located in the root folder of your repository, and (b) you have defined excluded files/path in a configuration file which are relative to this source code folder (e.g., to be used within an Xcode build phase). In those cases this GitHub action can not be used anymore, due to the following changes of SwiftLint:

realm/SwiftLint@6d77deb

A similar issue has already been addressed in pull request #24.

Example:

  • Source code and .swiftlint.yml are located in: src/
  • .swiftlint.yml contains excluded paths which are relative to this src/ folder:
excluded:
 - Carthage
  • Valid usage before SwiftLint version 0.41.0:
uses: norio-nomura/[email protected]
with:
  args: --path src --config .swiftlint.yml

Checking only Files in PR - .swiftlint.yml is not respected

When using the configuration option

env:
 - name: SwiftLint
      uses: norio-nomura/[email protected]
      env:
        DIFF_BASE: ${{ github.base_ref }}
      with:
        args: --strict

in order to check only files of the current PR, my .swiftlint.yml configuration (containing some exclusion filters) is not taken into account.

Removing the line DIFF_BASE: ${{ github.base_ref }} re-enables my .swiftlint.yml configuration.

Pinned swiftlint version support

Hey, when our .swiftlint.yml specifies a specific swiftlint_version to lint our project with, it causes our builds to start to fail when the Action starts using a more recent version of Swiftlint.

Happy to look into it myself, but is there a way to pin the Swiftlint version that the action (or Docker image) are using? Or was it an explicit decision to track the latest release?

Can't run GitHub Action for SwiftLint (Only files changed in the PR)

When using the configuration option

     - name: GitHub Action for SwiftLint (Only files changed in the PR)
        uses: norio-nomura/[email protected]
        env:
          DIFF_BASE: ${{ github.base_ref }}

I got this errors.
Screenshot 2023-06-23 at 10 22 45

I tried some solutions on Stackoverflow like:
git config --global --add safe.directory '*'
or
git config --system --add safe.directory '*'
But it doesn't work...

Can't use SwiftLint file in repo

https://github.com/eonist/TestRunner/blob/master/.github/workflows/Tests.yml

But it uses some other SwiftLint file, not the one in the project, any idea how to fix this?

My workflow looks like this:

name: Tests

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
   #Something wrong with swiftlint action, figure it out later
  SwiftLint: ## Adds swift-linting to GH actions
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: GitHub Action for SwiftLint
        uses: norio-nomura/[email protected]
        with:
          args: --config .swiftlint.yml
  build:
    runs-on: macos-latest
    steps:
    - uses: actions/checkout@v2
    - name: Build
      run: swift build -v

Support running on macos runners

Title is pretty self explanatory.

We have our own macos build machine that we hooked up to be a runner (so we dont have to pay for github actions).

It would be nice to be able to run this workflow on a mac machine.

Strict mode

Hi! I see that your tests include the strict mode, but I couldn't find a way to use that with the action itself.

Is there a way to enable it?

Swiftlint and .swiftlint.yml in submodule

We are using config like below:

name: Swift

on:
  pull_request:
    types:
      - opened
      - edited
      - reopened
      - synchronize

jobs:
  swiftlint:
    name: Swiftlint
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          ssh-key: ${{ secrets.SSH_KEY }}
          submodules: recursive
      - name: Swiftlint
        uses: norio-nomura/[email protected]
        with:
          # https://github.com/realm/SwiftLint
          args: --strict --force-exclude
.swiftlint.yml file is excluding:

excluded:
  - Pods
  - SourcePackages
  - fastlane/SnapshotHelper.swift //This one is new!

Locally everything works fine. Our .swiftlint.yml file is in submodule. Checkout is fetching submodules correctly. I've verified commit and it is correct one. Right after checkout we are performing step named Swiftlint and we are constantly getting errors on excluded file fastlane/SnapshotHelper.swift. It seems like despite the fact that submodule fetching is successfull it is still using older (cached?) version of .swiftlint.yml from previous submodule commit.

Currently we are running out of ideas.

Read .swiftlint.yml rules

Hello, do we able to config this with rules which are stated in .swiftlint.yml?
If so, how do we do it?
thanks ๐Ÿ˜ƒ

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.