-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
129 lines (123 loc) · 5.42 KB
/
Copy pathci-bitrise-shadow.yml
File metadata and controls
129 lines (123 loc) · 5.42 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: CI (Bitrise shadow)
# On-demand dispatcher for Bitrise Build Hub shadow runs (INFRA-3679).
#
# Dispatches `ci.yml` as a separate `workflow_dispatch` run with
# `runner_provider=bitrise` (not `workflow_call`), so shadow runs live in the
# Actions tab only and never appear in PR checks or the merge queue. The token
# exchange and dispatch steps use continue-on-error so this job's own check
# always concludes success even when the dispatch cannot run.
#
# Authentication: Token Exchange Service via MetaMask/github-tools get-token
# (OIDC → POST /api/exchange/token). Prerequisites:
# - Actions variable TOKEN_EXCHANGE_URL (already used elsewhere, e.g. triage-forwarder).
# - Rego policy mm-metamask-mobile-bitrise-shadow-ci-token-exchange in
# token-exchange-service (matches the OIDC `workflow_ref` claim).
#
# Auto-dispatch gate: set repo Actions variable BITRISE_SHADOW_AUTO_DISPATCH=true
# to dispatch on PR/push. Default (unset/false) = manual workflow_dispatch only.
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths-ignore:
- "docs/**"
- "**/*.md"
- ".github/CODEOWNERS"
push:
branches: [main]
workflow_dispatch:
concurrency:
group: bitrise-shadow-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
id-token: write
jobs:
dispatch-shadow:
name: "[bitrise-shadow] Dispatch"
runs-on: ubuntu-latest
# Fork PRs use head.repo != github.repository — skip (no shadow, no token exchange).
# PR/push auto-dispatch requires BITRISE_SHADOW_AUTO_DISPATCH=true; workflow_dispatch always runs.
if: >-
${{
(github.event_name == 'workflow_dispatch' || vars.BITRISE_SHADOW_AUTO_DISPATCH == 'true') &&
(github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
}}
steps:
- name: Get access token
id: get-token
continue-on-error: true
uses: MetaMask/github-tools/.github/actions/get-token@v1
with:
token-exchange-url: ${{ vars.TOKEN_EXCHANGE_URL }}
permissions: |
actions: write
contents: read
metadata: read
- name: Dispatch ci.yml on Bitrise (best effort)
id: dispatch
continue-on-error: true
env:
GH_TOKEN: ${{ steps.get-token.outputs.token }}
REPO: ${{ github.repository }}
REF: ${{ github.head_ref || github.ref_name }}
PR_NUMBER: ${{ github.event.pull_request.number || '' }}
HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
run: |
set -euo pipefail
if [ -z "${GH_TOKEN}" ]; then
echo "::error::Token exchange did not return a token; shadow dispatch skipped — this job still succeeds."
echo "::notice::Ensure token-exchange-service policy mm-metamask-mobile-bitrise-shadow-ci-token-exchange is deployed (INFRA-3679)."
exit 0
fi
echo "Dispatching ci.yml on ref='${REF}' (PR='${PR_NUMBER:-none}', sha='${HEAD_SHA}')"
set +e
DISPATCH_LOG="$(gh workflow run ci.yml \
--repo "$REPO" \
--ref "$REF" \
-f runner_provider=bitrise \
-f pr_number="$PR_NUMBER" \
-f head_sha="$HEAD_SHA" 2>&1)"
gh_status=$?
set -e
RUN_URL=""
if [[ "$gh_status" -ne 0 ]]; then
echo "::error::gh workflow run failed (exit ${gh_status}); shadow dispatch skipped — this job still succeeds."
echo "$DISPATCH_LOG"
else
echo "$DISPATCH_LOG"
RUN_URL="$(printf '%s\n' "$DISPATCH_LOG" | grep -oE 'https://[^[:space:]]+/actions/runs/[0-9]+' | tail -1 || true)"
if [[ -z "$RUN_URL" ]]; then
echo "::warning::Could not parse workflow run URL from gh output; open the Actions tab for ci.yml on ref ${REF}."
fi
fi
echo "run_url=${RUN_URL}" >> "$GITHUB_OUTPUT"
- name: Step summary
env:
PR_NUMBER: ${{ github.event.pull_request.number || '' }}
PR_URL: ${{ github.event.pull_request.html_url || '' }}
HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
REF: ${{ github.head_ref || github.ref_name }}
RUN_URL: ${{ steps.dispatch.outputs.run_url }}
run: |
{
echo "## Bitrise shadow CI dispatched"
echo
echo "| Field | Value |"
echo "|---|---|"
if [ -n "$PR_NUMBER" ]; then
echo "| PR | [#${PR_NUMBER}](${PR_URL}) |"
fi
echo "| Ref | \`${REF}\` |"
echo "| Head SHA | \`${HEAD_SHA}\` |"
if [ -n "${RUN_URL}" ]; then
echo "| Shadow run | ${RUN_URL} |"
else
echo "| Shadow run | (not yet visible — check the Actions tab) |"
fi
echo
echo "_Bitrise shadow CI runs **fire-and-forget**: it does not appear in this PR's checks and never blocks the merge queue. This is a benchmark run for INFRA-3679._"
if [ "${{ vars.BITRISE_SHADOW_AUTO_DISPATCH }}" != "true" ] && [ "${{ github.event_name }}" != "workflow_dispatch" ]; then
echo
echo "_Auto-dispatch is **disabled** (BITRISE_SHADOW_AUTO_DISPATCH ≠ true). Use workflow_dispatch on this workflow or ci.yml._"
fi
} >> "$GITHUB_STEP_SUMMARY"