Repository navigation
91 lines (86 loc) · 3.33 KB
/
Copy pathlive-e2e-gate.yml
File metadata and controls
91 lines (86 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
name: Live E2E Gate
on:
workflow_call:
inputs:
sha:
description: Exact commit to verify
required: true
type: string
branch:
description: Branch whose live-e2e.yml runs may be reused
required: false
type: string
default: develop
secrets:
SUPABASE_E2E_CLI_LIVE_STAGING_ACCESS_TOKEN:
required: true
permissions:
actions: read
contents: read
jobs:
lookup:
name: Find exact-SHA live result
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
reuse: ${{ steps.lookup.outputs.reuse }}
steps:
- name: Check latest relevant run
id: lookup
env:
GH_TOKEN: ${{ github.token }}
REPOSITORY: ${{ github.repository }}
SHA: ${{ inputs.sha }}
BRANCH: ${{ inputs.branch }}
run: |
set -euo pipefail
response="$(gh api --paginate -X GET "/repos/${REPOSITORY}/actions/workflows/live-e2e.yml/runs" -f branch="$BRANCH" -f head_sha="$SHA" -F per_page=100)"
latest="$(jq -s -c 'map(.workflow_runs[]) | sort_by(.run_number) | reverse | .[0] // empty' <<< "$response")"
if [[ -z "$latest" ]]; then
echo "No live run exists for ${SHA} on ${BRANCH}; the stable gate will run the suite."
echo "reuse=false" >> "$GITHUB_OUTPUT"
exit 0
fi
status="$(jq -r '.status' <<< "$latest")"
conclusion="$(jq -r '.conclusion // empty' <<< "$latest")"
run_id="$(jq -r '.id' <<< "$latest")"
echo "Latest live run ${run_id}: status=${status}, conclusion=${conclusion}"
jobs="$(gh api --paginate "/repos/${REPOSITORY}/actions/runs/${run_id}/jobs?per_page=100")"
# Keep this exact job suffix and step name aligned with the producer
# and notifier; renaming either changes reuse semantics.
executed="$(jq -s -r 'any(.[].jobs[]; (.name == "Live e2e" or (.name | endswith(" / Live e2e"))) and .conclusion == "success" and any(.steps[]?; .name == "Run live e2e" and .conclusion == "success"))' <<< "$jobs")"
if [[ "$status" == completed && "$conclusion" == success && "$executed" == true ]]; then
echo "reuse=true" >> "$GITHUB_OUTPUT"
else
echo "Latest live run did not pass; the stable gate will run the suite."
echo "reuse=false" >> "$GITHUB_OUTPUT"
fi
run:
name: Run live e2e for stable gate
needs: lookup
if: needs.lookup.outputs.reuse != 'true'
uses: ./.github/workflows/live-e2e-suite.yml
with:
ref: ${{ inputs.sha }}
concurrency_group: live-e2e-stable-${{ inputs.sha }}
# Forward the one secret required by live-e2e-suite.yml.
secrets:
SUPABASE_E2E_CLI_LIVE_STAGING_ACCESS_TOKEN: ${{ secrets.SUPABASE_E2E_CLI_LIVE_STAGING_ACCESS_TOKEN }}
result:
name: Verify live e2e gate
needs: [lookup, run]
if: ${{ !cancelled() }}
runs-on: ubuntu-latest
timeout-minutes: 2
steps:
- name: Require a successful result
env:
REUSE: ${{ needs.lookup.outputs.reuse }}
RUN_RESULT: ${{ needs.run.result }}
run: |
set -euo pipefail
if [[ "$REUSE" == true || "$RUN_RESULT" == success ]]; then
exit 0
fi
echo "::error::live e2e did not produce a successful result"
exit 1