Repository navigation
146 lines (134 loc) · 7.14 KB
/
Copy pathnotifications-runtime-copy.yml
File metadata and controls
146 lines (134 loc) · 7.14 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
name: Notifications runtime copy (M84, temporary)
# One-shot copy of one Notifications Secrets Store value, the Expo token, into Infisical production
# /workloads/notifications/NOTIFICATIONS_EXPO_ACCESS_TOKEN (Create-only, M108) through a temporary
# cron-only copier Worker (scripts/secrets-migration/m84-notifications-run.mjs). The other three
# Notifications values come from 1Password through secrets-cutover, never from this workflow.
# Removed after the run. It takes no input except the exact commit the dispatcher approved,
# and it runs only from Kilo-Org/cloud main in the protected `notifications-runtime-copy`
# environment. That environment must already exist with main as its only deployment branch,
# no admin bypass, and required reviewers with self-review prevented (the dispatcher cannot
# approve their own run). GitHub enforces those rules when the copy job starts. This workflow
# never creates, configures or reads it: the job token cannot read environment settings
# (that needs the administration permission, which GITHUB_TOKEN never gets).
#
# Before dispatch (operator, with an organization and repository admin login), in this order.
#
# 1. Read the environment back. A 404 means it does not exist; do not dispatch, because a
# dispatch would create it with no protection.
#
# gh api repos/Kilo-Org/cloud/environments/notifications-runtime-copy --jq '{
# adminBypassOff: (.can_admins_bypass == false),
# customBranchPolicyOnly: (.deployment_branch_policy
# == {protected_branches: false, custom_branch_policies: true}),
# reviewers: ([.protection_rules[] | select(.type == "required_reviewers")]
# | length == 1 and .[0].prevent_self_review == true and (.[0].reviewers | length >= 2)
# and any(.[0].reviewers[]; .reviewer.login == "iscekic"))}'
# gh api repos/Kilo-Org/cloud/environments/notifications-runtime-copy/deployment-branch-policies \
# --jq '{onlyMain: ([.branch_policies[] | {name, type}] == [{name: "main", type: "branch"}])}'
#
# All four booleans must be true.
#
# 2. List Actions secrets and variables outside the environment, names only. No M65_* name may
# exist at organization level (or be shared with this repository) or at repository level: such
# a value would stand in for a missing environment value. Each command must print only empty
# lists.
#
# gh api --paginate 'orgs/Kilo-Org/actions/secrets?per_page=100' \
# --jq '[.secrets[].name | select(startswith("M65_"))]'
# gh api --paginate 'orgs/Kilo-Org/actions/variables?per_page=30' \
# --jq '[.variables[].name | select(startswith("M65_"))]'
# gh api --paginate 'repos/Kilo-Org/cloud/actions/organization-secrets?per_page=100' \
# --jq '[.secrets[].name | select(startswith("M65_"))]'
# gh api --paginate 'repos/Kilo-Org/cloud/actions/organization-variables?per_page=30' \
# --jq '[.variables[].name | select(startswith("M65_"))]'
# gh api --paginate 'repos/Kilo-Org/cloud/actions/secrets?per_page=100' \
# --jq '[.secrets[].name | select(startswith("M65_"))]'
# gh api --paginate 'repos/Kilo-Org/cloud/actions/variables?per_page=30' \
# --jq '[.variables[].name | select(startswith("M65_"))]'
#
# 3. Immediately before setting the environment's writer secrets (M65_INFISICAL_CLIENT_SECRET,
# M65_OPERATOR_PREFLIGHT), run the two step 1 reads and the step 2 lists again. Set the secrets
# only when all four booleans are still true and every list is still empty, then dispatch.
# Keep the window from this step to the reviewers' approval short.
#
# After the run, the operator deletes both environment secrets. Record every boolean and every
# empty list in the run notes. The first job (no secret, no environment, `contents: read` only;
# the guard step gets no token) refuses a wrong dispatch before reviewers are asked.
#
# Concurrency: its own group, so it can never replace or cancel a pending production or
# staging rollout. Instead the driver refuses while any Worker rollout workflow is queued or
# running (at start and again before arming). It also requires every existing Worker's
# deployment (versions and percentages) to be identical before arming and after cleanup.
#
# Credentials: the existing CLOUDFLARE_API_TOKEN (M84b/M84c), the one-use writer client secret
# and the operator's names-only Infisical readback. All three reach only the driver step's
# environment. The driver passes the client secret only to `wrangler secret put` on stdin;
# install and checkout steps see no secret.
on:
workflow_dispatch:
inputs:
expected_commit:
description: 'Exact main commit SHA the run was approved for'
required: true
type: string
permissions: {}
concurrency:
group: notifications-runtime-copy
cancel-in-progress: false
jobs:
dispatch-guard:
if: github.repository == 'Kilo-Org/cloud' && github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch'
runs-on: ubuntu-24.04
timeout-minutes: 5
permissions:
contents: read
steps:
- name: Checkout the dispatched commit
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ github.sha }}
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version-file: '.nvmrc'
- name: Check the dispatch
env:
EXPECTED_COMMIT: ${{ inputs.expected_commit }}
run: node scripts/secrets-migration/m84-notifications-run.mjs --dispatch-guard
copy:
needs: dispatch-guard
if: github.repository == 'Kilo-Org/cloud' && github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch'
runs-on: ubuntu-24.04
timeout-minutes: 80
environment: notifications-runtime-copy
permissions:
contents: read
actions: read
steps:
- name: Checkout the dispatched commit
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ github.sha }}
persist-credentials: false
- name: Setup pnpm
uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v4.4.0
- name: Setup Node.js
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version-file: '.nvmrc'
cache: 'pnpm'
- name: Install the pinned Wrangler
working-directory: services/notifications
# No lifecycle scripts: the pinned Wrangler runs from its optional-dependency binaries
# alone (checked with this exact install and a closed `wrangler deploy --dry-run`).
run: pnpm install --frozen-lockfile --ignore-scripts --filter '{.}...' --filter kilocode-monorepo
- name: Run the copier
env:
EXPECTED_COMMIT: ${{ inputs.expected_commit }}
GITHUB_TOKEN: ${{ github.token }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
M65_INFISICAL_CLIENT_ID: ${{ vars.M65_INFISICAL_CLIENT_ID }}
M65_INFISICAL_CLIENT_SECRET: ${{ secrets.M65_INFISICAL_CLIENT_SECRET }}
M65_OPERATOR_PREFLIGHT: ${{ secrets.M65_OPERATOR_PREFLIGHT }}
run: node scripts/secrets-migration/m84-notifications-run.mjs