Skip to content

Commit 4313e81

Browse files
authored
Add Commit hook install script (duckduckgo#1845)
Task URL: https://app.asana.com/0/1200194497630846/1205110674679790/f Descrption: Adds a script that allows us to automatically install a pre-commit hook that runs swiftlint --fix The original installation script lives in BSK for easier maintenance. App Scripts download it and install it locally. (Remote URL will be updated once we merge BSK. This script can be extended as necesary to install/manage additional pre-commit hooks
1 parent af145db commit 4313e81

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

DuckDuckGo.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5781,7 +5781,7 @@
57815781
);
57825782
runOnlyForDeploymentPostprocessing = 0;
57835783
shellPath = /bin/sh;
5784-
shellScript = "if [[ -n \"$CI\" ]] || [[ -n \"$BITRISE_IO\" ]]; then\n echo \"Skipping SwiftLint run in CI\"\n exit 0\nfi\n\nif test -d \"/opt/homebrew/bin/\"; then\n PATH=\"/opt/homebrew/bin/:${PATH}\"\nfi\n\nif test -d \"$HOME/.mint/bin/\"; then\n PATH=\"$HOME/.mint/bin/:${PATH}\"\nfi\n\nexport PATH\n\nif which swiftlint >/dev/null; then\n if [ \"$CONFIGURATION\" = \"Release\" ]; then\n swiftlint lint --strict\n if [ $? -ne 0 ]; then\n echo \"error: SwiftLint validation failed.\"\n exit 1\n fi\n else\n swiftlint lint\n fi\nelse\n echo \"error: SwiftLint not installed. Install using \\`brew install swiftlint\\`\"\n exit 1\nfi\n";
5784+
shellScript = "./lint.sh\n";
57855785
};
57865786
98B0CE69251C937D003FB601 /* Update Localizable.strings */ = {
57875787
isa = PBXShellScriptBuildPhase;

lint.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
FIX=false
4+
5+
if [[ "$1" == "--fix" ]]; then
6+
FIX=true
7+
fi
8+
9+
if [[ -n "$CI" ]] || [[ -n "$BITRISE_IO" ]]; then
10+
echo "Skipping SwiftLint run in CI"
11+
exit 0
12+
fi
13+
14+
# Add brew into PATH
15+
if [[ -f /opt/homebrew/bin/brew ]]; then
16+
eval $(/opt/homebrew/bin/brew shellenv)
17+
fi
18+
19+
if test -d "$HOME/.mint/bin/"; then
20+
PATH="$HOME/.mint/bin/:${PATH}"
21+
fi
22+
23+
export PATH
24+
25+
26+
SWIFTLINT_COMMAND="swiftlint lint"
27+
if $FIX; then
28+
SWIFTLINT_COMMAND="swiftlint lint --fix"
29+
fi
30+
31+
if which swiftlint >/dev/null; then
32+
if [ "$CONFIGURATION" = "Release" ]; then
33+
$SWIFTLINT_COMMAND --strict
34+
if [ $? -ne 0 ]; then
35+
echo "error: SwiftLint validation failed."
36+
exit 1
37+
fi
38+
else
39+
$SWIFTLINT_COMMAND
40+
fi
41+
else
42+
echo "error: SwiftLint not installed. Install using \`brew install swiftlint\`"
43+
exit 1
44+
fi

scripts/pre-commit.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
SCRIPT_URL="https://raw.githubusercontent.com/duckduckgo/BrowserServicesKit/main/scripts/pre-commit.sh"
4+
curl -s "${SCRIPT_URL}" | bash -s -- "$@"

0 commit comments

Comments
 (0)