Skip to content

Commit

Permalink
Add Commit hook install script (#1845)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
afterxleep authored Aug 23, 2023
1 parent af145db commit 4313e81
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5781,7 +5781,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
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";
shellScript = "./lint.sh\n";
};
98B0CE69251C937D003FB601 /* Update Localizable.strings */ = {
isa = PBXShellScriptBuildPhase;
Expand Down
44 changes: 44 additions & 0 deletions lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

FIX=false

if [[ "$1" == "--fix" ]]; then
FIX=true
fi

if [[ -n "$CI" ]] || [[ -n "$BITRISE_IO" ]]; then
echo "Skipping SwiftLint run in CI"
exit 0
fi

# Add brew into PATH
if [[ -f /opt/homebrew/bin/brew ]]; then
eval $(/opt/homebrew/bin/brew shellenv)
fi

if test -d "$HOME/.mint/bin/"; then
PATH="$HOME/.mint/bin/:${PATH}"
fi

export PATH


SWIFTLINT_COMMAND="swiftlint lint"
if $FIX; then
SWIFTLINT_COMMAND="swiftlint lint --fix"
fi

if which swiftlint >/dev/null; then
if [ "$CONFIGURATION" = "Release" ]; then
$SWIFTLINT_COMMAND --strict
if [ $? -ne 0 ]; then
echo "error: SwiftLint validation failed."
exit 1
fi
else
$SWIFTLINT_COMMAND
fi
else
echo "error: SwiftLint not installed. Install using \`brew install swiftlint\`"
exit 1
fi
4 changes: 4 additions & 0 deletions scripts/pre-commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

SCRIPT_URL="https://raw.githubusercontent.com/duckduckgo/BrowserServicesKit/main/scripts/pre-commit.sh"
curl -s "${SCRIPT_URL}" | bash -s -- "$@"

0 comments on commit 4313e81

Please sign in to comment.