Skip to content

Commit 231a7a1

Browse files
fix(SwiftLint): CI and local running inconsistent versions (#32)
* fix: remove swiftlin from test targets * fix(SwiftLint): CI and local running inconsistent versions
1 parent 33fe749 commit 231a7a1

5 files changed

Lines changed: 148 additions & 76 deletions

File tree

.swiftlint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ disabled_rules:
33
- file_length
44
- non_optional_string_data_conversion
55
- type_body_length
6-
- type_name
6+
- type_name
77
- identifier_name
88
- opening_brace
9-
- function_body_length
9+
- function_body_length
1010

1111
included:
1212
- swift/Sources

dev.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ name: checkout-kit
22

33
up:
44
- packages:
5-
- quicktype
5+
- quicktype
6+
- ruby
7+
- custom:
8+
name: Install bundle packages
9+
met?: BUNDLE_GEMFILE=swift/Gemfile bundle check
10+
meet: BUNDLE_GEMFILE=swift/Gemfile bundle install
611

712
commands:
813
codegen:

swift/.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.4.4

swift/Scripts/lint

Lines changed: 124 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -3,135 +3,192 @@
33
# Check for verbose flag
44
VERBOSE=false
55
if [[ "$*" == *"--verbose"* ]]; then
6-
VERBOSE=true
6+
VERBOSE=true
77
fi
88

99
# Accept --verbose before check/fix
1010
if [[ "$1" == "--verbose" ]]; then
11-
MODE="${2:-check}"
11+
MODE="${2:-check}"
1212
else
13-
MODE="${1:-check}"
13+
MODE="${1:-check}"
1414
fi
1515

1616
# Validate the mode
1717
if [[ "$MODE" != "check" && "$MODE" != "fix" ]]; then
18-
echo "❌ Invalid mode: $MODE"
19-
echo "Usage: $0 [check|fix] [--verbose]"
20-
echo " check: Run linters in check mode (default)"
21-
echo " fix: Run linters in fix mode to auto-fix issues"
22-
echo " --verbose: Show detailed output from linters"
23-
exit 1
18+
echo "❌ Invalid mode: $MODE"
19+
echo "Usage: $0 [check|fix] [--verbose]"
20+
echo " check: Run linters in check mode (default)"
21+
echo " fix: Run linters in fix mode to auto-fix issues"
22+
echo " --verbose: Show detailed output from linters"
23+
exit 1
2424
fi
2525

2626
print_install_instructions() {
27-
echo "🔧 FIX:"
28-
echo " Shopify employee? Run 'dev up'"
29-
echo " Not a Shopify employee? Install Mint and run 'mint bootstrap':"
30-
echo " brew install mint"
31-
echo " mint bootstrap"
32-
echo " See: https://github.com/yonaskolb/Mint"
27+
echo "🔧 FIX:"
28+
echo " Shopify employee? Run 'dev up'"
29+
echo " Not a Shopify employee? Install Mint and run 'mint bootstrap':"
30+
echo " brew install mint"
31+
echo " mint bootstrap"
32+
echo " See: https://github.com/yonaskolb/Mint"
3333
}
3434

3535
if ! command -v mint >/dev/null; then
36-
echo "❌ Mint is not installed"
37-
print_install_instructions
38-
exit 1
36+
echo "❌ Mint is not installed"
37+
print_install_instructions
38+
exit 1
3939
fi
4040

4141
if [ ! -f "Mintfile" ]; then
42-
echo "❌ Mintfile not found in the current directory"
43-
exit 1
42+
echo "❌ Mintfile not found in the current directory"
43+
exit 1
4444
fi
4545

46-
SWIFTLINT="mint run swiftlint"
47-
SWIFTFORMAT="mint run swiftformat"
46+
expected_swiftlint="$(sed -n 's#^realm/SwiftLint@##p' Mintfile)"
47+
expected_swiftformat="$(sed -n 's#^nicklockwood/SwiftFormat@##p' Mintfile)"
48+
49+
if [ -z "$expected_swiftlint" ] || [ -z "$expected_swiftformat" ]; then
50+
echo "❌ Could not read SwiftLint and SwiftFormat versions from Mintfile"
51+
print_install_instructions
52+
exit 1
53+
fi
54+
55+
mint_package_has_version() {
56+
local package_name=$1
57+
local package_version=$2
58+
59+
mint list | awk -v package_name="$package_name" -v package_version="$package_version" '
60+
$1 == package_name { in_package = 1; next }
61+
in_package && $1 !~ /^-/ { exit 1 }
62+
in_package && $1 == "-" && $2 == package_version { found = 1; exit 0 }
63+
END { exit found ? 0 : 1 }
64+
'
65+
}
66+
67+
if ! mint_package_has_version "SwiftLint" "$expected_swiftlint"; then
68+
echo "❌ SwiftLint $expected_swiftlint is not installed"
69+
print_install_instructions
70+
exit 1
71+
fi
72+
73+
if ! mint_package_has_version "SwiftFormat" "$expected_swiftformat"; then
74+
echo "❌ SwiftFormat $expected_swiftformat is not installed"
75+
print_install_instructions
76+
exit 1
77+
fi
78+
79+
swiftlint_bin="$(mint which swiftlint)"
80+
swiftformat_bin="$(mint which swiftformat)"
81+
82+
if [ "$("$swiftlint_bin" version)" != "$expected_swiftlint" ]; then
83+
echo "❌ SwiftLint version mismatch. Expected $expected_swiftlint, found $("$swiftlint_bin" version)"
84+
print_install_instructions
85+
exit 1
86+
fi
87+
88+
if [ "$("$swiftformat_bin" --version)" != "$expected_swiftformat" ]; then
89+
echo "❌ SwiftFormat version mismatch. Expected $expected_swiftformat, found $("$swiftformat_bin" --version)"
90+
print_install_instructions
91+
exit 1
92+
fi
93+
94+
SWIFTLINT="$swiftlint_bin"
95+
SWIFTFORMAT="$swiftformat_bin"
4896

4997
QUIET_FLAG=""
5098
if [[ "$VERBOSE" == "false" ]]; then
51-
QUIET_FLAG="--quiet"
99+
QUIET_FLAG="--quiet"
52100
fi
53101

54102
if [[ "$MODE" == "fix" ]]; then
55-
$SWIFTLINT lint --fix $QUIET_FLAG
103+
$SWIFTLINT lint --fix --no-cache $QUIET_FLAG
56104
fi
57105

58106
# SwiftLint doesn't report errors when running in fix mode
59107
# Running again in strict mode to ensure no errors are missed.
60108
# Run from the directory containing .swiftlint.yml so its `included:` paths
61-
# resolve consistently — in the monorepo that's the repo root, not the
62-
# script's CWD (which is swift/, where Mintfile lives).
109+
# resolve consistently.
63110
PROJECT_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
64-
(cd "$PROJECT_ROOT" && $SWIFTLINT lint --strict $QUIET_FLAG)
111+
(cd "$PROJECT_ROOT" && $SWIFTLINT lint --strict --no-cache $QUIET_FLAG)
65112
LINT_STATUS=$?
66113

67114
if [ $LINT_STATUS -eq 0 ]; then
68-
echo "✅ SwiftLint exit status: $LINT_STATUS"
115+
echo "✅ SwiftLint exit status: $LINT_STATUS"
69116
else
70-
echo "❌ SwiftLint exit status: $LINT_STATUS"
117+
echo "❌ SwiftLint exit status: $LINT_STATUS"
71118
fi
72119

73-
echo ""
74-
75120
# Run SwiftFormat
76121
if [[ "$MODE" == "fix" ]]; then
77-
$SWIFTFORMAT . $QUIET_FLAG
78-
FORMAT_STATUS=$?
122+
$SWIFTFORMAT . $QUIET_FLAG
123+
FORMAT_STATUS=$?
79124
else
80-
$SWIFTFORMAT . $QUIET_FLAG --lint
81-
FORMAT_STATUS=$?
125+
$SWIFTFORMAT . $QUIET_FLAG --lint
126+
FORMAT_STATUS=$?
82127
fi
83128

84129
if [ $FORMAT_STATUS -eq 0 ]; then
85-
echo "✅ SwiftFormat exit status: $FORMAT_STATUS"
130+
echo "✅ SwiftFormat exit status: $FORMAT_STATUS"
86131
else
87-
echo "❌ SwiftFormat exit status: $FORMAT_STATUS"
132+
echo "❌ SwiftFormat exit status: $FORMAT_STATUS"
88133
fi
89134

90135
# Function to print error messages for linting issues
91136
print_linting_error() {
92-
local tool_name=$1
93-
echo "$tool_name detected issues that need to be fixed."
94-
if [[ "$MODE" == "check" ]]; then
95-
echo "🔧 How to fix:"
96-
echo " Shopify employee? Run 'dev fix' and resolve remaining issues"
97-
echo " Not a Shopify employee? Run './Scripts/lint fix' and resolve remaining issues"
98-
else
99-
echo "🔧 These files will need to be fixed manually"
100-
fi
137+
local tool_name=$1
138+
echo "$tool_name detected issues that need to be fixed."
139+
if [[ "$MODE" == "check" ]]; then
140+
echo "🔧 How to fix:"
141+
echo " Shopify employee? Run 'dev fix' and resolve remaining issues"
142+
echo " Not a Shopify employee? Run './Scripts/lint fix' and resolve remaining issues"
143+
else
144+
echo "🔧 These files will need to be fixed manually"
145+
fi
101146
}
102147

103-
# Handle exit codes for check mode
104-
echo ""
105-
106148
if [ $LINT_STATUS -ne 0 ]; then
107-
print_linting_error "SwiftLint"
108-
exit 1
149+
print_linting_error "SwiftLint"
150+
exit 1
109151
fi
110152

111153
if [ $FORMAT_STATUS -ne 0 ]; then
112-
print_linting_error "SwiftFormat"
113-
exit 1
154+
print_linting_error "SwiftFormat"
155+
exit 1
114156
fi
115157

116158
# Run CocoaPods lint (check mode only, not applicable to fix)
117159
# Skip with --skip-pod (e.g. in CI where pod lint runs as a separate job)
118160
SKIP_POD=false
119161
if [[ "$*" == *"--skip-pod"* ]]; then
120-
SKIP_POD=true
162+
SKIP_POD=true
121163
fi
122164

123165
if [[ "$MODE" == "check" && "$SKIP_POD" == "false" ]]; then
124-
echo ""
125-
echo "🔍 Running CocoaPods lint..."
126-
bundle exec pod lib lint --allow-warnings
127-
POD_STATUS=$?
128-
129-
if [ $POD_STATUS -eq 0 ]; then
130-
echo "✅ CocoaPods lint exit status: $POD_STATUS"
131-
else
132-
echo "❌ CocoaPods lint exit status: $POD_STATUS"
133-
echo "❌ CocoaPods detected issues that need to be fixed."
134-
echo "🔧 Run 'bundle exec pod lib lint --allow-warnings --verbose' for details"
135-
exit 1
136-
fi
166+
echo "🔍 Running CocoaPods lint..."
167+
168+
POD_LOG=""
169+
if [[ "$VERBOSE" == "true" ]]; then
170+
bundle exec pod lib lint --allow-warnings
171+
else
172+
POD_LOG="$(mktemp "${TMPDIR:-/tmp}/checkout-kit-pod-lint.XXXXXX")"
173+
bundle exec pod lib lint --allow-warnings >"$POD_LOG" 2>&1
174+
fi
175+
POD_STATUS=$?
176+
177+
if [ $POD_STATUS -eq 0 ]; then
178+
echo "✅ CocoaPods lint exit status: $POD_STATUS"
179+
else
180+
if [ -n "$POD_LOG" ]; then
181+
cat "$POD_LOG"
182+
rm -f "$POD_LOG"
183+
fi
184+
185+
echo "❌ CocoaPods lint exit status: $POD_STATUS"
186+
echo "❌ CocoaPods detected issues that need to be fixed."
187+
echo "🔧 Run 'bundle exec pod lib lint --allow-warnings --verbose' for details"
188+
exit 1
189+
fi
190+
191+
if [ -n "$POD_LOG" ]; then
192+
rm -f "$POD_LOG"
193+
fi
137194
fi

swift/dev.yml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,30 @@ type: ios
44

55
up:
66
- packages:
7-
- mint
8-
- xcbeautify
9-
- rover
10-
- jq
7+
- mint
8+
- xcbeautify
9+
- rover
10+
- jq
1111
- custom:
1212
name: Bootstrap Mint packages
13-
met?: mint which swiftlint >/dev/null 2>&1 && mint which swiftformat >/dev/null 2>&1
13+
met?: |
14+
set -e
15+
expected_swiftlint="$(sed -n 's#^realm/SwiftLint@##p' Mintfile)"
16+
expected_swiftformat="$(sed -n 's#^nicklockwood/SwiftFormat@##p' Mintfile)"
17+
swiftlint_bin="$(mint which swiftlint)"
18+
swiftformat_bin="$(mint which swiftformat)"
19+
test -n "$expected_swiftlint"
20+
test -n "$expected_swiftformat"
21+
test "$("$swiftlint_bin" version)" = "$expected_swiftlint"
22+
test "$("$swiftformat_bin" --version)" = "$expected_swiftformat"
1423
meet: mint bootstrap
15-
- ruby
1624
- xcode:
1725
version: "26.2"
1826
runtimes:
1927
ios:
2028
- version: 23C54 # 26.2
2129
architecture_variant: arm64
30+
- ruby
2231
- custom:
2332
name: Ensure Storefront.xcconfig file
2433
met?: |

0 commit comments

Comments
 (0)