|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Run a Step's live `test` workflow against the real TestingBot service. |
| 4 | +# |
| 5 | +# Unlike tests/run.sh, this spends device minutes and needs credentials. It |
| 6 | +# reads them from ONE .bitrise.secrets.yml at the repo root (git-ignored) rather |
| 7 | +# than a copy per Step, and downloads the sample artifacts it needs. |
| 8 | +# |
| 9 | +# scripts/e2e.sh espresso # or: upload-app, xcuitest, maestro, tunnel |
| 10 | +# scripts/e2e.sh # list what each Step needs |
| 11 | +# |
| 12 | +# Credentials go in <repo root>/.bitrise.secrets.yml: |
| 13 | +# |
| 14 | +# envs: |
| 15 | +# - TESTINGBOT_KEY: <your key> |
| 16 | +# - TESTINGBOT_SECRET: <your secret> |
| 17 | + |
| 18 | +set -euo pipefail |
| 19 | + |
| 20 | +REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 21 | +export PATH="${HOME}/.bitrise/tools:${PATH}" |
| 22 | + |
| 23 | +SECRETS="${REPO_ROOT}/.bitrise.secrets.yml" |
| 24 | +FIXTURES="${REPO_ROOT}/.fixtures" |
| 25 | + |
| 26 | +# The Espresso demo app ships prebuilt APKs, so no Gradle build is needed. |
| 27 | +DEMO_RELEASE="https://github.com/testingbot/android-espresso-demo-app/releases/download/1.0.0" |
| 28 | + |
| 29 | +die() { |
| 30 | + echo "error: $*" >&2 |
| 31 | + exit 1 |
| 32 | +} |
| 33 | + |
| 34 | +usage() { |
| 35 | + cat <<EOF |
| 36 | +usage: scripts/e2e.sh <step> |
| 37 | +
|
| 38 | + upload-app uploads a real app; needs credentials only |
| 39 | + espresso runs the demo Espresso suite on a device |
| 40 | + xcuitest needs SAMPLE_APP_IPA and SAMPLE_TEST_BUNDLE (build them yourself) |
| 41 | + maestro needs SAMPLE_FLOWS (a Maestro flows directory) |
| 42 | + tunnel opens a real tunnel; needs Java 11+ locally |
| 43 | +
|
| 44 | +Credentials: ${SECRETS} |
| 45 | +
|
| 46 | + envs: |
| 47 | + - TESTINGBOT_KEY: <your key> |
| 48 | + - TESTINGBOT_SECRET: <your secret> |
| 49 | +EOF |
| 50 | +} |
| 51 | + |
| 52 | +[ "$#" -ge 1 ] || { |
| 53 | + usage |
| 54 | + exit 1 |
| 55 | +} |
| 56 | +target="$1" |
| 57 | + |
| 58 | +[ -f "$SECRETS" ] || die "no credentials at ${SECRETS} |
| 59 | +
|
| 60 | +Create it with: |
| 61 | +
|
| 62 | + envs: |
| 63 | + - TESTINGBOT_KEY: <your key> |
| 64 | + - TESTINGBOT_SECRET: <your secret> |
| 65 | +
|
| 66 | +It is git-ignored." |
| 67 | + |
| 68 | +grep -q 'TESTINGBOT_KEY' "$SECRETS" || die "${SECRETS} has no TESTINGBOT_KEY" |
| 69 | + |
| 70 | +# fetch <url> <dest> -- download once, reuse afterwards. |
| 71 | +fetch() { |
| 72 | + if [ -s "$2" ]; then |
| 73 | + echo " cached $(basename "$2")" |
| 74 | + return 0 |
| 75 | + fi |
| 76 | + echo " fetch $(basename "$2")" |
| 77 | + mkdir -p "$(dirname "$2")" |
| 78 | + curl --fail --location --silent --show-error \ |
| 79 | + --retry 3 --connect-timeout 10 --max-time 300 \ |
| 80 | + --output "$2" "$1" || die "could not download $1" |
| 81 | +} |
| 82 | + |
| 83 | +case "$target" in |
| 84 | +upload-app) |
| 85 | + step_dir="${REPO_ROOT}/steps/testingbot-upload-app" |
| 86 | + echo "==> Fixtures" |
| 87 | + # The upload Step's test workflow uses the remote-URL path, so it just needs |
| 88 | + # a public URL to a real binary. |
| 89 | + extra_envs=(--inventory "$SECRETS") |
| 90 | + export SAMPLE_APP_URL="${DEMO_RELEASE}/app-debug.apk" |
| 91 | + echo " SAMPLE_APP_URL=${SAMPLE_APP_URL}" |
| 92 | + ;; |
| 93 | + |
| 94 | +espresso) |
| 95 | + step_dir="${REPO_ROOT}/steps/testingbot-espresso" |
| 96 | + echo "==> Fixtures" |
| 97 | + fetch "${DEMO_RELEASE}/app-debug.apk" "${FIXTURES}/app-debug.apk" |
| 98 | + fetch "${DEMO_RELEASE}/app-debug-androidTest.apk" "${FIXTURES}/app-debug-androidTest.apk" |
| 99 | + extra_envs=(--inventory "$SECRETS") |
| 100 | + export SAMPLE_APP_APK="${FIXTURES}/app-debug.apk" |
| 101 | + export SAMPLE_TEST_APK="${FIXTURES}/app-debug-androidTest.apk" |
| 102 | + ;; |
| 103 | + |
| 104 | +xcuitest | maestro | tunnel) |
| 105 | + step_dir="${REPO_ROOT}/steps/testingbot-${target}" |
| 106 | + extra_envs=(--inventory "$SECRETS") |
| 107 | + ;; |
| 108 | + |
| 109 | +*) |
| 110 | + usage |
| 111 | + die "unknown step: ${target}" |
| 112 | + ;; |
| 113 | +esac |
| 114 | + |
| 115 | +echo |
| 116 | +echo "==> bitrise run test (steps/$(basename "$step_dir"))" |
| 117 | +echo " This runs on real devices and spends device minutes." |
| 118 | +echo |
| 119 | + |
| 120 | +cd "$step_dir" |
| 121 | +exec bitrise run test "${extra_envs[@]}" |
0 commit comments