Skip to content

Commit

Permalink
chore: add shellcheck precommit hook (#4200)
Browse files Browse the repository at this point in the history
  • Loading branch information
armcknight authored Aug 8, 2024
1 parent 5f6f658 commit 706c41f
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 34 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,11 @@ jobs:
- run: pod repo update
- name: Validate HybridPod Podspec
run: pod lib lint ./Tests/HybridSDKTest/HybridPod.podspec --allow-warnings --verbose --platforms=ios "--include-podspecs={Sentry.podspec}"

shellcheck:
name: Run Shellcheck
runs-on: macos-13
steps:
- uses: actions/checkout@v4
- run: brew install shellcheck
- run: shellcheck **/*.sh
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ repos:
- id: check-github-actions
- id: check-github-workflows
args: [--verbose]

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.10.0.1
hooks:
- id: shellcheck

- repo: local
hooks:
Expand Down
14 changes: 7 additions & 7 deletions scripts/build-xcframework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ generate_xcframework() {
rm -rf Carthage/DerivedData

for sdk in "${sdks[@]}"; do
if [[ -n "$(grep "${sdk}" <<< "$ALL_SDKS")" ]]; then
if grep -q "${sdk}" <<< "$ALL_SDKS"; then

xcodebuild archive -project Sentry.xcodeproj/ -scheme "$scheme" -configuration "$resolved_configuration" -sdk "$sdk" -archivePath ./Carthage/archive/${scheme}${suffix}/${sdk}.xcarchive CODE_SIGNING_REQUIRED=NO SKIP_INSTALL=NO CODE_SIGN_IDENTITY= CARTHAGE=YES MACH_O_TYPE=$MACH_O_TYPE ENABLE_CODE_COVERAGE=NO GCC_GENERATE_DEBUGGING_SYMBOLS="$GCC_GENERATE_DEBUGGING_SYMBOLS"
xcodebuild archive -project Sentry.xcodeproj/ -scheme "$scheme" -configuration "$resolved_configuration" -sdk "$sdk" -archivePath "./Carthage/archive/${scheme}${suffix}/${sdk}.xcarchive" CODE_SIGNING_REQUIRED=NO SKIP_INSTALL=NO CODE_SIGN_IDENTITY= CARTHAGE=YES MACH_O_TYPE="$MACH_O_TYPE" ENABLE_CODE_COVERAGE=NO GCC_GENERATE_DEBUGGING_SYMBOLS="$GCC_GENERATE_DEBUGGING_SYMBOLS"

createxcframework+="-framework Carthage/archive/${scheme}${suffix}/${sdk}.xcarchive/Products/Library/Frameworks/${resolved_product_name}.framework "

Expand All @@ -56,16 +56,16 @@ generate_xcframework() {
done

#Create framework for mac catalyst
xcodebuild -project Sentry.xcodeproj/ -scheme "$scheme" -configuration "$resolved_configuration" -sdk iphoneos -destination 'platform=macOS,variant=Mac Catalyst' -derivedDataPath ./Carthage/DerivedData CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES MACH_O_TYPE=$MACH_O_TYPE SUPPORTS_MACCATALYST=YES ENABLE_CODE_COVERAGE=NO GCC_GENERATE_DEBUGGING_SYMBOLS="$GCC_GENERATE_DEBUGGING_SYMBOLS"
xcodebuild -project Sentry.xcodeproj/ -scheme "$scheme" -configuration "$resolved_configuration" -sdk iphoneos -destination 'platform=macOS,variant=Mac Catalyst' -derivedDataPath ./Carthage/DerivedData CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES MACH_O_TYPE="$MACH_O_TYPE" SUPPORTS_MACCATALYST=YES ENABLE_CODE_COVERAGE=NO GCC_GENERATE_DEBUGGING_SYMBOLS="$GCC_GENERATE_DEBUGGING_SYMBOLS"

if [ "$MACH_O_TYPE" = "staticlib" ]; then
local infoPlist="Carthage/DerivedData/Build/Products/"$resolved_configuration"-maccatalyst/${scheme}.framework/Resources/Info.plist"
local infoPlist="Carthage/DerivedData/Build/Products/$resolved_configuration-maccatalyst/${scheme}.framework/Resources/Info.plist"
plutil -replace "MinimumOSVersion" -string "100.0" "$infoPlist"
fi

createxcframework+="-framework Carthage/DerivedData/Build/Products/"$resolved_configuration"-maccatalyst/${resolved_product_name}.framework "
if [ -d "Carthage/DerivedData/Build/Products/"$resolved_configuration"-maccatalyst/${resolved_product_name}.framework.dSYM" ]; then
createxcframework+="-debug-symbols $(pwd -P)/Carthage/DerivedData/Build/Products/"$resolved_configuration"-maccatalyst/${resolved_product_name}.framework.dSYM "
createxcframework+="-framework Carthage/DerivedData/Build/Products/$resolved_configuration-maccatalyst/${resolved_product_name}.framework "
if [ -d "Carthage/DerivedData/Build/Products/$resolved_configuration-maccatalyst/${resolved_product_name}.framework.dSYM" ]; then
createxcframework+="-debug-symbols $(pwd -P)/Carthage/DerivedData/Build/Products/$resolved_configuration-maccatalyst/${resolved_product_name}.framework.dSYM "
fi

createxcframework+="-output Carthage/${scheme}${suffix}.xcframework"
Expand Down
7 changes: 3 additions & 4 deletions scripts/bump.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#!/bin/bash
set -eux
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $SCRIPT_DIR/..
cd "$SCRIPT_DIR/.."

OLD_VERSION="${1}"
NEW_VERSION="${2}"

echo "--> Clean VersionBump"
cd Utils/VersionBump && swift build
cd $SCRIPT_DIR/..
cd "$SCRIPT_DIR/.."
echo "--> Bumping version to ${OLD_VERSION} ${NEW_VERSION}"
./Utils/VersionBump/.build/debug/VersionBump ${NEW_VERSION}
./Utils/VersionBump/.build/debug/VersionBump "${NEW_VERSION}"

./scripts/update-package-sha.sh

12 changes: 6 additions & 6 deletions scripts/check-uikit-linkage.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# We ship a version of Sentry that does not link UIKit. This script runs in CI to ensure we don't accidentally add any code to that configuration that re-adds it again.

#!/bin/bash

# We ship a version of Sentry that does not link UIKit. This script runs in CI to ensure we don't accidentally add any code to that configuration that re-adds it again.

set -eou pipefail

CONFIGURATION="${1}"
Expand All @@ -11,20 +11,20 @@ MODULE_NAME="${4}"

SENTRY_BUILD_PRODUCT_PATH="$DERIVED_DATA_PATH/Build/Products/$CONFIGURATION-iphonesimulator/$MODULE_NAME.framework/$MODULE_NAME"

stat $SENTRY_BUILD_PRODUCT_PATH
stat "$SENTRY_BUILD_PRODUCT_PATH"

MATCHES=$(otool -L $SENTRY_BUILD_PRODUCT_PATH | grep -c -e "UIKit.framework/UIKit" -e "libswiftUIKit.dylib" ||:)
MATCHES=$(otool -L "$SENTRY_BUILD_PRODUCT_PATH" | grep -c -e "UIKit.framework/UIKit" -e "libswiftUIKit.dylib" ||:)

case "$LINKAGE_TEST" in
"linked")
if [ $MATCHES == 0 ]; then
if [ "$MATCHES" == 0 ]; then
echo "UIKit.framework linkage not found."
exit 1
fi
echo "Success! UIKit.framework linked."
;;
"unlinked")
if [ $MATCHES != 0 ]; then
if [ "$MATCHES" != 0 ]; then
echo "UIKit.framework linkage found."
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci-select-xcode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ set -euo pipefail
# 14.3 is the default
XCODE_VERSION="${1:-14.3}"

sudo xcode-select -s /Applications/Xcode_${XCODE_VERSION}.app/Contents/Developer
sudo xcode-select -s "/Applications/Xcode_${XCODE_VERSION}.app/Contents/Developer"
swiftc --version
4 changes: 2 additions & 2 deletions scripts/commit-formatted-code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ else
git config --global user.name 'Sentry Github Bot'
git config --global user.email 'bot+github-bot@sentry.io'
git fetch
git checkout ${GITHUB_BRANCH}
git checkout "${GITHUB_BRANCH}"
git commit -am "Format code"
git push --set-upstream origin ${GITHUB_BRANCH}
git push --set-upstream origin "${GITHUB_BRANCH}"
fi
2 changes: 1 addition & 1 deletion scripts/create-simulator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ SIM_RUNTIME="${2}"
SIM_RUNTIME_WITH_DASH="${3}"

sudo mkdir -p /Library/Developer/CoreSimulator/Profiles/Runtimes
sudo ln -s /Applications/Xcode_${XCODE_VERSION}.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ ${SIM_RUNTIME}.simruntime
sudo ln -s "/Applications/Xcode_${XCODE_VERSION}.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime" "/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS ${SIM_RUNTIME}.simruntime"
xcrun simctl create custom-test-device "iPhone 8" "com.apple.CoreSimulator.SimRuntime.iOS-${SIM_RUNTIME_WITH_DASH}"
2 changes: 1 addition & 1 deletion scripts/test-alamofire.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set -euo pipefail
echo "### Integration test - Alamofire ###"

current_dir=$(pwd)
scripts_path=$(dirname $(readlink -f "$0"))
scripts_path=$(dirname "$(readlink -f "$0")")

trap 'cd "$current_dir"' ERR

Expand Down
2 changes: 1 addition & 1 deletion scripts/test-homekit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set -euo pipefail
echo "### Integration test - Home Assistant ###"

current_dir=$(pwd)
scripts_path=$(dirname $(readlink -f "$0"))
scripts_path=$(dirname "$(readlink -f "$0")")

trap 'cd "$current_dir"' ERR

Expand Down
2 changes: 1 addition & 1 deletion scripts/update-package-sha.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ else
sed -i "" "s/checksum: \".*\" \/\/Sentry-Dynamic/checksum: \"$NEW_CHECKSUM_DYNAMIC\" \/\/Sentry-Dynamic/" Package.swift
fi

echo $GITHUB_RUN_ID > .github/last-release-runid
echo "$GITHUB_RUN_ID" > .github/last-release-runid
2 changes: 1 addition & 1 deletion scripts/upload-dsyms-with-xcode-build-phase.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ set -euxo pipefail
SENTRY_AUTH_TOKEN="${1}"

REPLACE="s/YOUR_AUTH_TOKEN/${SENTRY_AUTH_TOKEN}/g"
sed -i '' $REPLACE ./scripts/upload-dsyms-with-xcode-build-phase.patch
sed -i '' "$REPLACE" ./scripts/upload-dsyms-with-xcode-build-phase.patch

git apply ./scripts/upload-dsyms-with-xcode-build-phase.patch
2 changes: 1 addition & 1 deletion scripts/xcode-slowest-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ RAW_TEST_OUTPUT_LOG=${1:-raw-test-output.log}
NUMBER_OF_SLOWEST_TEST="${2:-20}"

echo "The $NUMBER_OF_SLOWEST_TEST slowest test cases:"
cat $RAW_TEST_OUTPUT_LOG | grep 'Test\ Case.*seconds' | awk -F '[()]' '{print $2 " -> " $1}' | sort -rn | head -n $NUMBER_OF_SLOWEST_TEST
grep 'Test\ Case.*seconds' "$RAW_TEST_OUTPUT_LOG" | awk -F '[()]' '{print $2 " -> " $1}' | sort -rn | head -n "$NUMBER_OF_SLOWEST_TEST"
16 changes: 8 additions & 8 deletions scripts/xcode-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ case $PLATFORM in
;;
esac

if [ -n $CONFIGURATION_OVERRIDE ]; then
CONFIGURATION=$CONFIGURATION_OVERRIDE
if [ -n "$CONFIGURATION_OVERRIDE" ]; then
CONFIGURATION="$CONFIGURATION_OVERRIDE"
else
case $REF_NAME in
"main")
Expand Down Expand Up @@ -91,9 +91,9 @@ if [ $RUN_BUILD == true ]; then
env NSUnbufferedIO=YES xcodebuild \
-workspace Sentry.xcworkspace \
-scheme Sentry \
-configuration $CONFIGURATION \
-configuration "$CONFIGURATION" \
-destination "$DESTINATION" \
-derivedDataPath $DERIVED_DATA_PATH \
-derivedDataPath "$DERIVED_DATA_PATH" \
-quiet \
build
fi
Expand All @@ -102,7 +102,7 @@ if [ $RUN_BUILD_FOR_TESTING == true ]; then
env NSUnbufferedIO=YES xcodebuild \
-workspace Sentry.xcworkspace \
-scheme Sentry \
-configuration $CONFIGURATION \
-configuration "$CONFIGURATION" \
-destination "$DESTINATION" -quiet \
build-for-testing
fi
Expand All @@ -111,11 +111,11 @@ if [ $RUN_TEST_WITHOUT_BUILDING == true ]; then
env NSUnbufferedIO=YES xcodebuild \
-workspace Sentry.xcworkspace \
-scheme Sentry \
-configuration $CONFIGURATION \
-configuration "$CONFIGURATION" \
-destination "$DESTINATION" \
test-without-building |
tee raw-test-output.log |
$RUBY_ENV_ARGS xcpretty -t &&
slather coverage --configuration $CONFIGURATION &&
exit ${PIPESTATUS[0]}
slather coverage --configuration "$CONFIGURATION" &&
exit "${PIPESTATUS[0]}"
fi

0 comments on commit 706c41f

Please sign in to comment.