Skip to content

Commit 43b34b7

Browse files
committed
chore: SwiftLint 실행 방식 정리
1 parent 2538b4e commit 43b34b7

12 files changed

Lines changed: 88 additions & 24 deletions

File tree

.github/workflows/ci.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ jobs:
5858
install: true
5959
cache: true
6060

61+
- name: Install SwiftLint
62+
shell: bash
63+
run: |
64+
set -euo pipefail
65+
66+
brew list swiftlint >/dev/null 2>&1 || brew install swiftlint
67+
swiftlint version
68+
6169
- name: Cache SwiftPM
6270
uses: actions/cache@v5
6371
with:
@@ -255,6 +263,14 @@ jobs:
255263
install: true
256264
cache: true
257265

266+
- name: Install SwiftLint
267+
shell: bash
268+
run: |
269+
set -euo pipefail
270+
271+
brew list swiftlint >/dev/null 2>&1 || brew install swiftlint
272+
swiftlint version
273+
258274
- name: Cache SwiftPM
259275
uses: actions/cache@v5
260276
with:

.github/workflows/testflight.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ jobs:
9090
install: true
9191
cache: true
9292

93+
- name: Install SwiftLint
94+
shell: bash
95+
run: |
96+
set -euo pipefail
97+
98+
brew list swiftlint >/dev/null 2>&1 || brew install swiftlint
99+
swiftlint version
100+
93101
- name: Generate Xcode workspace with Tuist
94102
shell: bash
95103
run: |

Application/DevLogApp/Project.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let project = Project(
77
disableBundleAccessors: true,
88
disableSynthesizedResourceAccessors: true
99
),
10-
packages: DevLogPackages.lintOnlyPackages,
10+
packages: DevLogPackages.defaultPackages,
1111
settings: .devlogProject(versionXcconfigPath: "../Shared/Version.xcconfig"),
1212
targets: [
1313
.target(
@@ -24,6 +24,9 @@ let project = Project(
2424
"Sources/Resource/Localizable.xcstrings",
2525
],
2626
entitlements: .file(path: "Sources/Resource/DevLog.entitlements"),
27+
scripts: [
28+
DevLogScripts.swiftLint(sourcePath: "Sources"),
29+
],
2730
dependencies: [
2831
.project(target: "DevLogPresentation", path: "../DevLogPresentation"),
2932
.project(target: "DevLogPersistence", path: "../DevLogPersistence"),
@@ -33,13 +36,13 @@ let project = Project(
3336
.project(target: "DevLogCore", path: "../DevLogCore"),
3437
.project(target: "DevLogWidgetCore", path: "../../Widget/DevLogWidgetCore"),
3538
.project(target: "DevLogWidgetExtension", path: "../../Widget/DevLogWidgetExtension"),
36-
DevLogPackages.swiftLintPlugin,
3739
],
3840
settings: .devlog(
3941
versionXcconfigPath: "Sources/Resource/App.xcconfig",
4042
base: [
4143
"ASSETCATALOG_COMPILER_APPICON_NAME": "AppIcon",
4244
"CODE_SIGN_STYLE": "Automatic",
45+
"ENABLE_USER_SCRIPT_SANDBOXING": "NO",
4346
"PRODUCT_MODULE_NAME": "DevLogApp",
4447
],
4548
debug: [

Application/DevLogCore/Project.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ let project = Project.devlogFramework(
77
versionXcconfigPath: "../Shared/Version.xcconfig",
88
frameworkInfoPlistPath: "../Shared/InfoPlists/Framework-Info.plist",
99
testsInfoPlistPath: "../Shared/InfoPlists/UnitTests-Info.plist",
10-
packages: DevLogPackages.lintOnlyPackages,
10+
packages: DevLogPackages.defaultPackages,
1111
hasTests: false
1212
)

Application/DevLogData/Project.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let project = Project.devlogFramework(
77
versionXcconfigPath: "../Shared/Version.xcconfig",
88
frameworkInfoPlistPath: "../Shared/InfoPlists/Framework-Info.plist",
99
testsInfoPlistPath: "../Shared/InfoPlists/UnitTests-Info.plist",
10-
packages: DevLogPackages.lintOnlyPackages,
10+
packages: DevLogPackages.defaultPackages,
1111
dependencies: [
1212
.project(target: "DevLogDomain", path: "../DevLogDomain"),
1313
.project(target: "DevLogCore", path: "../DevLogCore"),

Application/DevLogDomain/Project.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let project = Project.devlogFramework(
77
versionXcconfigPath: "../Shared/Version.xcconfig",
88
frameworkInfoPlistPath: "../Shared/InfoPlists/Framework-Info.plist",
99
testsInfoPlistPath: "../Shared/InfoPlists/UnitTests-Info.plist",
10-
packages: DevLogPackages.lintOnlyPackages,
10+
packages: DevLogPackages.defaultPackages,
1111
dependencies: [
1212
.project(target: "DevLogCore", path: "../DevLogCore"),
1313
],

Application/DevLogPersistence/Project.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let project = Project.devlogFramework(
77
versionXcconfigPath: "../Shared/Version.xcconfig",
88
frameworkInfoPlistPath: "../Shared/InfoPlists/Framework-Info.plist",
99
testsInfoPlistPath: "../Shared/InfoPlists/UnitTests-Info.plist",
10-
packages: DevLogPackages.lintOnlyPackages,
10+
packages: DevLogPackages.defaultPackages,
1111
dependencies: [
1212
.project(target: "DevLogData", path: "../DevLogData"),
1313
.project(target: "DevLogCore", path: "../DevLogCore"),

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ MVVM을 기반으로 하되, ViewModel 상태 관리에는 MVI 형태의 단방
176176

177177
```bash
178178
brew install mise
179+
brew install swiftlint
179180
mise install
180181
```
181182

Tuist/ProjectDescriptionHelpers/Project+Packages.swift

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import ProjectDescription
22

33
public enum DevLogPackages {
4-
public static let swiftLintPackage: Package = .package(
5-
url: "https://github.com/realm/SwiftLint",
6-
.upToNextMajor(from: "0.62.1")
7-
)
84
public static let markdownUIPackage: Package = .package(
95
url: "https://github.com/gonzalezreal/swift-markdown-ui.git",
106
.upToNextMajor(from: "2.4.1")
@@ -26,11 +22,6 @@ public enum DevLogPackages {
2622
.upToNextMajor(from: "1.1.0")
2723
)
2824

29-
public static let swiftLintPlugin: TargetDependency = .package(
30-
product: "SwiftLintBuildToolPlugin",
31-
type: .plugin
32-
)
33-
3425
public static let presentationPackageDependencies: [TargetDependency] = [
3526
.package(product: "MarkdownUI"),
3627
.package(product: "OrderedCollections"),
@@ -47,20 +38,53 @@ public enum DevLogPackages {
4738
.package(product: "Nexa"),
4839
]
4940

50-
public static let lintOnlyPackages: [Package] = [
51-
swiftLintPackage,
52-
]
41+
public static let defaultPackages: [Package] = []
5342

5443
public static let presentationPackages: [Package] = [
55-
swiftLintPackage,
5644
markdownUIPackage,
5745
swiftCollectionsPackage,
5846
]
5947

6048
public static let infraPackages: [Package] = [
61-
swiftLintPackage,
6249
firebasePackage,
6350
googleSignInPackage,
6451
nexaPackage,
6552
]
6653
}
54+
55+
public enum DevLogScripts {
56+
public static func swiftLint(sourcePath: String) -> TargetScript {
57+
TargetScript.pre(
58+
script: """
59+
export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH"
60+
61+
swiftLintPath="$(command -v swiftlint || true)"
62+
if [ -z "$swiftLintPath" ]; then
63+
echo "error: SwiftLint is not installed. Run 'brew install swiftlint'."
64+
exit 1
65+
fi
66+
67+
configPath="${SRCROOT}/../../.swiftlint.yml"
68+
sourcePathName="\(sourcePath)"
69+
lintSourcePath="${SRCROOT}/${sourcePathName}"
70+
71+
if [ "$sourcePathName" != "." ]; then
72+
"$swiftLintPath" lint --config "$configPath" "$lintSourcePath"
73+
else
74+
status=0
75+
while IFS= read -r swiftFilePath; do
76+
"$swiftLintPath" lint --config "$configPath" "$swiftFilePath" || status=$?
77+
done < <(find "$lintSourcePath" -name "*.swift" -not -path "*/Derived/*" -not -name "Project.swift")
78+
exit "$status"
79+
fi
80+
""",
81+
name: "SwiftLint",
82+
inputPaths: [
83+
"$(SRCROOT)/../../.swiftlint.yml",
84+
"$(SRCROOT)/\(sourcePath)",
85+
],
86+
basedOnDependencyAnalysis: false,
87+
shellPath: "/bin/bash"
88+
)
89+
}
90+
}

Tuist/ProjectDescriptionHelpers/Project+Templates.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public extension Project {
77
versionXcconfigPath: Path,
88
frameworkInfoPlistPath: Path,
99
testsInfoPlistPath: Path,
10-
packages: [Package] = DevLogPackages.lintOnlyPackages,
10+
packages: [Package] = DevLogPackages.defaultPackages,
1111
dependencies: [TargetDependency] = [],
1212
hasTests: Bool
1313
) -> Project {
@@ -19,8 +19,16 @@ public extension Project {
1919
bundleId: bundleId,
2020
infoPlist: .file(path: frameworkInfoPlistPath),
2121
sources: ["Sources/**/*.swift"],
22-
dependencies: dependencies + [DevLogPackages.swiftLintPlugin],
23-
settings: .devlog(versionXcconfigPath: versionXcconfigPath)
22+
scripts: [
23+
DevLogScripts.swiftLint(sourcePath: "Sources"),
24+
],
25+
dependencies: dependencies,
26+
settings: .devlog(
27+
versionXcconfigPath: versionXcconfigPath,
28+
base: [
29+
"ENABLE_USER_SCRIPT_SANDBOXING": "NO",
30+
]
31+
)
2432
),
2533
]
2634

0 commit comments

Comments
 (0)