Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Commit hook install script #1845

Merged
merged 8 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5690,7 +5690,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just like for macOS, this could also be simplified to 2 lines:
duckduckgo/macos-browser#1369 (comment)

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 -- "$@"