How to Run SwiftLint in GitHub Actions
Install SwiftLint with Homebrew and run it in strict mode so any warning fails the CI job.
SwiftLint ships as a Homebrew formula. Install it, then run swiftlint lint --strict so warnings become errors and the gate is enforced. Use --reporter github-actions-logging for inline annotations.
Steps
- Install SwiftLint with
brew install swiftlint. - Run
swiftlint lint --strictto fail on any violation. - Add
--reporter github-actions-loggingfor inline PR annotations.
Workflow
.github/workflows/ci.yml
jobs:
lint:
runs-on: macos-latest
env:
HOMEBREW_NO_AUTO_UPDATE: '1'
steps:
- uses: actions/checkout@v4
- run: brew install swiftlint
- run: swiftlint lint --strict --reporter github-actions-loggingGotchas
--strictturns warnings into a non-zero exit, so an unfixed warning blocks the merge.- Commit a
.swiftlint.ymlso local and CI runs use the same enabled rules.
Related guides
How to Install a Tool With Homebrew in GitHub ActionsInstall a CLI tool on a GitHub Actions macOS runner with brew install, pinning auto-update off so the step st…
How to Run xcbeautify on xcodebuild Output in GitHub ActionsPipe xcodebuild output through xcbeautify on a GitHub Actions macOS runner for readable logs and GitHub annot…