3

I m running jobs on Mac-os-11. I have integrated the SwiftLint locally as well and that is working fine. But When someone raise the pr I need to run the SwiftLint on GitHub actions. How can I do that. Below is the current yml file for actions.

name: Build & Test

on:
  # Run tests when PRs are created or updated
  pull_request:
    types: [opened, synchronize, reopened, ready_for_review]

env:
  # Defines the Xcode version
  DEVELOPER_DIR: /Applications/Xcode_13.0.app/Contents/Developer
  FETCH_DEPTH: 0
  RUBY_VERSION: 2.7.1

defaults:
  run:
    shell: bash

jobs:
  test:
    name: Build & Test
    if: ${{ github.event.pull_request.draft == false }}
    runs-on: macos-11

    steps:
      - name: Checkout Project
        uses: actions/checkout@v2.3.4
        with:
          fetch-depth: ${{ env.FETCH_DEPTH }}

      - name: Restore Gem Cache
        uses: actions/cache@v2.1.3
        with:
          path: vendor/bundle
          key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
          restore-keys: ${{ runner.os }}-gem-

      - name: Restore Pod Cache
        uses: actions/cache@v2.1.3
        with:
          path: Pods
          key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}
          restore-keys: ${{ runner.os }}-pods-

      - name: Setup Ruby
        uses: ruby/setup-ruby@v1.51.1
        with:
          bundler-cache: true
          ruby-version: ${{ env.RUBY_VERSION }}

SwiftLint is working fine locally, But when I raise the pull request no SwiftLint warning are coming.

  • Which branch is the pull request targeting? Check the reference for `on..` -- https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#onpull_requestpull_request_targetbranchesbranches-ignore – TechSolomon Mar 22 '22 at 10:41
  • I m targeting pull request for any branch – aashish nagar Mar 22 '22 at 11:10
  • I m looking for a bash script command that can run the SwiftLint and can show all swift lint warning – aashish nagar Mar 22 '22 at 11:10

1 Answers1

2

I am using this step:

- name: Lint
        run: |
          set -o pipefail
          swiftlint lint --strict --quiet | sed -E 's/^(.*):([0-9]+):([0-9]+): (warning|error|[^:]+): (.*)/::\4 title=Lint error,file=\1,line=\2,col=\3::\5\n\1:\2:\3/'

It parses swiftlint warnings and errors into GitHub annotations which are visible in summary straight away.

Grzegorz Krukowski
  • 18,081
  • 5
  • 50
  • 71