|
| 1 | +name: SharedCore tests |
| 2 | + |
| 3 | +# The Swift facade in `kmp/shared-core/spm` and the Kotlin/Native halves of the modules it |
| 4 | +# exports both need Xcode, so neither runs in the Ubuntu `CI` workflow. This is the macOS lane |
| 5 | +# that covers them. Path-filtered rather than folded into `CI`: a macOS runner is expensive and |
| 6 | +# nothing outside these directories can change the answer. |
| 7 | +on: |
| 8 | + pull_request: |
| 9 | + paths: |
| 10 | + - 'kmp/shared-core/**' |
| 11 | + - 'libs/codes/kikcode/**' |
| 12 | + - 'libs/encryption/**' |
| 13 | + - 'gradle/libs.versions.toml' |
| 14 | + - '.github/workflows/shared-core-tests.yml' |
| 15 | + |
| 16 | +concurrency: |
| 17 | + group: shared-core-tests-${{ github.head_ref || github.run_id }} |
| 18 | + cancel-in-progress: true |
| 19 | + |
| 20 | +env: |
| 21 | + CI: true |
| 22 | + |
| 23 | +jobs: |
| 24 | + shared-core-tests: |
| 25 | + name: Run SharedCore tests |
| 26 | + runs-on: macos-15 |
| 27 | + steps: |
| 28 | + - uses: actions/checkout@v4 |
| 29 | + with: |
| 30 | + fetch-depth: 1 |
| 31 | + |
| 32 | + # Cheap supply-chain guard: fails the run if gradle/wrapper/gradle-wrapper.jar |
| 33 | + # is not a byte-for-byte match for a jar published by Gradle. |
| 34 | + - name: Validate Gradle wrapper |
| 35 | + uses: gradle/actions/wrapper-validation@v4 |
| 36 | + |
| 37 | + - name: Setup Java env |
| 38 | + uses: actions/setup-java@v3 |
| 39 | + with: |
| 40 | + java-version: '21' |
| 41 | + distribution: 'corretto' |
| 42 | + cache: 'gradle' |
| 43 | + |
| 44 | + # Gradle configures every project in the build, and the Android app applies the secrets |
| 45 | + # plugin, which fails configuration outright when `local.properties` is absent. This lane |
| 46 | + # only builds the KMP modules — nothing here compiles the app or talks to any of these |
| 47 | + # services — so obviously-fake values are enough to get through configuration. Same |
| 48 | + # placeholders the publish workflow writes. |
| 49 | + - name: Write placeholder local.properties |
| 50 | + run: | |
| 51 | + set -euo pipefail |
| 52 | + { |
| 53 | + echo 'BUGSNAG_API_KEY="00000000000000000000000000000000"' |
| 54 | + echo 'GOOGLE_CLOUD_PROJECT_NUMBER=000000000000' |
| 55 | + echo 'MIXPANEL_API_KEY="00000000000000000000000000000000"' |
| 56 | + echo 'COINBASE_ONRAMP_API_KEY=00000000-0000-0000-0000-000000000000' |
| 57 | + } > ./local.properties |
| 58 | +
|
| 59 | + # commonTest runs on the JVM in the Ubuntu lane, which says nothing about the Kotlin/Native |
| 60 | + # halves — ed25519's actual is cinterop over vendored C, and the rest go through a different |
| 61 | + # compiler backend. These compile anyway as part of the XCFramework below; running them is |
| 62 | + # nearly free from here. |
| 63 | + - name: Run the Kotlin tests on the iOS simulator target |
| 64 | + run: | |
| 65 | + ./gradlew \ |
| 66 | + :libs:codes:kikcode:iosSimulatorArm64Test \ |
| 67 | + :libs:encryption:base58:iosSimulatorArm64Test \ |
| 68 | + :libs:encryption:ed25519:iosSimulatorArm64Test \ |
| 69 | + :libs:encryption:hmac:iosSimulatorArm64Test \ |
| 70 | + :libs:encryption:sha256:iosSimulatorArm64Test \ |
| 71 | + :libs:encryption:sha512:iosSimulatorArm64Test |
| 72 | +
|
| 73 | + # The facade suite has to run against the Kotlin in this checkout, not against the last |
| 74 | + # published release, or a facade written for an unreleased Kotlin change is untested until |
| 75 | + # after the release that would have caught it. |
| 76 | + - name: Assemble the XCFramework |
| 77 | + run: ./gradlew :kmp:shared-core:assembleSharedCoreReleaseXCFramework |
| 78 | + |
| 79 | + # Named simulators come and go with the runner image, so pick whatever iPhone this one has |
| 80 | + # rather than pinning a name that silently stops existing. |
| 81 | + - name: Pick a simulator |
| 82 | + id: sim |
| 83 | + run: | |
| 84 | + set -euo pipefail |
| 85 | + udid=$(xcrun simctl list devices available -j \ |
| 86 | + | python3 -c "import json,sys; d=json.load(sys.stdin)['devices']; print(next(x['udid'] for r in sorted(d, reverse=True) for x in d[r] if x['name'].startswith('iPhone')))") |
| 87 | + echo "udid=$udid" >> "$GITHUB_OUTPUT" |
| 88 | + echo "Using simulator $udid" |
| 89 | +
|
| 90 | + # The package is iOS-only and the XCFramework has no host slice, so `swift test` cannot |
| 91 | + # run this suite — it goes through a simulator destination. FLIPCASH_SHARED_CORE_LOCAL is |
| 92 | + # the same override the local loop uses; see docs/proto-local-development.md's sibling, |
| 93 | + # shared-core-local-development.md, in the orchestrator repo. |
| 94 | + - name: Run the SharedCoreKit tests |
| 95 | + working-directory: kmp/shared-core/spm |
| 96 | + env: |
| 97 | + FLIPCASH_SHARED_CORE_LOCAL: ${{ github.workspace }} |
| 98 | + run: | |
| 99 | + set -euo pipefail |
| 100 | + xcodebuild test \ |
| 101 | + -scheme SharedCore \ |
| 102 | + -destination "platform=iOS Simulator,id=${{ steps.sim.outputs.udid }}" \ |
| 103 | + -clonedSourcePackagesDirPath "$RUNNER_TEMP/spm" \ |
| 104 | + -resultBundlePath "$RUNNER_TEMP/SharedCoreKit.xcresult" \ |
| 105 | + -quiet |
| 106 | +
|
| 107 | + # `-quiet` prints nothing on success, so a run that executed no tests at all reads exactly |
| 108 | + # like a run that passed all of them — the one failure mode a gate must not have. Print the |
| 109 | + # counts and fail on zero. |
| 110 | + - name: Report the test counts |
| 111 | + if: always() |
| 112 | + run: | |
| 113 | + set -euo pipefail |
| 114 | + bundle="$RUNNER_TEMP/SharedCoreKit.xcresult" |
| 115 | + if [ ! -d "$bundle" ]; then |
| 116 | + echo "no result bundle at $bundle — the test step never got as far as running" |
| 117 | + exit 1 |
| 118 | + fi |
| 119 | + xcrun xcresulttool get test-results summary --path "$bundle" --format json \ |
| 120 | + > "$RUNNER_TEMP/summary.json" |
| 121 | + python3 -c " |
| 122 | + import json, sys |
| 123 | + summary = json.load(open(sys.argv[1])) |
| 124 | + total = summary.get('totalTestCount', 0) |
| 125 | + print(total, 'tests:', |
| 126 | + summary.get('passedTests', 0), 'passed,', |
| 127 | + summary.get('failedTests', 0), 'failed,', |
| 128 | + summary.get('skippedTests', 0), 'skipped') |
| 129 | + if total == 0: |
| 130 | + sys.exit('the suite executed no tests') |
| 131 | + " "$RUNNER_TEMP/summary.json" |
0 commit comments