Skip to content

Commit e30c1d8

Browse files
committed
[CI] Add format ignore file
# Motivation Some repositories may want to exclude files from being format checked. # Modification This PR moves the formatting into a separate script and adds an optional `.swiftformatignore` file that can be placed at the repo root similar to the `.licenseignore` file. # Result Repos can now decide what files are ignored when running the formatter.
1 parent 1d25937 commit e30c1d8

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

.github/workflows/soundness.yml

+4-6
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ jobs:
126126
- name: Mark the workspace as safe
127127
# https://github.com/actions/checkout/issues/766
128128
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
129-
- name: Format Swift files
130-
run: git ls-files -z '*.swift' | xargs -0 swift format format --parallel --in-place
131-
- name: Lint Swift files
132-
run: git ls-files -z '*.swift' | xargs -0 swift format lint --strict --parallel
133-
- name: Check format produced no diff
134-
run: GIT_PAGER= git diff --exit-code '*.swift'
129+
- name: Run format check
130+
run: |
131+
apt-get -qq update && apt-get -qq -y install curl
132+
curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/check-swift-format.sh | bash

scripts/check-swift-format.sh

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
##===----------------------------------------------------------------------===##
3+
##
4+
## This source file is part of the SwiftNIO open source project
5+
##
6+
## Copyright (c) 2024 Apple Inc. and the SwiftNIO project authors
7+
## Licensed under Apache License v2.0
8+
##
9+
## See LICENSE.txt for license information
10+
## See CONTRIBUTORS.txt for the list of SwiftNIO project authors
11+
##
12+
## SPDX-License-Identifier: Apache-2.0
13+
##
14+
##===----------------------------------------------------------------------===##
15+
set -euo pipefail
16+
17+
log() { printf -- "** %s\n" "$*" >&2; }
18+
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
19+
fatal() { error "$@"; exit 1; }
20+
21+
excluded_files=""
22+
23+
if [ -f .swiftformatignore ]; then
24+
log "Found swiftformatignore file..."
25+
excluded_files=$(cat .swiftformatignore | xargs -I% printf ":(exclude)% ")
26+
fi
27+
28+
log "Running swift format format..."
29+
git ls-files -z '*.swift' $excluded_files | xargs -0 swift format format --parallel --in-place
30+
31+
log "Running swift format lint..."
32+
33+
git ls-files -z '*.swift' $excluded_files | xargs -0 swift format lint --strict --parallel
34+
35+
log "Checking for modified files..."
36+
37+
GIT_PAGER= git diff --exit-code '*.swift'
38+
39+
log "✅ Found no formatting issues."

0 commit comments

Comments
 (0)