Skip to content

Commit 14cfcd1

Browse files
committed
Format source code and run git diff instead of listing first
The diff yields more insightful results than `swift-format lint`
1 parent b639ffe commit 14cfcd1

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

.github/workflows/pull_request.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,34 @@ jobs:
4444
swift /tmp/cross-pr-checkout.swift "${{ github.repository }}" "${{ github.event.number }}"
4545
- name: Build
4646
run: swift build --configuration release
47+
- name: Write check script
48+
run: |
49+
cat > /tmp/check-formatting.sh <<EOL
50+
#!/usr/bin/env sh
51+
set -ex
52+
cd "$1"
53+
# Format and run `git diff` first because this yields more insightful results than `swift-format lint`
54+
.build/release/swift-format --in-place --parallel --recursive .
55+
git diff
56+
# Linting may discover issues that weren't changed during formatting (such as diagnosing lowercase classes). Check that we didn't introduce any new lint errors.
57+
.build/release/swift-format lint --parallel --recursive --strict .
58+
EOL
59+
chmod a+x /tmp/check-formatting.sh
4760
- name: Format swift-format
48-
run: .build/release/swift-format lint --parallel --recursive --strict .
61+
run: /tmp/check-formatting.sh .
4962
- name: Checkout swift-syntax
5063
uses: actions/checkout@v4
5164
with:
5265
repository: swiftlang/swift-syntax
5366
persist-credentials: false
5467
path: swift-syntax
5568
- name: Format swift-syntax
56-
run: .build/release/swift-format lint --parallel --recursive --strict swift-syntax
69+
run: /tmp/check-formatting.sh swift-syntax
5770
- name: Checkout sourcekit-lsp
5871
uses: actions/checkout@v4
5972
with:
6073
repository: swiftlang/sourcekit-lsp
6174
persist-credentials: false
6275
path: sourcekit-lsp
6376
- name: Format sourcekit-lsp
64-
run: .build/release/swift-format lint --parallel --recursive --strict sourcekit-lsp
77+
run: /tmp/check-formatting.sh sourcekit-lsp

0 commit comments

Comments
 (0)