Files
purchases-ios/scripts/pre-commit.sh
T
Pol Piella AbadiaandHidde van der Ploeg 7138c59a5b SampleCat: A new iOS Sample app that guides users through any configuration issues (#5200)
* Initial app creation

* Initial screen

* Installs and configures the SDK

* Creates a full Swift 6 compliant ViewModel

* Adds a demo customer center button

* Fixes icon name

* Updates a bit of the logic to fetch offerings

* Updates initial layout by showing offerings

* Makes more progress with a VERY DRAFT and VERY WIP screen

* Creates a new network path and requests

* Creates a new health API and adds it to the BE class

* Creates a `checkOfferings` method

* Pushes local changes

* Moved viewmodels to separate files

* Prepared some basic UI structure

* Adds specific branch of `purchases-ios` for testing

* Gets the sample app back to compiling

* Shows products

* Initial implementation of the products view

* More progress

* More changes

* Added first illustrations

* Added noise background and visual to offerings

* Presenting Product on tap

* made more progress on sample

* Removed NavBar

* Fetches offerings with the latest changes to the SDK

* Adds offerings view

* Maps packages into offering

* Updates app so that we can show a list of the packages that belong to an offering

* Moves all logic to a dedicated health view model

* Adds a full-screen blocking error to the app

* More slight adjustments

* Adds a way to purchase products directly from the Sample App

* Adds an empty StoreKit Configuration file to the scheme

* Changes bundle id

* Only allow scroll behaviour to bounce where it makes sense

* Bit of a better layout for the full screen error

* Points RC Swift Package back to the `main` branch

* Re-adds error messages to make sure that we can just point the user in the right direction

* Updates product cell to have better styles and test purchase button

* Updates `ProductCell` to make sure purchased products can be shown

* Removes unnecessary files from PR

* Formats files

* Removes warning

* Adds project to the API checker script

* Adds project to the update revision fastlane script

* Updates error view

* Removes storekit config file temporarily

* Updates name of property to match dashboard

* Updates entitlementId name

* Adds storekit file back to the scheme (this will get injected from the BE)

* Optimizes app icon to reduce repo size

* Reduces app icon file

* Remove instead of comment out

* Removes unused `EntitlementsView`

* Removes duplicate

* Removes all headers from Swift files

* Uses string directly rather than property holding single string

* canNot to cannot

* Renames products to packages

* Refactors logic to tidy up a bit

* Moves types over to their own files

* More tidying up

* Renames properties from sdk to loaded

* Removes previews that do not work

* Renames `purchasable` to `viewModel`

* Fixes sendability issues

* Converts folders to groups instead

---------

Co-authored-by: Hidde van der Ploeg <hiddevanderploeg@me.com>
2025-06-05 11:41:50 +01:00

92 lines
3.2 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/PaywallsTester/PaywallsTester/Config/Constants.swift"
"${SCRIPT_DIR}/../Examples/SampleCat/SampleCat/Constants.swift"
)
FILES_STAGED=$(git diff --cached --name-only)
PATTERN="\"REVENUECAT_API_KEY\""
for staged_file in $FILES_STAGED
do
absolute_staged_file=$(realpath "$staged_file")
for api_file in "${FILES_TO_CHECK[@]}"
do
absolute_api_file=$(realpath "$api_file")
if [ -n "$absolute_staged_file" ] && [ -n "$absolute_api_file" ] && [ "$absolute_staged_file" = "$absolute_api_file" ] && ! grep -q "$PATTERN" "$absolute_staged_file"; then
echo "Leftover API Key found in '$(basename $absolute_staged_file)'. Please remove."
exit 1
fi
done
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
# Get only modified or added files that are staged (exclude deleted files)
while IFS= read -r -d '' file; do
# Get file status from git status --porcelain
status=$(git status --porcelain -- "$file" | cut -c1-2)
# Run SwiftLint only on files that are not deleted (status != 'D ')
if [[ "$status" != "D " ]]; then
run_swiftlint "$file"
fi
done < <(git diff --cached --name-only -z -- '*.swift')
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