Browse Source

Add SwiftFormat lint check on pull requests (#599)

* Add SwiftFormat lint check on pull requests

Runs swiftformat --lint in a Linux container on every PR using the
same BuildTools pin (SwiftFormat 0.56.1) and flags as the local
Scripts/swiftformat.sh, so CI stays in sync with `swift run swiftformat`
on a developer machine.

Fails the check on any violation without rewriting files — contributors
fix formatting themselves and push, rather than having CI commit back
over their branch.

BuildTools/.build is cached by Package.resolved hash to keep subsequent
runs fast.

* Cancel in-flight lint runs when a newer push lands

Adds a concurrency group so rapid successive pushes to a PR branch
don't stack up multiple Lint runs — the in-progress run is cancelled
as soon as a newer commit arrives.
Jonas Björkert 3 months ago
parent
commit
c4adb9bc08
1 changed files with 37 additions and 0 deletions
  1. 37 0
      .github/workflows/lint.yml

+ 37 - 0
.github/workflows/lint.yml

@@ -0,0 +1,37 @@
+name: Lint
+run-name: Lint (${{ github.head_ref || github.ref_name }})
+
+on:
+  pull_request:
+  workflow_dispatch:
+
+concurrency:
+  group: lint-${{ github.ref }}
+  cancel-in-progress: true
+
+permissions:
+  contents: read
+
+jobs:
+  swiftformat:
+    name: SwiftFormat
+    runs-on: ubuntu-latest
+    container: swift:6.0
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v5
+
+      - name: Cache SwiftFormat build
+        uses: actions/cache@v4
+        with:
+          path: BuildTools/.build
+          key: ${{ runner.os }}-swiftformat-${{ hashFiles('BuildTools/Package.resolved', 'BuildTools/Package.swift') }}
+          restore-keys: |
+            ${{ runner.os }}-swiftformat-
+
+      - name: SwiftFormat --lint
+        run: |
+          swift run -c release --package-path BuildTools swiftformat . \
+            --lint \
+            --header "LoopFollow\n{file}" \
+            --exclude Pods,Generated,R.generated.swift,fastlane/swift,Dependencies,dexcom-share-client-swift