diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 535167b8..54d87b14 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -47,7 +47,7 @@ When in doubt about whether we will be interested in including a new feature, pl This project uses [Mint](https://github.com/yonaskolb/Mint) to manage Swift linting tools (SwiftLint and SwiftFormat) at pinned versions via `platforms/swift/Mintfile`. This ensures consistent formatting across all contributors and CI. -**Shopify employees** (from `platforms/swift/`): +**Shopify employees** (from the repo root): ```bash dev up diff --git a/dev.yml b/dev.yml index fd4bca72..9381dfa0 100644 --- a/dev.yml +++ b/dev.yml @@ -4,6 +4,9 @@ up: - packages: - quicktype - rover + - mint + - xcbeautify + - jq - ruby - custom: name: Install bundle packages @@ -16,6 +19,37 @@ up: ([ -f "./platforms/android/samples/MobileBuyIntegration/.env" ] || exit 1) meet: cd platforms/android && ./scripts/setup_env.sh + - custom: + name: Bootstrap Mint packages + met?: | + set -e + cd platforms/swift + expected_swiftlint="$(sed -n 's#^realm/SwiftLint@##p' Mintfile)" + expected_swiftformat="$(sed -n 's#^nicklockwood/SwiftFormat@##p' Mintfile)" + swiftlint_bin="$(mint which swiftlint)" + swiftformat_bin="$(mint which swiftformat)" + test -n "$expected_swiftlint" + test -n "$expected_swiftformat" + test "$("$swiftlint_bin" version)" = "$expected_swiftlint" + test "$("$swiftformat_bin" --version)" = "$expected_swiftformat" + meet: cd platforms/swift && mint bootstrap + - xcode: + version: "26.2" + runtimes: + ios: + - version: 23C54 # 26.2 + architecture_variant: arm64 + - custom: + name: Ensure Storefront.xcconfig file + met?: | + ([ -f "./platforms/swift/Samples/MobileBuyIntegration/Storefront.xcconfig" ] || exit 1) + meet: cd platforms/swift && ./Scripts/ensure_storefront_config + - custom: + name: Setup entitlements + met?: | + ([ -f "./platforms/swift/Samples/MobileBuyIntegration/MobileBuyIntegration/MobileBuyIntegration.entitlements" ] || exit 1;) + meet: cd platforms/swift && ./Scripts/setup_entitlements + open: "GitHub": "https://github.com/Shopify/checkout-kit" "Issues": "https://github.com/Shopify/checkout-kit/issues" @@ -25,6 +59,7 @@ check: android-license-headers: cd platforms/android && ./scripts/check_license_headers.rb android-detekt: cd platforms/android && ./gradlew detekt android-lint: cd platforms/android && ./gradlew lintRelease + swift-lint: cd platforms/swift && ./Scripts/lint commands: # Repo-wide @@ -120,3 +155,35 @@ commands: android-lint: desc: Run Android lint run: cd platforms/android && ./gradlew lintRelease + + # Swift + swift: + desc: "Swift Checkout Kit commands" + subcommands: + lint: + desc: Check format and lint issues using SwiftLint and SwiftFormat + aliases: [style] + run: cd platforms/swift && ./Scripts/lint + fix: + desc: Automatically fix format and lint issues where possible + run: cd platforms/swift && ./Scripts/lint fix + build: + desc: Build Swift packages or sample apps + run: | + echo "Usage: dev swift build {packages|samples}" + subcommands: + packages: + desc: Build both ShopifyCheckoutKit and ShopifyAcceleratedCheckouts packages + run: | + cd platforms/swift + ./Scripts/xcode_run build ShopifyCheckoutKit + ./Scripts/xcode_run build ShopifyAcceleratedCheckouts + samples: + desc: Build all sample applications to verify integration + run: cd platforms/swift && ./Scripts/build_samples + test: + desc: | + `dev swift test` - Run all tests for the ShopifyCheckoutKit-Package. + `dev swift test ` - Run only the specified test class. + syntax: "[test_class_name]" + run: cd platforms/swift && ./Scripts/xcode_run test ShopifyCheckoutKit-Package "$1" diff --git a/platforms/swift/.cursor/rules/swift-development.mdc b/platforms/swift/.cursor/rules/swift-development.mdc index 58ebdaca..5ae1c7d3 100644 --- a/platforms/swift/.cursor/rules/swift-development.mdc +++ b/platforms/swift/.cursor/rules/swift-development.mdc @@ -16,18 +16,18 @@ alwaysApply: true ## Verification Commands ### Check your work systematically: -1. **Lint & Format** → `dev lint` (or `dev style`) - Checks for linting and stylistic errors -2. **Build Issues** → `dev build` - Checks for compilation issues -3. **Test Issues** → `dev test` - Checks for failing tests +1. **Lint & Format** → `dev swift lint` (or `dev swift style`) - Checks for linting and stylistic errors +2. **Build Issues** → `dev swift build` - Checks for compilation issues +3. **Test Issues** → `dev swift test` - Checks for failing tests ### Available dev commands: **See `dev.yml` in project root for complete list of commands and descriptions.** Key commands for verification: -- `dev lint` (alias: `dev style`) - Check format & lint issues -- `dev fix` - Auto-fix formatting and linting issues -- `dev build packages` - Build both packages -- `dev test packages` - Run all tests +- `dev swift lint` (alias: `dev swift style`) - Check format & lint issues +- `dev swift fix` - Auto-fix formatting and linting issues +- `dev swift build packages` - Build both packages +- `dev swift test` - Run all tests ## Concurrency Best Practices @@ -50,7 +50,7 @@ actor QueryCache { ✅ DO: Run the appropriate dev command to verify ### After making changes: -- ALWAYS run `dev fix && dev lint` to check your code is formatted and written in our style. +- ALWAYS run `dev swift fix && dev swift lint` to check your code is formatted and written in our style. ## Example Workflow @@ -58,14 +58,14 @@ actor QueryCache { # Make your Swift changes... # Fix any auto-fixable issues -dev fix +dev swift fix # Check for any remaining lint issues -dev lint +dev swift lint # Verify it compiles -dev build +dev swift build # Run tests if needed -dev test packages +dev swift test ``` diff --git a/platforms/swift/Samples/MobileBuyIntegration/README.md b/platforms/swift/Samples/MobileBuyIntegration/README.md index 437bedf2..d6d58343 100644 --- a/platforms/swift/Samples/MobileBuyIntegration/README.md +++ b/platforms/swift/Samples/MobileBuyIntegration/README.md @@ -123,7 +123,7 @@ From the **repo root**: dev apollo codegen mobile-buy ``` -This reads the schema + your `.graphql` files and regenerates the Swift code in `Generated/`. The command also runs `dev fix` to auto-format the output. +This reads the schema + your `.graphql` files and regenerates the Swift code in `Generated/`. The command also runs `dev swift fix` to auto-format the output. ### 5. Build and fix any issues @@ -138,9 +138,9 @@ All commands are run from the **repo root** (`checkout-kit/`): | `dev apollo download_schema mobile-buy` | Download the Storefront API schema for this sample app | | `dev apollo codegen mobile-buy` | Regenerate Swift types from `.graphql` files | | `dev apollo codegen all` | Regenerate for all sample apps | -| `dev style` | Run SwiftLint + SwiftFormat checks | -| `dev fix` | Auto-fix lint/format issues | -| `dev build samples` | Build all sample apps | +| `dev swift style` | Run SwiftLint + SwiftFormat checks | +| `dev swift fix` | Auto-fix lint/format issues | +| `dev swift build samples` | Build all sample apps | ## Key files diff --git a/platforms/swift/Scripts/apollo_codegen b/platforms/swift/Scripts/apollo_codegen index 34ba20eb..9839c390 100755 --- a/platforms/swift/Scripts/apollo_codegen +++ b/platforms/swift/Scripts/apollo_codegen @@ -58,4 +58,4 @@ case "$APP" in ;; esac -/opt/dev/bin/dev fix +/opt/dev/bin/dev swift fix diff --git a/platforms/swift/Scripts/lint b/platforms/swift/Scripts/lint index 20443533..b0edf5b9 100755 --- a/platforms/swift/Scripts/lint +++ b/platforms/swift/Scripts/lint @@ -138,7 +138,7 @@ print_linting_error() { echo "❌ $tool_name detected issues that need to be fixed." if [[ "$MODE" == "check" ]]; then echo "🔧 How to fix:" - echo " Shopify employee? Run 'dev fix' and resolve remaining issues" + echo " Shopify employee? Run 'dev swift fix' and resolve remaining issues" echo " Not a Shopify employee? Run './Scripts/lint fix' and resolve remaining issues" else echo "🔧 These files will need to be fixed manually" diff --git a/platforms/swift/dev.yml b/platforms/swift/dev.yml deleted file mode 100644 index 18961d59..00000000 --- a/platforms/swift/dev.yml +++ /dev/null @@ -1,70 +0,0 @@ -name: checkout-kit-swift - -type: ios - -up: - - packages: - - mint - - xcbeautify - - rover - - jq - - custom: - name: Bootstrap Mint packages - met?: | - set -e - expected_swiftlint="$(sed -n 's#^realm/SwiftLint@##p' Mintfile)" - expected_swiftformat="$(sed -n 's#^nicklockwood/SwiftFormat@##p' Mintfile)" - swiftlint_bin="$(mint which swiftlint)" - swiftformat_bin="$(mint which swiftformat)" - test -n "$expected_swiftlint" - test -n "$expected_swiftformat" - test "$("$swiftlint_bin" version)" = "$expected_swiftlint" - test "$("$swiftformat_bin" --version)" = "$expected_swiftformat" - meet: mint bootstrap - - xcode: - version: "26.2" - runtimes: - ios: - - version: 23C54 # 26.2 - architecture_variant: arm64 - - ruby - - custom: - name: Ensure Storefront.xcconfig file - met?: | - ([ -f "./samples/MobileBuyIntegration/Storefront.xcconfig" ] || exit 1) - meet: ./scripts/ensure_storefront_config - - custom: - name: Setup entitlements - met?: | - ([ -f "./samples/MobileBuyIntegration/MobileBuyIntegration/MobileBuyIntegration.entitlements" ] || exit 1;) - meet: ./scripts/setup_entitlements - -check: - lint: /opt/dev/bin/dev lint - -commands: - lint: - aliases: [style] - desc: Check format and lint issues across all Swift files using SwiftLint and SwiftFormat - run: scripts/lint - - fix: - desc: Automatically fix format and lint issues where possible - run: scripts/lint fix - - build: - subcommands: - packages: - desc: Build both ShopifyCheckoutKit and ShopifyAcceleratedCheckouts packages - run: | - ./scripts/xcode_run build ShopifyCheckoutKit - ./scripts/xcode_run build ShopifyAcceleratedCheckouts - samples: - desc: Build all sample applications to verify integration - run: ./scripts/build_samples - - test: - desc: | - `dev test` - Run all tests for the ShopifyCheckoutKit-Package. - `dev test ` - Run only the specified test class. - run: ./scripts/xcode_run test ShopifyCheckoutKit-Package "$1"