Skip to content

Instantly share code, notes, and snippets.

@kjlape
Last active October 23, 2024 14:17
Show Gist options
  • Save kjlape/bce22a6f3e27af4cef336c115d8b2ad0 to your computer and use it in GitHub Desktop.
Save kjlape/bce22a6f3e27af4cef336c115d8b2ad0 to your computer and use it in GitHub Desktop.
A simple linter + pull request flow for GitHub Actions
  • Add lint.yml under .github/workflows/
  • Add the swiftlint stub under bin/
  • Don't forget to chmod +x bin/swiftlint
name: lint
on:
pull_request:
push:
branches: [ master ]
jobs:
lint-swift:
if: ${{ !startsWith(github.head_ref, 'dependabot/') }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Lint
run: bin/swiftlint --fix .
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
title: "[lint] Fix SwiftLint issues in #${{ github.event.pull_request.number }}"
base: ${{ github.head_ref }}
branch: ci-lint/swift/${{ github.ref_name }}
body: |
Here are some helpful linter fixes for your swift code in #${{ github.event.pull_request.number }}
#!/usr/bin/env bash
if [[ -z "${CI}" ]]; then
echo "Running locally"
else
echo "Running in CI"
function swiftlint() {
docker run --rm -v "$(pwd):/workdir" --workdir /workdir ghcr.io/realm/swiftlint:latest swiftlint "$@"
}
fi
swiftlint $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment