Skip to content

Commit 9aa48f6

Browse files
committed
add ci jobs4
1 parent 3c22da3 commit 9aa48f6

2 files changed

Lines changed: 63 additions & 41 deletions

File tree

.github/workflows/ci.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,30 @@ jobs:
7373
swift-format-lint-check:
7474
name: Swift Format And Lint Check
7575
runs-on: macos-latest
76+
if: github.event_name == 'pull_request'
7677
continue-on-error: true
7778
steps:
7879
- uses: actions/checkout@v4
79-
- name: Run style checks
80+
with:
81+
fetch-depth: 0
82+
- name: Run style checks on changed Swift files
83+
shell: bash
8084
run: |
85+
set -euo pipefail
8186
chmod +x scripts/check-swift-style.sh
82-
./scripts/check-swift-style.sh
87+
mapfile -d '' swift_files < <(
88+
git diff -z --name-only --diff-filter=ACMR \
89+
"${{ github.event.pull_request.base.sha }}" \
90+
"${{ github.event.pull_request.head.sha }}" \
91+
-- '*.swift'
92+
)
93+
94+
if [[ "${#swift_files[@]}" -eq 0 ]]; then
95+
echo "No changed Swift files in this PR."
96+
exit 0
97+
fi
98+
99+
./scripts/check-swift-style.sh "${swift_files[@]}"
83100
84101
link-health:
85102
name: Link Health

scripts/check-swift-style.sh

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,51 @@ cd "$repo_root"
88

99
tabs_report="$(mktemp)"
1010
trailing_ws_report="$(mktemp)"
11-
trap 'rm -f "$tabs_report" "$trailing_ws_report"' EXIT
11+
target_files_list="$(mktemp)"
12+
trap 'rm -f "$tabs_report" "$trailing_ws_report" "$target_files_list"' EXIT
1213

13-
if command -v rg >/dev/null 2>&1; then
14-
rg -n $'\t' --glob '*.swift' --glob '!**/.git/**' --glob '!**/.build/**' . > "$tabs_report" || true
15-
if [[ -s "$tabs_report" ]]; then
16-
head -n 50 "$tabs_report"
17-
if [[ "$(wc -l < "$tabs_report")" -gt 50 ]]; then
18-
echo "...truncated (showing first 50 matches)"
14+
if [[ "$#" -gt 0 ]]; then
15+
for file in "$@"; do
16+
if [[ -f "$file" && "$file" == *.swift ]]; then
17+
echo "$file" >> "$target_files_list"
1918
fi
20-
echo "Swift style check: tabs found in Swift files." >&2
21-
errors=1
22-
fi
19+
done
20+
else
21+
find . -type f -name '*.swift' -not -path './.git/*' -not -path './.build/*' > "$target_files_list"
22+
fi
2323

24-
rg -n "[[:blank:]]$" --glob '*.swift' --glob '!**/.git/**' --glob '!**/.build/**' . > "$trailing_ws_report" || true
25-
if [[ -s "$trailing_ws_report" ]]; then
26-
head -n 50 "$trailing_ws_report"
27-
if [[ "$(wc -l < "$trailing_ws_report")" -gt 50 ]]; then
28-
echo "...truncated (showing first 50 matches)"
29-
fi
30-
echo "Swift style check: trailing whitespace found in Swift files." >&2
31-
errors=1
24+
if [[ ! -s "$target_files_list" ]]; then
25+
echo "No Swift files found for style check."
26+
exit 0
27+
fi
28+
29+
while IFS= read -r file; do
30+
if grep -n $'\t' "$file" > /tmp/codex-style-tabs.$$ 2>/dev/null; then
31+
sed "s#^#$file:#" /tmp/codex-style-tabs.$$ >> "$tabs_report"
3232
fi
33-
else
34-
grep -RIn --include='*.swift' $'\t' . > "$tabs_report" || true
35-
if [[ -s "$tabs_report" ]]; then
36-
head -n 50 "$tabs_report"
37-
if [[ "$(wc -l < "$tabs_report")" -gt 50 ]]; then
38-
echo "...truncated (showing first 50 matches)"
39-
fi
40-
echo "Swift style check: tabs found in Swift files." >&2
41-
errors=1
33+
if grep -n -E "[[:blank:]]$" "$file" > /tmp/codex-style-trailing.$$ 2>/dev/null; then
34+
sed "s#^#$file:#" /tmp/codex-style-trailing.$$ >> "$trailing_ws_report"
4235
fi
36+
done < "$target_files_list"
4337

44-
grep -RIn --include='*.swift' -E "[[:blank:]]$" . > "$trailing_ws_report" || true
45-
if [[ -s "$trailing_ws_report" ]]; then
46-
head -n 50 "$trailing_ws_report"
47-
if [[ "$(wc -l < "$trailing_ws_report")" -gt 50 ]]; then
48-
echo "...truncated (showing first 50 matches)"
49-
fi
50-
echo "Swift style check: trailing whitespace found in Swift files." >&2
51-
errors=1
38+
rm -f /tmp/codex-style-tabs.$$ /tmp/codex-style-trailing.$$
39+
40+
if [[ -s "$tabs_report" ]]; then
41+
head -n 50 "$tabs_report"
42+
if [[ "$(wc -l < "$tabs_report")" -gt 50 ]]; then
43+
echo "...truncated (showing first 50 matches)"
5244
fi
45+
echo "Swift style check: tabs found in Swift files." >&2
46+
errors=1
47+
fi
48+
49+
if [[ -s "$trailing_ws_report" ]]; then
50+
head -n 50 "$trailing_ws_report"
51+
if [[ "$(wc -l < "$trailing_ws_report")" -gt 50 ]]; then
52+
echo "...truncated (showing first 50 matches)"
53+
fi
54+
echo "Swift style check: trailing whitespace found in Swift files." >&2
55+
errors=1
5356
fi
5457

5558
swift_format_cmd=""
@@ -60,10 +63,12 @@ elif xcrun --find swift-format >/dev/null 2>&1; then
6063
fi
6164

6265
if [[ -n "$swift_format_cmd" && -f "$repo_root/.swift-format" ]]; then
63-
if ! eval "$swift_format_cmd lint --recursive ."; then
64-
echo "Swift style check: swift-format lint failed." >&2
65-
errors=1
66-
fi
66+
while IFS= read -r file; do
67+
if ! eval "$swift_format_cmd lint \"$file\""; then
68+
echo "Swift style check: swift-format lint failed for $file." >&2
69+
errors=1
70+
fi
71+
done < "$target_files_list"
6772
else
6873
echo "swift-format lint skipped (missing swift-format command or .swift-format config)."
6974
fi

0 commit comments

Comments
 (0)