mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-10 22:45:55 +05:45
I added this in order to debug #2132. ### Changes: - Extracted `Core` framework to be used by both apps - Added new `watchOS` target - Changed `fastlane match` to also create profiles for this new target - Added a simple view in the watch app that displays a text if an entitlement is active, or a `restore` purchases button otherwise This is just a starting point, we can add more to it in the future. #### Note: _Unfortunately I haven't been able to test this because of an Apple bug (`FB11873951`):_ 
83 lines
2.5 KiB
Bash
Executable File
83 lines
2.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Figure out where swiftlint is
|
|
HOMEBREW_BINARY_DESTINATION="/opt/homebrew/bin"
|
|
SWIFT_LINT="${HOMEBREW_BINARY_DESTINATION}/swiftlint"
|
|
|
|
if ! test -d $HOMEBREW_BINARY_DESTINATION; then
|
|
# X86_64 macs have this destination
|
|
SWIFT_LINT="/usr/local/bin/swiftlint"
|
|
fi
|
|
|
|
# Start timer
|
|
START_DATE=$(date +"%s")
|
|
SHOULD_FAIL_PRECOMMIT=0
|
|
|
|
# Run SwiftLint for given filename
|
|
run_swiftlint() {
|
|
local filename="${1}"
|
|
if [[ "${filename##*.}" == "swift" ]]; then
|
|
if [[ "${filename#*.}" != "generated.swift" ]]; then
|
|
${SWIFT_LINT} --strict "${filename}"
|
|
retVal=$?
|
|
if [ $retVal -ne 0 ]; then
|
|
SHOULD_FAIL_PRECOMMIT=$retVal
|
|
fi
|
|
|
|
${SWIFT_LINT} --autocorrect --strict "${filename}"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
verify_no_included_apikeys() {
|
|
# readlink -f follows the link from .git/hooks/pre-commit back to scripts/pre-commit.sh
|
|
# if executed through there. If not it returns the same file.
|
|
SCRIPT_DIR=$(cd $(dirname $(readlink -f "${BASH_SOURCE[0]}")) && pwd)
|
|
FILES_TO_CHECK=(
|
|
"${SCRIPT_DIR}/../Tests/BackendIntegrationTests/Constants.swift"
|
|
"${SCRIPT_DIR}/../Examples/MagicWeather/MagicWeather/Constants.swift"
|
|
"${SCRIPT_DIR}/../Examples/MagicWeatherSwiftUI/Shared/Constants.swift"
|
|
"${SCRIPT_DIR}/../Tests/TestingApps/PurchaseTesterSwiftUI/Core/Constants.swift"
|
|
"${SCRIPT_DIR}/../Tests/TestingApps/PurchaseTester/PurchaseTester/Constants.swift"
|
|
)
|
|
PATTERN="\"REVENUECAT_API_KEY\""
|
|
|
|
for i in "${FILES_TO_CHECK[@]}"
|
|
do
|
|
grep -q $PATTERN $i
|
|
FOUND=$?
|
|
if [ $FOUND -ne 0 ]; then
|
|
echo "Leftover API Key found in '$(basename $i)'. Please remove."
|
|
exit $FOUND
|
|
fi
|
|
done
|
|
}
|
|
|
|
if [[ -e "${SWIFT_LINT}" ]]; then
|
|
echo "SwiftLint version: $(${SWIFT_LINT} version)"
|
|
# Run only if not merging
|
|
if ! git rev-parse -q --verify MERGE_HEAD; then
|
|
# Run for just staged files
|
|
while IFS= read -r -d '' file; do
|
|
run_swiftlint "${file}"
|
|
done < <(git diff --cached --name-only -z)
|
|
fi
|
|
else
|
|
echo "${SWIFT_LINT} is not installed. Please install it via: fastlane setup_dev"
|
|
exit -1
|
|
fi
|
|
|
|
END_DATE=$(date +"%s")
|
|
|
|
DIFF=$(($END_DATE - $START_DATE))
|
|
echo "SwiftLint took $(($DIFF / 60)) minutes and $(($DIFF % 60)) seconds to complete."
|
|
|
|
if [ $SHOULD_FAIL_PRECOMMIT -ne 0 ]; then
|
|
echo "😵 Found formatting errors, some might have been autocorrected."
|
|
echo ""
|
|
echo "⚠️ Please run '${SWIFT_LINT} --autocorrect --strict' then check the changes were made and commit them. ⚠️"
|
|
|
|
exit $SHOULD_FAIL_PRECOMMIT
|
|
else
|
|
verify_no_included_apikeys
|
|
fi |