在GitHub Actions上针对pull request运行SwiftLint

4

我正在Mac-os-11上运行任务。我已经在本地集成了SwiftLint,并且它工作正常。但是,当有人提出PR时,我需要在GitHub actions中运行SwiftLint。我该如何做到这一点?以下是当前的yml文件。

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在本地工作正常,但是当我发起合并请求时,没有出现任何SwiftLint警告。


这个 pull request 目标分支是哪一个?请查看 on.<pull_request|pull_request_target>.<branches|branches-ignore> 的参考文档 -- https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#onpull_requestpull_request_targetbranchesbranches-ignore - TechSolomon
我正在针对任何分支的拉取请求进行操作。 - aashish nagar
我正在寻找一个Bash脚本命令,可以运行SwiftLint并显示所有的Swift Lint警告。 - aashish nagar
1个回答

4

我正在使用这个步骤:

- 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/'

它将swiftlint的警告和错误解析为GitHub注释,这些注释可以立即在摘要中看到。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接