|
| 1 | +name: Live E2E |
| 2 | + |
| 3 | +# Live e2e suite (ADR-0013). Runs the real CLI against the real staging |
| 4 | +# Management API + Docker bundler, then invokes the deployed functions over HTTP. |
| 5 | +# |
| 6 | +# Non-blocking by construction: this is a standalone workflow, NOT part of the |
| 7 | +# required-checks set, and it never runs on the default PR path of test.yml. |
| 8 | +# |
| 9 | +# Triggers: |
| 10 | +# - workflow_dispatch — manual run. The Actions UI branch picker selects the |
| 11 | +# ref (github.ref), always a same-repo branch. We deliberately take NO |
| 12 | +# free-form `ref` input: that would let a manual run check out arbitrary |
| 13 | +# (e.g. external PR) code while the staging token is in the job env. |
| 14 | +# - schedule (hourly) — exercises the `@beta` channel. `develop` is the default |
| 15 | +# branch AND the beta release source, so a scheduled run checks it out and |
| 16 | +# builds from source. The `gate` job skips the run unless the published |
| 17 | +# `supabase@beta` version changed since the last green run (an actions/cache |
| 18 | +# marker keyed on the version), so we only spend a staging project when there |
| 19 | +# is actually a new beta to test. |
| 20 | +# |
| 21 | +# Secrets: workflow_dispatch and schedule both run on trusted same-repo refs, so |
| 22 | +# the staging token is never exposed to fork code. |
| 23 | +on: |
| 24 | + workflow_dispatch: |
| 25 | + schedule: |
| 26 | + # Hourly, offset from other scheduled workflows. Cron timing is best-effort. |
| 27 | + - cron: "23 * * * *" |
| 28 | + |
| 29 | +permissions: |
| 30 | + contents: read |
| 31 | + |
| 32 | +jobs: |
| 33 | + # Decide whether to run. Manual dispatch always runs. Scheduled runs only fire |
| 34 | + # when the latest published `@beta` is newer than the last one we tested green. |
| 35 | + gate: |
| 36 | + name: Gate (newer @beta?) |
| 37 | + runs-on: ubuntu-latest |
| 38 | + outputs: |
| 39 | + should_run: ${{ steps.decide.outputs.should_run }} |
| 40 | + version: ${{ steps.ver.outputs.version }} |
| 41 | + steps: |
| 42 | + - name: Resolve latest @beta version |
| 43 | + id: ver |
| 44 | + run: | |
| 45 | + set -euo pipefail |
| 46 | + version="$(npm view supabase@beta version)" |
| 47 | + # Validate the shape before it becomes a cache key (defense-in-depth |
| 48 | + # against a garbage/poisoned registry value). |
| 49 | + if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]+)?$ ]]; then |
| 50 | + echo "::error::unexpected supabase@beta version '$version'"; exit 1 |
| 51 | + fi |
| 52 | + echo "version=$version" >> "$GITHUB_OUTPUT" |
| 53 | +
|
| 54 | + # Marker presence == "this beta already tested green". lookup-only so we |
| 55 | + # download nothing; the marker is written by `finalize` after a green run. |
| 56 | + - name: Check tested marker |
| 57 | + id: cache |
| 58 | + if: github.event_name == 'schedule' |
| 59 | + uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 |
| 60 | + with: |
| 61 | + path: .beta-marker |
| 62 | + key: live-e2e-beta-${{ steps.ver.outputs.version }} |
| 63 | + lookup-only: true |
| 64 | + |
| 65 | + - name: Decide |
| 66 | + id: decide |
| 67 | + run: | |
| 68 | + if [ "${{ github.event_name }}" != "schedule" ]; then |
| 69 | + echo "manual dispatch -> run" |
| 70 | + echo "should_run=true" >> "$GITHUB_OUTPUT" |
| 71 | + elif [ "${{ steps.cache.outputs.cache-hit }}" = "true" ]; then |
| 72 | + echo "beta ${{ steps.ver.outputs.version }} already tested green -> skip" |
| 73 | + echo "should_run=false" >> "$GITHUB_OUTPUT" |
| 74 | + else |
| 75 | + echo "new beta ${{ steps.ver.outputs.version }} -> run" |
| 76 | + echo "should_run=true" >> "$GITHUB_OUTPUT" |
| 77 | + fi |
| 78 | +
|
| 79 | + live-e2e: |
| 80 | + needs: gate |
| 81 | + if: needs.gate.outputs.should_run == 'true' |
| 82 | + name: Live e2e (${{ matrix.target }}) |
| 83 | + runs-on: blacksmith-8vcpu-ubuntu-2404 |
| 84 | + # Serialize a target against itself across runs; go and ts-legacy run in |
| 85 | + # parallel. Per-job-scoped project names mean this is mostly belt-and-braces. |
| 86 | + concurrency: |
| 87 | + group: live-e2e-${{ matrix.target }}-${{ github.ref }} |
| 88 | + cancel-in-progress: true |
| 89 | + strategy: |
| 90 | + # Each target is an independent green/red signal. |
| 91 | + fail-fast: false |
| 92 | + matrix: |
| 93 | + # go = source-of-truth Go binary; ts-legacy = the TS rewrite (shells out |
| 94 | + # to Go for most commands). Authoring target is go; ts-legacy proves the |
| 95 | + # shim matches. ts-next is a later axis. |
| 96 | + target: |
| 97 | + - go |
| 98 | + - ts-legacy |
| 99 | + # Non-secret config is job-level; the staging token is scoped to only the two |
| 100 | + # steps that need it (run + cleanup) so build/checkout/docker never see it. |
| 101 | + env: |
| 102 | + CLI_E2E_MODE: live |
| 103 | + CLI_E2E_TARGET_ENV: staging |
| 104 | + CLI_E2E_API_URL: https://api.supabase.green |
| 105 | + CLI_E2E_PROJECT_HOST: supabase.red |
| 106 | + CLI_HARNESS_TARGET: ${{ matrix.target }} |
| 107 | + steps: |
| 108 | + - name: Checkout |
| 109 | + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 |
| 110 | + with: |
| 111 | + persist-credentials: false |
| 112 | + |
| 113 | + - name: Setup |
| 114 | + uses: ./.github/actions/setup |
| 115 | + |
| 116 | + - name: Setup Go |
| 117 | + uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 |
| 118 | + with: |
| 119 | + go-version-file: apps/cli-go/go.mod |
| 120 | + cache-dependency-path: apps/cli-go/go.sum |
| 121 | + |
| 122 | + # Build the Go binary for every target: `go` runs it directly and |
| 123 | + # `ts-legacy` shells out to it for most commands. |
| 124 | + - name: Build Go CLI |
| 125 | + working-directory: apps/cli-go |
| 126 | + run: go build -o supabase-go . |
| 127 | + |
| 128 | + - name: Export Go binary path |
| 129 | + run: echo "SUPABASE_GO_BINARY=${{ github.workspace }}/apps/cli-go/supabase-go" >> "$GITHUB_ENV" |
| 130 | + |
| 131 | + # The ts-legacy harness runs the compiled supabase binary from apps/cli/dist. |
| 132 | + - name: Build CLI |
| 133 | + if: matrix.target == 'ts-legacy' |
| 134 | + run: pnpm exec nx run supabase:build |
| 135 | + |
| 136 | + # Docker is a hard requirement for the --use-docker bundler cell. |
| 137 | + - name: Docker preflight |
| 138 | + run: docker info |
| 139 | + |
| 140 | + - name: Run live e2e (retry up to 3x) |
| 141 | + env: |
| 142 | + SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_E2E_CLI_LIVE_STAGING_ACCESS_TOKEN }} |
| 143 | + run: | |
| 144 | + PREFIX="cli-e2e-live-${CLI_HARNESS_TARGET}-${GITHUB_RUN_ID}-" |
| 145 | + # GitHub runs this step as `bash -e`; use `if cmd; then` (errexit-exempt) |
| 146 | + # so a failing attempt does not abort the step before the retry. |
| 147 | + for attempt in 1 2 3; do |
| 148 | + echo "::group::live e2e attempt ${attempt}" |
| 149 | + if [ "$attempt" -gt 1 ]; then |
| 150 | + bash .github/scripts/sweep-live-projects.sh "$PREFIX" || true |
| 151 | + fi |
| 152 | + if pnpm --filter @supabase/cli-e2e test:e2e:live; then |
| 153 | + echo "::endgroup::" |
| 154 | + exit 0 |
| 155 | + fi |
| 156 | + echo "::endgroup::" |
| 157 | + echo "attempt ${attempt} failed" |
| 158 | + done |
| 159 | + exit 1 |
| 160 | +
|
| 161 | + # Backstop: delete any project this job created that survived a crash. |
| 162 | + # The script exits non-zero (failing this step) if any delete failed. |
| 163 | + - name: Cleanup leftover projects |
| 164 | + if: always() |
| 165 | + env: |
| 166 | + SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_E2E_CLI_LIVE_STAGING_ACCESS_TOKEN }} |
| 167 | + run: bash .github/scripts/sweep-live-projects.sh "cli-e2e-live-${CLI_HARNESS_TARGET}-${GITHUB_RUN_ID}-" |
| 168 | + |
| 169 | + # Record that this beta tested green so the next scheduled run skips it. Needs |
| 170 | + # the whole matrix: the marker is saved only if BOTH go and ts-legacy passed |
| 171 | + # (a red leg leaves no marker, so the next hour re-runs the same beta). |
| 172 | + finalize: |
| 173 | + needs: [gate, live-e2e] |
| 174 | + if: github.event_name == 'schedule' && needs.live-e2e.result == 'success' |
| 175 | + name: Mark @beta tested |
| 176 | + runs-on: ubuntu-latest |
| 177 | + steps: |
| 178 | + - name: Write marker |
| 179 | + run: | |
| 180 | + mkdir -p .beta-marker |
| 181 | + echo "${{ needs.gate.outputs.version }}" > .beta-marker/version |
| 182 | +
|
| 183 | + - name: Save tested marker |
| 184 | + uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 |
| 185 | + with: |
| 186 | + path: .beta-marker |
| 187 | + key: live-e2e-beta-${{ needs.gate.outputs.version }} |
0 commit comments