Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run SwiftLint on pull request GitHub actions

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/[email protected]
        with:
          fetch-depth: ${{ env.FETCH_DEPTH }}

      - name: Restore Gem Cache
        uses: actions/[email protected]
        with:
          path: vendor/bundle
          key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
          restore-keys: ${{ runner.os }}-gem-

      - name: Restore Pod Cache
        uses: actions/[email protected]
        with:
          path: Pods
          key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}
          restore-keys: ${{ runner.os }}-pods-

      - name: Setup Ruby
        uses: ruby/[email protected]
        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.

like image 999
aashish nagar Avatar asked Aug 02 '26 08:08

aashish nagar


1 Answers

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.

like image 137
Grzegorz Krukowski Avatar answered Aug 05 '26 14:08

Grzegorz Krukowski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!