Skip to content

Commit af94aa8

Browse files
committed
feat(dx): Add custom pre-commit hook to check for disabled tests
1 parent 17ef711 commit af94aa8

File tree

3 files changed

+29
-43
lines changed

3 files changed

+29
-43
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
# Check that testing dependencies are not accidentally committed
3+
4+
has_error=0
5+
6+
for file in "$@"; do
7+
if [[ "$file" == "Package.swift" ]]; then
8+
if grep -q 'isTestingEnabled = /\*TESTING_FLAG\*/true/\*TESTING_FLAG\*/' "$file"; then
9+
echo "ERROR: Package.swift has testing enabled."
10+
echo "Please set isTestingEnabled to false before committing."
11+
has_error=1
12+
fi
13+
fi
14+
15+
if [[ "$file" == "Package.resolved" ]]; then
16+
echo "ERROR: Package.resolved should not be committed."
17+
echo "Please unstage this file with: git reset HEAD Package.resolved"
18+
has_error=1
19+
fi
20+
done
21+
22+
exit $has_error

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,10 @@ repos:
5454
language: system
5555
args:
5656
- "fmt"
57+
58+
- id: check-testing-disabled
59+
name: Check testing is disabled
60+
description: "Ensure Package.swift has testing disabled and Package.resolved is not committed"
61+
files: ^(Package\.swift|Package\.resolved)$
62+
entry: .git-hooks/check-testing-disabled.sh
63+
language: script

Example macOS-SwiftPM/Example_macOS-SPM.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)