name: Native SDK E2E # Mirrors the web E2E pattern (see e2e-amplify-interop.yml): trigger on all PRs, # detect whether native SDK / test-backend source changed, run the local suite # always-when-relevant, deploy a per-run sandbox to the shared repo account for # the sandbox suite (same-repo PRs + manual dispatch only), and expose a single # always-running required gate so unrelated/fork PRs don't block branch protection. # # Jobs check out the PR's merge commit (actions/checkout's default), the # commit GitHub reads this file from, so a step added on main finds its script # even when the PR branch predates it. on: pull_request: branches: ['*'] workflow_dispatch: concurrency: group: native-e2e-${{ github.event.pull_request.number || github.run_id }} cancel-in-progress: true # Grant OIDC tokens only to role-assuming jobs so PR-head build jobs cannot # mint AWS credentials. permissions: contents: read jobs: detect-changes: name: Detect Changes runs-on: ubuntu-latest outputs: # E2E account for this PR (see .github/actions/e2e-slot). e2e-index: ${{ steps.e2e-slot.outputs.index }} # Per-platform flags so a change to one language's SDK doesn't fan out to # the others. `any-changed` gates the shared setup/gate jobs. dart-changed: ${{ steps.check.outputs.dart-changed }} swift-changed: ${{ steps.check.outputs.swift-changed }} kotlin-changed: ${{ steps.check.outputs.kotlin-changed }} any-changed: ${{ steps.check.outputs.any-changed }} # The sandbox (real-deploy) jobs: the same flags without the Auth block's # code, whose wire contract the local e2e jobs already cover. dart-sandbox: ${{ steps.check.outputs.dart-sandbox }} swift-sandbox: ${{ steps.check.outputs.swift-sandbox }} kotlin-sandbox: ${{ steps.check.outputs.kotlin-sandbox }} # The auth-derived codegen fixtures (18, 23) must match the live Auth # block's spec; a change to the block, the spec generator or the # fixtures re-runs that check (setup job) without the platform suites. auth-fixtures-changed: ${{ steps.check.outputs.auth-fixtures-changed }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 - id: e2e-slot uses: ./.github/actions/e2e-slot - id: check run: | if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then dart=true; swift=true; kotlin=true; fixtures=true dart_sandbox=true; swift_sandbox=true; kotlin_sandbox=true else CHANGED="$(git diff --name-only origin/main...HEAD)" # Shared inputs affect EVERY platform: the test backend that # generates the OpenRPC spec all SDKs are code-genned from, and this # workflow file itself. A change here forces all platforms to run, # sandbox jobs included. shared=false if echo "$CHANGED" | grep -qE '^test-apps/native-bindings/|^\.github/workflows/native-sdk-e2e\.yml$'; then shared=true fi # The Auth block's code runs the local suites only, not the sandbox # deploys. Its tests, fixtures and codemod don't reach the wire. auth=false if echo "$CHANGED" \ | grep -vE '\.test\.ts$|/__fixtures__/|/src/migrate/' \ | grep -qE '^packages/(bb-auth|auth-common)/(src/|package\.json$|tsconfig\.json$)'; then auth=true fi # Each platform runs when a shared input changed OR its own SDK dir # changed — so a Dart-only change no longer triggers Kotlin/Swift. dart_sandbox=$shared; swift_sandbox=$shared; kotlin_sandbox=$shared if echo "$CHANGED" | grep -qE '^native/dart/'; then dart_sandbox=true; fi if echo "$CHANGED" | grep -qE '^native/swift/'; then swift_sandbox=true; fi # The emulator action is used by the Kotlin Android legs only. if echo "$CHANGED" | grep -qE '^native/kotlin/|^\.github/actions/android-emulator/'; then kotlin_sandbox=true; fi dart=$dart_sandbox; swift=$swift_sandbox; kotlin=$kotlin_sandbox if [ "$auth" = true ]; then dart=true; swift=true; kotlin=true; fi fixtures=false if echo "$CHANGED" | grep -qE '^packages/(bb-auth|auth-common)/|^packages/core/src/scripts/(generate-spec|extract-ts-types|native-catalogs|validate-native-catalogs|read-native-declarations|validate-spec)|^native/codegen-fixtures/'; then fixtures=true fi fi any=false if [ "$dart" = true ] || [ "$swift" = true ] || [ "$kotlin" = true ]; then any=true fi { echo "dart-changed=$dart" echo "swift-changed=$swift" echo "kotlin-changed=$kotlin" echo "dart-sandbox=$dart_sandbox" echo "swift-sandbox=$swift_sandbox" echo "kotlin-sandbox=$kotlin_sandbox" echo "any-changed=$any" echo "auth-fixtures-changed=$fixtures" } >> "$GITHUB_OUTPUT" # Shared setup: build monorepo, generate spec, upload artifact setup: name: Build & Generate Spec needs: [detect-changes] if: >- needs.detect-changes.outputs.any-changed == 'true' || needs.detect-changes.outputs.auth-fixtures-changed == 'true' runs-on: ubuntu-latest timeout-minutes: 10 outputs: spec-path: ${{ steps.spec.outputs.path }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version-file: '.nvmrc' cache: npm - run: npm ci - run: npm run build - name: Generate OpenRPC spec id: spec working-directory: test-apps/native-bindings run: | npm run spec echo "path=test-apps/native-bindings/cdk-blocks/blocks.spec.json" >> $GITHUB_OUTPUT # Codegen fixtures 18-hybrid-arm and 23-cognito-nested-unions are the Auth # block's sign-in state machine and sign-in results. regenerate-all.sh only # proves the generators are stable against the committed spec.json; this # proves those specs still match what the live block emits. - name: Check auth codegen fixtures against the live Auth spec run: node native/codegen-fixtures/check-live-auth-fixtures.mjs test-apps/native-bindings/cdk-blocks/blocks.spec.json - name: Upload spec artifact uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: blocks-spec path: test-apps/native-bindings/cdk-blocks/blocks.spec.json retention-days: 1 # Dart E2E (local server) — no AWS, so it runs on fork PRs too dart-e2e: name: Dart E2E needs: [detect-changes, setup] if: needs.detect-changes.outputs.dart-changed == 'true' runs-on: ubuntu-latest timeout-minutes: 15 permissions: contents: read steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version-file: '.nvmrc' cache: npm - uses: dart-lang/setup-dart@2286a0c042b44434fe26d292bbce8d34f7ec662b # v1.8.2 with: sdk: '3.13.0' # Pin a fixed CDK Blocks CLI telemetry installation ID for CI e2e runs so this # traffic is consistent and identifiable (and can be excluded from product # usage metrics). - uses: ./.github/actions/seed-telemetry-id - run: npm ci - run: npm run build - name: Download spec uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: name: blocks-spec path: test-apps/native-bindings/cdk-blocks/ - name: Pick a free port for the local server run: | # Pick a free port so the local server never collides on the runner. # python3 bind-to-0 is portable (the ubuntu runner ships python3); # fall back to 3001 if it fails. Thread the value to later steps via # $GITHUB_ENV so the server (reads PORT) and the suite (reads # BLOCKS_URL) agree on it without a hardcoded literal. PORT="$(python3 -c 'import socket; s=socket.socket(); s.bind(("127.0.0.1",0)); print(s.getsockname()[1]); s.close()' 2>/dev/null || echo 3001)" echo "PORT=${PORT}" >> "$GITHUB_ENV" echo "BLOCKS_URL=http://localhost:${PORT}/cdk-blocks/api" >> "$GITHUB_ENV" echo "Picked local server port ${PORT}" - name: Start native-bindings server working-directory: test-apps/native-bindings run: | # Inherits PORT from $GITHUB_ENV; server.ts honors it (3001 fallback). # Keep the server's output: a later step prints it if the job fails. npx tsx cdk-blocks/scripts/server.ts > "$RUNNER_TEMP/native-bindings-server.log" 2>&1 & for i in $(seq 1 30); do curl -s -X POST "$BLOCKS_URL" \ -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","method":"api.kvGet","params":{"key":"healthcheck"},"id":1}' && break sleep 1 done - name: Run Dart codegen working-directory: native/dart/packages/blocks_codegen run: | # blocks_codegen resolves blocks_runtime via a gitignored # pubspec_overrides.yaml in local dev; recreate it so `dart pub get` # finds the sibling package in CI (blocks_runtime isn't on pub.dev). printf 'dependency_overrides:\n blocks_runtime:\n path: ../blocks_runtime\n' > pubspec_overrides.yaml dart pub get dart run bin/blocks_codegen.dart \ --spec ../../../../test-apps/native-bindings/cdk-blocks/blocks.spec.json \ --output ../../example/lib/blocks_client.dart - name: Verify generated client compiles working-directory: native/dart/example run: | # Recreate the gitignored path overrides so the example resolves the # in-repo runtime/codegen, and blocks_codegen's hosted blocks_runtime # dep unifies with the path version. printf 'dependency_overrides:\n blocks_runtime:\n path: ../packages/blocks_runtime\n blocks_codegen:\n path: ../packages/blocks_codegen\n' > pubspec_overrides.yaml dart pub get dart analyze lib/blocks_client.dart - name: Run E2E tests working-directory: native/dart/example # BLOCKS_URL is provided via $GITHUB_ENV from the "Pick a free port" step. run: dart run bin/e2e_test.dart - name: Show native-bindings server log if: failure() run: tail -n 400 "$RUNNER_TEMP/native-bindings-server.log" || true kotlin-e2e: name: Kotlin E2E (${{ matrix.label }}) needs: [detect-changes, setup] if: needs.detect-changes.outputs.kotlin-changed == 'true' runs-on: ${{ matrix.runs-on }} timeout-minutes: ${{ matrix.timeout }} strategy: fail-fast: false matrix: include: - label: JVM runs-on: ubuntu-latest gradle-task: jvmTest timeout: 15 - label: iOS runs-on: macos-15 gradle-task: iosSimulatorArm64Test timeout: 20 # The Android leg runs the same commonTest suite on a booted emulator. # 30 covers npm install, the emulator's system-image download and cold # boot, then the suite (~5 min of that). - label: Android runs-on: ubuntu-latest gradle-task: connectedAndroidDeviceTest timeout: 30 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version-file: '.nvmrc' cache: npm - uses: actions/setup-java@d1374f8ac74474200d16ef8ecee22c7ae7a51880 # v6.3.0 with: distribution: temurin java-version: 17 - run: npm ci - run: npm run build - name: Download spec uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: name: blocks-spec path: native/kotlin/e2e/ - name: Run Kotlin codegen working-directory: native/kotlin/e2e run: ./gradlew cdkBlocksCodegen - name: Start native-bindings server working-directory: test-apps/native-bindings run: | # Keep the server's output: a later step prints it if the job fails. npx tsx cdk-blocks/scripts/server.ts > "$RUNNER_TEMP/native-bindings-server.log" 2>&1 & for i in $(seq 1 30); do curl -s -X POST http://localhost:3001/cdk-blocks/api \ -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","method":"api.kvGet","params":{"key":"healthcheck"},"id":1}' && break sleep 1 done - name: Run E2E tests if: matrix.label != 'Android' working-directory: native/kotlin/e2e env: BLOCKS_URL: http://localhost:3001/cdk-blocks/api run: ./gradlew ${{ matrix.gradle-task }} # `adb reverse` forwards the device's own localhost:3001 to the runner's, # so the suite reaches the dev server at the same BLOCKS_URL every other # leg uses. (The emulator's 10.0.2.2 host alias would work for plain RPC, # but the OIDC relay URL is derived from the configured server, and the # examples standardise on forwarding for that reason.) Keeping it inside # the script means a retried attempt re-establishes the forward, which a # device that dropped out of adb's view will have lost. - name: Run E2E tests on an Android emulator if: matrix.label == 'Android' uses: ./.github/actions/android-emulator with: working-directory: native/kotlin/e2e blocks-url: http://localhost:3001/cdk-blocks/api script: | adb reverse tcp:3001 tcp:3001 ./gradlew ${{ matrix.gradle-task }} - name: Show native-bindings server log if: failure() run: tail -n 400 "$RUNNER_TEMP/native-bindings-server.log" || true # The diagnostics directory is where the emulator action's retry wrapper # leaves each attempt's output and the device state it could still read; # the path is that action's `ANDROID_E2E_DIAGNOSTICS_DIR` default. - name: Upload Android test report if: failure() && matrix.label == 'Android' uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: kotlin-android-e2e-report path: | native/kotlin/e2e/build/reports/androidTests/ ${{ runner.temp }}/android-e2e-diagnostics/ if-no-files-found: ignore swift-e2e: name: Swift E2E needs: [detect-changes, setup] if: needs.detect-changes.outputs.swift-changed == 'true' runs-on: macos-26 # A green run takes ~16 min, but macOS arm64 runners are capacity-constrained # and the simulator boot alone can stall for minutes; 20 tripped the wall. timeout-minutes: 40 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version-file: '.nvmrc' cache: npm # Pin a fixed CDK Blocks CLI telemetry installation ID for CI e2e runs so this # traffic is consistent and identifiable (and can be excluded from product # usage metrics). - uses: ./.github/actions/seed-telemetry-id - run: npm ci - run: npm run build - name: Download spec uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: name: blocks-spec path: test-apps/native-bindings/cdk-blocks/ - name: Pick a free port for the local server run: | # Pick a free port so the local server never collides on the runner. # python3 bind-to-0 is portable (the macOS runner ships python3); # fall back to 3001 if it fails. Thread the value to later steps via # $GITHUB_ENV so the server (reads PORT) and the suite (reads # BLOCKS_URL) agree on it without a hardcoded literal. PORT="$(python3 -c 'import socket; s=socket.socket(); s.bind(("127.0.0.1",0)); print(s.getsockname()[1]); s.close()' 2>/dev/null || echo 3001)" echo "PORT=${PORT}" >> "$GITHUB_ENV" echo "BLOCKS_URL=http://localhost:${PORT}/cdk-blocks/api" >> "$GITHUB_ENV" echo "Picked local server port ${PORT}" - name: Run Swift codegen working-directory: native/swift run: | swift run swift-code-generator \ ../../test-apps/native-bindings/cdk-blocks/blocks.spec.json \ Tests/BlocksE2ETests/Generated - name: Start native-bindings server working-directory: test-apps/native-bindings run: | # Inherits PORT from $GITHUB_ENV; server.ts honors it (3001 fallback). # Keep the server's output: a later step prints it if the job fails. npx tsx cdk-blocks/scripts/server.ts > "$RUNNER_TEMP/native-bindings-server.log" 2>&1 & for i in $(seq 1 30); do curl -s -X POST "$BLOCKS_URL" \ -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","method":"api.kvGet","params":["healthcheck"],"id":1}' && break sleep 1 done - name: Verify server is ready run: | for i in $(seq 1 30); do if curl -sf -X POST "$BLOCKS_URL" \ -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","method":"api.kvGet","params":["healthcheck"],"id":1}' > /dev/null 2>&1; then echo "✅ Server ready" exit 0 fi echo "⏳ attempt $i/30: server not ready; retrying in 2s..." sleep 2 done echo "❌ Server never became ready" exit 1 # Boot the simulator in its own step, with its own timeout, so a slow boot # on a capacity-constrained runner fails here, visibly, instead of silently # eating the test step's budget. It is the device the test step names # (iPhone 17 Pro, on the newest installed iOS runtime); the test step then # targets it by UDID so xcodebuild runs on the simulator booted here. - name: Boot iOS simulator timeout-minutes: 10 run: | SIM_UDID="$(xcrun simctl list devices available -j | python3 -c ' import json, re, sys name = "iPhone 17 Pro" devices = json.load(sys.stdin)["devices"] def version(runtime): m = re.search(r"SimRuntime\.iOS-([0-9-]+)$", runtime) return tuple(int(p) for p in m.group(1).split("-")) if m else None runtimes = sorted((r for r in devices if version(r)), key=version, reverse=True) print(next((d["udid"] for r in runtimes for d in devices[r] if d["name"] == name), "")) ')" if [ -z "$SIM_UDID" ]; then echo "❌ No available iPhone 17 Pro simulator" xcrun simctl list devices available exit 1 fi echo "SIM_UDID=${SIM_UDID}" >> "$GITHUB_ENV" echo "Booting iPhone 17 Pro (${SIM_UDID})" # -b boots the device if it is shut down, then waits until it is ready. xcrun simctl bootstatus "$SIM_UDID" -b - name: Run E2E tests env: BLOCKS_URL: ${{ env.BLOCKS_URL }} run: | xcodebuild clean test \ -project native/swift/Tests/BlocksE2ETests/BlocksE2ETestApp.xcodeproj \ -scheme BlocksE2ETests \ -destination "platform=iOS Simulator,id=${SIM_UDID}" - name: Show native-bindings server log if: failure() run: tail -n 400 "$RUNNER_TEMP/native-bindings-server.log" || true # Sandbox E2E — deploys a per-run stack to the shared repo AWS account. # Runs on same-repo PRs (fork PRs can't access secrets/OIDC) and on manual # dispatch. Deploy uses `npm run deploy:sandbox` (cdk-blocks/scripts/deploy-sandbox.ts # -> startSandbox deployOnly -> cdk-blocks/index.cdk.ts with sandboxMode); the # API serves JSON-RPC under `/cdk-blocks/api`. # # Native OIDC sign-in against the sandbox. The OIDC relay suites (Dart # oidc_test.dart, Swift OIDCE2ETests, Kotlin OidcE2ETest) always run in the # local-server jobs above, against `Auth`'s stub IdP. The sandbox deploys # with sandboxMode, where `stubIdp()` is allowed, so the deployed sandbox # serves the stub too: the Dart and Swift sandbox jobs set RUN_OIDC=1 and run # the suites against it, as they did with `AuthOIDC`. (The Kotlin sandbox job # runs it against the stub on JVM; its iOS leg still needs a real IdP, below.) Optionally, federate a real IdP instead by setting these # Actions variables (repository or `publish` environment — `vars`, not # `secrets`: neither value is secret): # # NATIVE_E2E_OIDC_ISSUER the IdP's issuer URL (HTTPS, serving # /.well-known/openid-configuration) # NATIVE_E2E_OIDC_CLIENT_ID a public client (authorization code + PKCE, # no client secret) registered at that IdP # # With both set, each sandbox job below passes them to the deploy (the # native-bindings `auth-oidc` block then federates that IdP directly, keyed # `google`; index.cdk.ts forwards both to the deployed handler) and sets # RUN_OIDC=1, which un-skips the suites. The suites stand in for the browser # by following HTTP redirects, so the IdP must: # - finish /authorize with redirects only — no login or consent page (a # test IdP that auto-approves a fixed user; a real Google/Okta tenant # will not work); # - accept the per-run redirect URI # https://.execute-api.us-east-1.amazonaws.com/prod/cdk-blocks/auth/callback # — each run deploys a new API, so it must allow any ``; # - issue ID tokens signed with an asymmetric key published in its JWKS, # with `aud` set to the client id. # Unset (the default), the deployed stub serves the suites (Dart, Swift) and # the Kotlin suite skips. dart-e2e-sandbox: permissions: contents: read id-token: write # assumes the AWS role below name: Dart E2E (sandbox) needs: [detect-changes, dart-e2e] if: >- needs.detect-changes.outputs.dart-sandbox == 'true' && (github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.full_name == github.repository) runs-on: ubuntu-latest # Deploy sandbox used to take ~21 min (sequential DynamoDB GSI custom-resource # backfill); 30 min left too little headroom (the job tripped the wall and # Destroy could be skipped -> leaked stacks). # test-apps/native-bindings/cdk-blocks/index.cdk.ts now defaults sandboxMode # on, so the GSIs are built with the table and the deploy takes about 3 # minutes. 45 stays until this job has 10 green runs with sandboxMode on, # then drops to 30 unless the slowest of them came within 5 min of that # (https://github.com/aws-devtools-labs/aws-blocks/issues/986). timeout-minutes: 45 environment: e2e env: # Unique per run: the PR number (d for manual runs), then the # run number, then the attempt. Every push starts a new run with a new run # number, and a re-run keeps it and bumps the attempt. Without the run # number, the first attempt of every push reused the previous push's stack # and bucket names and the deploy failed with AlreadyExists. The run number, # not the 11-digit run id, keeps the derived bucket name short (see # kotlin-e2e-sandbox). BLOCKS_STACK_SUFFIX: native-${{ github.event.pull_request.number || format('d{0}', github.run_number) }}-${{ github.run_number }}-${{ github.run_attempt }} # Optional real IdP for the OIDC suites — see "Native OIDC sign-in against # the sandbox" above. Empty unless the repository sets both variables. NATIVE_E2E_OIDC_ISSUER: ${{ vars.NATIVE_E2E_OIDC_ISSUER }} NATIVE_E2E_OIDC_CLIENT_ID: ${{ vars.NATIVE_E2E_OIDC_CLIENT_ID }} # The deployed pools send mail through this verified SES identity, not # Cognito's default sender (test-apps/native-bindings/cdk-blocks/index.ts). E2E_FROM_EMAIL: ${{ secrets.E2E_FROM_EMAIL }} # The sandbox always serves a headless IdP: the deployed stub, or the real one above. RUN_OIDC: '1' steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version-file: '.nvmrc' cache: npm - uses: dart-lang/setup-dart@2286a0c042b44434fe26d292bbce8d34f7ec662b # v1.8.2 with: sdk: '3.13.0' # Make sure we don't have an invalid OIDC token - name: Remove setup-dart's pub.dev OIDC token run: dart pub token remove https://pub.dev || true # Pin a fixed CDK Blocks CLI telemetry installation ID for CI e2e runs so this # traffic is consistent and identifiable (and can be excluded from product # usage metrics). - uses: ./.github/actions/seed-telemetry-id - run: npm ci - run: npm run build - name: Configure AWS credentials id: aws-creds uses: ./.github/actions/e2e-aws-credentials with: role-arns: ${{ secrets.AWS_ROLE_ARNS }} index: ${{ needs.detect-changes.outputs.e2e-index }} - name: Deploy sandbox working-directory: test-apps/native-bindings run: npm run deploy:sandbox - name: Seed returning-customer test user working-directory: test-apps/native-bindings # Real Cognito emails the confirmation code, so the sign-up→code→confirm # legs can't be verified in CI (the auth suites skip them against a # deployed pool). Instead, admin-provision a confirmed user in every # user pool of the stack so the suites can exercise the real # returning-customer sign-in path. AWS_REGION + BLOCKS_STACK_SUFFIX are # inherited from the job/credentials step. run: npm run seed:cognito - name: Resolve BLOCKS_URL id: url working-directory: test-apps/native-bindings run: | URL=$(python3 -c "import json; print(json.load(open('.cdk-blocks-sandbox/config.sandbox.json'))['apiUrl'])") # apiUrl is already the full JSON-RPC endpoint (…/prod/cdk-blocks/api), # so emit it as-is. (Appending /cdk-blocks/api here previously doubled # the path: the non-OIDC suites still worked because API Gateway routes # /prod/cdk-blocks/api/* to the JSON-RPC Lambda, but the OIDC suite # derived a wrong origin and misrouted its /auth/* relay request.) echo "blocks_url=${URL}" >> $GITHUB_OUTPUT - name: Warm up sandbox API (post-deploy readiness gate) env: BLOCKS_URL: ${{ steps.url.outputs.blocks_url }} run: | # A freshly-deployed per-run stack's Lambda/API Gateway can cold-start: # the very first request against a brand-new sandbox intermittently # fails before the function is warm. That is what made the OIDC suite's # first raw `POST /authorize-params` (assertion A1) flaky in CI while it # passed 5/5 against already-warm sandboxes. Poll the JSON-RPC endpoint # until it answers HTTP 200 (it returns 200 with a JSON-RPC error body # for any payload, which proves the Lambda is up and serving) BEFORE # running the suite, so no suite eats the cold-start on its first call. # This hits the same Lambda that serves the /auth/* OIDC routes, so it # protects the OIDC suite's first request too. Bounded backoff; fails # loudly if the API never becomes ready. attempts=24 delay=2 for i in $(seq 1 "$attempts"); do code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 10 \ -X POST -H 'content-type: application/json' -d '{}' \ "$BLOCKS_URL" 2>/dev/null || echo 000) if [ "$code" = "200" ]; then echo "✅ Sandbox API warm after $i attempt(s) (http=200)." exit 0 fi echo "⏳ attempt $i/$attempts: API not ready (http=$code); retrying in ${delay}s..." sleep "$delay" if [ "$delay" -lt 10 ]; then delay=$((delay + 2)); fi done echo "❌ Sandbox API did not return HTTP 200 after $attempts attempts." exit 1 - name: Generate OpenRPC spec working-directory: test-apps/native-bindings # The spec's server is the sandbox just deployed (config.sandbox.json), not the dev server's config.json. env: BLOCKS_SPEC_STAGE: sandbox run: npm run spec - name: Run Dart codegen working-directory: native/dart/packages/blocks_codegen run: | # blocks_codegen resolves blocks_runtime via a gitignored # pubspec_overrides.yaml in local dev; recreate it so `dart pub get` # finds the sibling package in CI (blocks_runtime isn't on pub.dev). printf 'dependency_overrides:\n blocks_runtime:\n path: ../blocks_runtime\n' > pubspec_overrides.yaml dart pub get dart run bin/blocks_codegen.dart \ --spec ../../../../test-apps/native-bindings/cdk-blocks/blocks.spec.json \ --output ../../example/lib/blocks_client.dart - name: Run Dart E2E against sandbox working-directory: native/dart/example env: BLOCKS_URL: ${{ steps.url.outputs.blocks_url }} # oidc_test.dart runs here (the job sets RUN_OIDC=1): against the # deployed stub IdP, or the real IdP when one is configured — see the # note above dart-e2e-sandbox. run: | printf 'dependency_overrides:\n blocks_runtime:\n path: ../packages/blocks_runtime\n blocks_codegen:\n path: ../packages/blocks_codegen\n' > pubspec_overrides.yaml dart pub get dart run bin/e2e_test.dart # e2e-cleanup.mjs first stops what earlier steps left running (after a # cancel, a deploy:sandbox could otherwise submit its stack after the # destroy), and reports a failed destroy as a warning. It runs only once AWS credentials were set up: before that # nothing was deployed, and there is nothing to destroy it with. - name: Destroy sandbox if: always() && steps.aws-creds.outcome == 'success' working-directory: test-apps/native-bindings run: node "$GITHUB_WORKSPACE/scripts/ci/e2e-cleanup.mjs" -- npm run sandbox:destroy swift-e2e-sandbox: permissions: contents: read id-token: write # assumes the AWS role below name: Swift E2E (sandbox) needs: [detect-changes, swift-e2e] if: >- needs.detect-changes.outputs.swift-sandbox == 'true' && (github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.full_name == github.repository) runs-on: macos-26 # Same deploy history as dart-e2e-sandbox; with the old ~27-min deploy+build # the slower xcodebuild blew past 30 (and skipped Destroy -> leaked stack). # 45 stays until this job has 10 green runs with sandboxMode on, then drops # to 35 unless the slowest of them came within 5 min of that # (https://github.com/aws-devtools-labs/aws-blocks/issues/986). timeout-minutes: 45 environment: e2e env: # Unique per run, as in dart-e2e-sandbox. BLOCKS_STACK_SUFFIX: native-swift-${{ github.event.pull_request.number || format('d{0}', github.run_number) }}-${{ github.run_number }}-${{ github.run_attempt }} # Optional real IdP for the OIDC suites — see "Native OIDC sign-in against # the sandbox" above. Empty unless the repository sets both variables. NATIVE_E2E_OIDC_ISSUER: ${{ vars.NATIVE_E2E_OIDC_ISSUER }} NATIVE_E2E_OIDC_CLIENT_ID: ${{ vars.NATIVE_E2E_OIDC_CLIENT_ID }} # The deployed pools send mail through this verified SES identity, not # Cognito's default sender (test-apps/native-bindings/cdk-blocks/index.ts). E2E_FROM_EMAIL: ${{ secrets.E2E_FROM_EMAIL }} # The sandbox always serves a headless IdP: the deployed stub, or the real one above. RUN_OIDC: '1' steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version-file: '.nvmrc' cache: npm # Pin a fixed CDK Blocks CLI telemetry installation ID for CI e2e runs so this # traffic is consistent and identifiable (and can be excluded from product # usage metrics). - uses: ./.github/actions/seed-telemetry-id - run: npm ci - run: npm run build - name: Configure AWS credentials id: aws-creds uses: ./.github/actions/e2e-aws-credentials with: role-arns: ${{ secrets.AWS_ROLE_ARNS }} index: ${{ needs.detect-changes.outputs.e2e-index }} - name: Deploy sandbox working-directory: test-apps/native-bindings run: npm run deploy:sandbox - name: Seed returning-customer test user working-directory: test-apps/native-bindings # `Auth` confirms every sign-up with an emailed code, so against a # deployed pool the auth + todos suites sign in this pre-provisioned # user instead (see seed-cognito-user.ts). run: npm run seed:cognito - name: Resolve BLOCKS_URL id: url working-directory: test-apps/native-bindings run: | URL=$(python3 -c "import json; print(json.load(open('.cdk-blocks-sandbox/config.sandbox.json'))['apiUrl'])") # apiUrl is already the full RPC endpoint and the spec's first server, so Blocks() reaches it too. echo "blocks_url=${URL}" >> $GITHUB_OUTPUT - name: Generate OpenRPC spec working-directory: test-apps/native-bindings env: BLOCKS_SPEC_STAGE: sandbox run: npm run spec - name: Run Swift codegen working-directory: native/swift run: | swift run swift-code-generator \ ../../test-apps/native-bindings/cdk-blocks/blocks.spec.json \ Tests/BlocksE2ETests/Generated - name: Warm up sandbox API env: BLOCKS_URL: ${{ steps.url.outputs.blocks_url }} run: | attempts=24 delay=2 for i in $(seq 1 "$attempts"); do code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 10 \ -X POST -H 'content-type: application/json' -d '{}' \ "$BLOCKS_URL" 2>/dev/null || echo 000) if [ "$code" = "200" ]; then echo "✅ Sandbox API warm after $i attempt(s) (http=200)." exit 0 fi echo "⏳ attempt $i/$attempts: API not ready (http=$code); retrying in ${delay}s..." sleep "$delay" if [ "$delay" -lt 10 ]; then delay=$((delay + 2)); fi done echo "❌ Sandbox API did not return HTTP 200 after $attempts attempts." exit 1 - name: Run Swift E2E against sandbox env: BLOCKS_URL: ${{ steps.url.outputs.blocks_url }} run: | xcodebuild test \ -project native/swift/Tests/BlocksE2ETests/BlocksE2ETestApp.xcodeproj \ -scheme BlocksE2ETests \ -destination 'platform=iOS Simulator,name=iPhone 17 Pro' # e2e-cleanup.mjs first stops what earlier steps left running (after a # cancel, a deploy:sandbox could otherwise submit its stack after the # destroy), and reports a failed destroy as a warning. It runs only once AWS credentials were set up: before that # nothing was deployed, and there is nothing to destroy it with. - name: Destroy sandbox if: always() && steps.aws-creds.outcome == 'success' working-directory: test-apps/native-bindings run: node "$GITHUB_WORKSPACE/scripts/ci/e2e-cleanup.mjs" -- npm run sandbox:destroy kotlin-e2e-sandbox: permissions: contents: read id-token: write # assumes the AWS role below name: Kotlin E2E (${{ matrix.label }}, sandbox) needs: [detect-changes, kotlin-e2e] if: >- needs.detect-changes.outputs.kotlin-sandbox == 'true' && (github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.full_name == github.repository) runs-on: ${{ matrix.runs-on }} # Per-leg: iOS deploy + simulator build exceeded a flat 30 min with the # serial GSI deploy. For now the same 45 as the Swift sandbox job; see each # leg's note for when it drops. timeout-minutes: ${{ matrix.timeout }} environment: e2e strategy: fail-fast: false matrix: include: - label: JVM suffix: jvm runs-on: ubuntu-latest gradle-task: jvmTest # The sandbox deploy took 19-25 min before sandboxMode (serial GSI # custom resources), so 30 min left no room for the build, tests and # destroy. 45 stays until this leg has 10 green runs with # sandboxMode on, then drops to 30 by the rule in #986. timeout: 45 - label: iOS suffix: ios runs-on: macos-15 gradle-task: iosSimulatorArm64Test # Drops to 30 after 10 green runs with sandboxMode on, by the rule # in #986. timeout: 45 - label: Android suffix: android runs-on: ubuntu-latest gradle-task: connectedAndroidDeviceTest # The deploy dominates, as on the JVM leg; the emulator adds its # system-image download and boot on top. Drops to 30 after 10 green # runs with sandboxMode on, by the rule in #986. timeout: 45 env: # Unique per run, as in dart-e2e-sandbox: PR number (d for # manual runs, d-prefixed so it can't match a PR number), run number, # attempt. The suffix uses the short run number, not the 11-digit run id: # with the run id the derived bucket name # `bb-test-nb--native-bindings-files` would exceed S3's 63-character # limit on the Kotlin legs and fall back to FileBucket's hashed short form. # The leg prefix is `nk-` rather than `native-kotlin-` for the same reason: # that bucket name spends 33 characters either side of the suffix, leaving # it 30. `native-kotlin-android-1497-6440-1` is 33, and `native-kotlin-jvm-` # crosses too once PR numbers reach five digits; every `nk-` leg fits. BLOCKS_STACK_SUFFIX: nk-${{ matrix.suffix }}-${{ github.event.pull_request.number || format('d{0}', github.run_number) }}-${{ github.run_number }}-${{ github.run_attempt }} # Optional real IdP for the OIDC suites — see "Native OIDC sign-in against # the sandbox" above. Empty unless the repository sets both variables. NATIVE_E2E_OIDC_ISSUER: ${{ vars.NATIVE_E2E_OIDC_ISSUER }} NATIVE_E2E_OIDC_CLIENT_ID: ${{ vars.NATIVE_E2E_OIDC_CLIENT_ID }} # The deployed pools send mail through this verified SES identity, not # Cognito's default sender (test-apps/native-bindings/cdk-blocks/index.ts). E2E_FROM_EMAIL: ${{ secrets.E2E_FROM_EMAIL }} # JVM: the suite runs against the deployed stub IdP, like Dart and Swift # (verified against a real sandbox, 2026-10-05). iOS (Kotlin/Native) and # Android have not been run against a deployed stub yet, so they keep the # real-IdP gate; both drive the flow through the same launcher stand-in the # JVM leg does, so the gate is about evidence, not capability. RUN_OIDC: ${{ (matrix.suffix == 'jvm' || (vars.NATIVE_E2E_OIDC_ISSUER != '' && vars.NATIVE_E2E_OIDC_CLIENT_ID != '')) && '1' || '' }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version-file: '.nvmrc' cache: npm - uses: actions/setup-java@d1374f8ac74474200d16ef8ecee22c7ae7a51880 # v6.3.0 with: distribution: temurin java-version: 17 - run: npm ci - run: npm run build - name: Configure AWS credentials id: aws-creds uses: ./.github/actions/e2e-aws-credentials with: role-arns: ${{ secrets.AWS_ROLE_ARNS }} index: ${{ needs.detect-changes.outputs.e2e-index }} - name: Deploy sandbox working-directory: test-apps/native-bindings run: npm run deploy:sandbox - name: Seed returning-customer test user working-directory: test-apps/native-bindings # `Auth` confirms every sign-up with an emailed code, so against a # deployed pool the auth + todos suites sign in this pre-provisioned # user instead (see seed-cognito-user.ts). run: npm run seed:cognito - name: Resolve BLOCKS_URL id: url working-directory: test-apps/native-bindings run: | URL=$(python3 -c "import json; print(json.load(open('.cdk-blocks-sandbox/config.sandbox.json'))['apiUrl'])") # apiUrl is already the full JSON-RPC endpoint (…/prod/cdk-blocks/api), # so emit it as-is. Appending /cdk-blocks/api here doubled the path; # API Gateway still routed /prod/cdk-blocks/api/* to the JSON-RPC Lambda # so the suite "worked", but keeping the URL clean avoids surprises. echo "blocks_url=${URL}" >> $GITHUB_OUTPUT - name: Warm up sandbox API env: BLOCKS_URL: ${{ steps.url.outputs.blocks_url }} run: | attempts=24 delay=2 for i in $(seq 1 "$attempts"); do code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 10 \ -X POST -H 'content-type: application/json' -d '{}' \ "$BLOCKS_URL" 2>/dev/null || echo 000) if [ "$code" = "200" ]; then echo "✅ Sandbox API warm after $i attempt(s) (http=200)." exit 0 fi echo "⏳ attempt $i/$attempts: API not ready (http=$code); retrying in ${delay}s..." sleep "$delay" if [ "$delay" -lt 10 ]; then delay=$((delay + 2)); fi done echo "❌ Sandbox API did not return HTTP 200 after $attempts attempts." exit 1 - name: Generate OpenRPC spec working-directory: test-apps/native-bindings env: BLOCKS_SPEC_STAGE: sandbox run: npm run spec - name: Download spec uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: name: blocks-spec path: native/kotlin/e2e/ - name: Run Kotlin codegen working-directory: native/kotlin/e2e run: ./gradlew cdkBlocksCodegen - name: Run Kotlin E2E against sandbox if: matrix.label != 'Android' working-directory: native/kotlin/e2e env: BLOCKS_URL: ${{ steps.url.outputs.blocks_url }} run: ./gradlew ${{ matrix.gradle-task }} # The sandbox endpoint is reachable from the emulator's own network, so # this leg needs no port forwarding — only the device. - name: Run Kotlin E2E against sandbox on an Android emulator if: matrix.label == 'Android' uses: ./.github/actions/android-emulator with: working-directory: native/kotlin/e2e blocks-url: ${{ steps.url.outputs.blocks_url }} run-oidc: ${{ env.RUN_OIDC }} script: ./gradlew ${{ matrix.gradle-task }} # Per-attempt output and device state, as in the local leg above. - name: Upload Android test report if: failure() && matrix.label == 'Android' uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: kotlin-android-e2e-sandbox-report path: | native/kotlin/e2e/build/reports/androidTests/ ${{ runner.temp }}/android-e2e-diagnostics/ if-no-files-found: ignore # e2e-cleanup.mjs first stops what earlier steps left running (after a # cancel, a deploy:sandbox could otherwise submit its stack after the # destroy), and reports a failed destroy as a warning. It runs only once AWS credentials were set up: before that # nothing was deployed, and there is nothing to destroy it with. - name: Destroy sandbox if: always() && steps.aws-creds.outcome == 'success' working-directory: test-apps/native-bindings run: node "$GITHUB_WORKSPACE/scripts/ci/e2e-cleanup.mjs" -- npm run sandbox:destroy # Aggregate gate so this can be a single required status check in branch # protection. Always runs (even when the e2e jobs are skipped for unrelated # or fork PRs) and only fails if a job that actually ran failed. native-sdk-e2e-required: name: Native SDK E2E (Required) if: always() needs: [detect-changes, setup, dart-e2e, kotlin-e2e, swift-e2e] runs-on: ubuntu-latest steps: - name: Check results run: | echo "detect-changes=${{ needs.detect-changes.result }} setup=${{ needs.setup.result }} dart-e2e=${{ needs.dart-e2e.result }} kotlin-e2e=${{ needs.kotlin-e2e.result }} swift-e2e=${{ needs.swift-e2e.result }}" # Required gate = SDK correctness. Skipped jobs (no source changes) # are treated as passing. for result in \ "${{ needs.detect-changes.result }}" \ "${{ needs.setup.result }}" \ "${{ needs.dart-e2e.result }}" \ "${{ needs.kotlin-e2e.result }}" \ "${{ needs.swift-e2e.result }}"; do if [ "$result" = "failure" ] || [ "$result" = "cancelled" ]; then echo "A required native SDK E2E job failed (or was cancelled)." exit 1 fi done echo "Native SDK E2E (required) checks passed (or were skipped)."