-
Notifications
You must be signed in to change notification settings - Fork 0
223 lines (206 loc) · 9.71 KB
/
Copy pathruntime-target-lifecycle.yml
File metadata and controls
223 lines (206 loc) · 9.71 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
name: Runtime Target Lifecycle
on:
workflow_dispatch:
workflow_run:
workflows: ["Deploy Cloud Run"]
types: [completed]
schedule:
- cron: "34 * * * *"
env:
GCP_PROJECT_ID: charlesschwabquant
GCP_WORKLOAD_IDENTITY_PROVIDER: projects/401309731911/locations/global/workloadIdentityPools/github-actions/providers/github-main
GCP_WORKLOAD_IDENTITY_SERVICE_ACCOUNT: schwab-platform-deploy@charlesschwabquant.iam.gserviceaccount.com
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: false
jobs:
lifecycle:
name: Publish Schwab target lifecycle
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
id-token: write
env:
RUNTIME_TARGET_ENABLED: ${{ vars.RUNTIME_TARGET_ENABLED }}
RUNTIME_TARGET_JSON: ${{ vars.RUNTIME_TARGET_JSON || secrets.RUNTIME_TARGET_JSON }}
SCHWAB_DRY_RUN_ONLY: ${{ vars.SCHWAB_DRY_RUN_ONLY }}
CLOUD_RUN_REGION: ${{ vars.CLOUD_RUN_REGION }}
CLOUD_RUN_SERVICE: ${{ secrets.CLOUD_RUN_SERVICE }}
CLOUD_RUN_SERVICES: ${{ secrets.CLOUD_RUN_SERVICES }}
CLOUD_RUN_SERVICE_TARGETS_JSON: ${{ vars.CLOUD_RUN_SERVICE_TARGETS_JSON || secrets.CLOUD_RUN_SERVICE_TARGETS_JSON }}
RUNTIME_GUARD_LOOKBACK_MINUTES: ${{ vars.RUNTIME_GUARD_LOOKBACK_MINUTES || '180' }}
RUNTIME_GUARD_REQUIRE_SUCCESS: ${{ vars.RUNTIME_GUARD_REQUIRE_SUCCESS || 'false' }}
RUNTIME_HEARTBEAT_GCS_URIS: ${{ vars.RUNTIME_HEARTBEAT_GCS_URIS || vars.EXECUTION_REPORT_GCS_URI }}
RUNTIME_HEARTBEAT_LOOKBACK_HOURS: ${{ vars.RUNTIME_HEARTBEAT_LOOKBACK_HOURS || '36' }}
RUNTIME_HEARTBEAT_ACCEPT_STATUSES: ${{ vars.RUNTIME_HEARTBEAT_ACCEPT_STATUSES }}
RUNTIME_HEARTBEAT_REJECT_STATUSES: ${{ vars.RUNTIME_HEARTBEAT_REJECT_STATUSES }}
RUNTIME_HEARTBEAT_MARKET_AWARE: ${{ vars.RUNTIME_HEARTBEAT_MARKET_AWARE || 'true' }}
RUNTIME_HEARTBEAT_MARKET_CALENDAR: ${{ vars.SCHWAB_MARKET_CALENDAR }}
RUNTIME_HEARTBEAT_MARKET_TIMEZONE: ${{ vars.SCHWAB_MARKET_TIMEZONE }}
RUNTIME_HEARTBEAT_PUBLICATION_GRACE_MINUTES: ${{ vars.RUNTIME_HEARTBEAT_PUBLICATION_GRACE_MINUTES || '30' }}
RUNTIME_HEARTBEAT_SCHEDULER_AWARE: ${{ vars.RUNTIME_HEARTBEAT_SCHEDULER_AWARE || 'true' }}
RUNTIME_HEARTBEAT_SCHEDULER_LOCATION: ${{ vars.RUNTIME_HEARTBEAT_SCHEDULER_LOCATION || vars.CLOUD_RUN_REGION || 'us-central1' }}
EXECUTION_EVIDENCE_SYNC_URL: ${{ vars.EXECUTION_EVIDENCE_SYNC_URL }}
LIFECYCLE_PERFORMANCE_BUCKET: ${{ vars.LIFECYCLE_PERFORMANCE_BUCKET }}
PRODUCTION_DRIFT_DOMAIN: ${{ vars.PRODUCTION_DRIFT_DOMAIN }}
PRODUCTION_DRIFT_STRATEGY_PROFILE: ${{ vars.PRODUCTION_DRIFT_STRATEGY_PROFILE }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up uv
uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6.8.0
- name: Resolve declared no-order target state
id: target_state
run: |
set -euo pipefail
python3 scripts/runtime_target_lifecycle_state.py >> "$GITHUB_OUTPUT"
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v3
with:
workload_identity_provider: ${{ env.GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ env.GCP_WORKLOAD_IDENTITY_SERVICE_ACCOUNT }}
- name: Set up gcloud
uses: google-github-actions/setup-gcloud@v3
with:
project_id: ${{ env.GCP_PROJECT_ID }}
- name: Install locked runtime dependencies
run: |
set -euo pipefail
uv sync --frozen --no-dev
- name: Check Cloud Run runtime without notification side effects
id: runtime_guard
env:
RUNTIME_GUARD_NAME: CharlesSchwabPlatform lifecycle
RUNTIME_GUARD_FAIL_WORKFLOW_ON_ALERT: "true"
RUNTIME_GUARD_IGNORE_ACTIVE_LKG_RECONCILE_GATE_REJECTS: "true"
run: |
set -uo pipefail
set +e
uv run --no-sync python scripts/cloud_run_runtime_guard.py > runtime-guard.log 2>&1
exit_code=$?
set -e
cat runtime-guard.log
if [ "$exit_code" -eq 0 ]; then
status=pass
elif grep -Eqi 'traceback|importerror|modulenotfounderror|log query failed|internal error|network|timed out|unable to list' runtime-guard.log; then
status=unavailable
else
status=attention
fi
echo "status=$status" >> "$GITHUB_OUTPUT"
exit 0
- name: Check enabled execution heartbeat without notification side effects
id: execution_heartbeat
env:
RUNTIME_HEARTBEAT_NAME: CharlesSchwabPlatform lifecycle
RUNTIME_HEARTBEAT_REPORT_PLATFORM: charles_schwab
RUNTIME_HEARTBEAT_REQUIRED_SERVICES: ${{ secrets.CLOUD_RUN_SERVICE }}
RUNTIME_HEARTBEAT_FAIL_WORKFLOW_ON_ALERT: "true"
run: |
set -uo pipefail
if [ "${{ steps.target_state.outputs.configured_state }}" = "disabled" ]; then
echo "status=not_applicable" >> "$GITHUB_OUTPUT"
echo "Execution heartbeat is not applicable because this target is deliberately disabled."
exit 0
fi
set +e
uv run --no-sync python scripts/execution_report_heartbeat.py > execution-heartbeat.log 2>&1
exit_code=$?
set -e
cat execution-heartbeat.log
if [ "$exit_code" -eq 0 ] && grep -qi 'heartbeat skipped' execution-heartbeat.log; then
status=not_due
elif [ "$exit_code" -eq 0 ]; then
status=pass
elif grep -Eqi 'traceback|importerror|modulenotfounderror|gcloud|storage|network|timed out|internal error|unable to list' execution-heartbeat.log; then
status=unavailable
else
status=attention
fi
echo "status=$status" >> "$GITHUB_OUTPUT"
exit 0
- name: Observe production drift without optimization side effects
id: production_drift
run: |
set -uo pipefail
set +e
uv run --no-sync python scripts/production_drift_health_observe.py > production-drift.log 2>&1
exit_code=$?
set -e
cat production-drift.log
if [ "$exit_code" -ne 0 ]; then
status=unavailable
else
status="$(python3 - <<'PY'
import json
from pathlib import Path
raw = Path("production-drift.log").read_text().strip().splitlines()
payload = {}
for line in reversed(raw):
line = line.strip()
if line.startswith("{") and line.endswith("}"):
payload = json.loads(line)
break
status = str(payload.get("status") or "unavailable").strip().lower()
if status in {"healthy", "parked"}:
print("pass" if status == "healthy" else "not_due")
elif status in {"review", "critical", "watch"}:
print("attention")
else:
print("unavailable")
PY
)"
fi
echo "status=$status" >> "$GITHUB_OUTPUT"
exit 0
- name: Detect unified control-plane ingress
id: lifecycle_ingress
env:
EXECUTION_EVIDENCE_SYNC_TOKEN: ${{ secrets.EXECUTION_EVIDENCE_SYNC_TOKEN }}
run: |
set -euo pipefail
if [ -n "${EXECUTION_EVIDENCE_SYNC_URL:-}" ] && [ -n "${EXECUTION_EVIDENCE_SYNC_TOKEN:-}" ]; then
echo "enabled=true" >> "$GITHUB_OUTPUT"
else
echo "enabled=false" >> "$GITHUB_OUTPUT"
fi
- name: Publish lifecycle to the unified control plane
if: ${{ steps.lifecycle_ingress.outputs.enabled == 'true' }}
uses: QuantStrategyLab/QuantRuntimeSettings/actions/publish-runtime-target-lifecycle@b26858b6d7049d960e226c8922556854f24139b5
with:
source-id: schwab.primary
target-id: schwab.primary
platform: schwab
observe-gcp: 'true'
gcp-project: ${{ env.GCP_PROJECT_ID }}
cloud-run-region: ${{ env.CLOUD_RUN_REGION }}
cloud-run-service: ${{ env.CLOUD_RUN_SERVICE }}
scheduler-location: ${{ env.RUNTIME_HEARTBEAT_SCHEDULER_LOCATION }}
configured-state: ${{ steps.target_state.outputs.configured_state }}
execution-mode: ${{ steps.target_state.outputs.execution_mode }}
runtime-guard: ${{ steps.runtime_guard.outputs.status }}
execution-heartbeat: ${{ steps.execution_heartbeat.outputs.status }}
sync-url: ${{ env.EXECUTION_EVIDENCE_SYNC_URL }}
env:
EXECUTION_EVIDENCE_SYNC_TOKEN: ${{ secrets.EXECUTION_EVIDENCE_SYNC_TOKEN }}
- name: Explain missing lifecycle ingress configuration
if: ${{ steps.lifecycle_ingress.outputs.enabled != 'true' }}
run: |
echo "Lifecycle was checked but not centrally published: configure EXECUTION_EVIDENCE_SYNC_URL and EXECUTION_EVIDENCE_SYNC_TOKEN." >&2
- name: Summarize no-order lifecycle
run: |
{
echo "## Runtime target lifecycle"
echo
echo "| Field | Value |"
echo "| --- | --- |"
echo "| Target | schwab.primary |"
echo "| Configured state | ${{ steps.target_state.outputs.configured_state }} |"
echo "| Intended lane | ${{ steps.target_state.outputs.execution_mode }} |"
echo "| Runtime guard | ${{ steps.runtime_guard.outputs.status }} |"
echo "| Execution heartbeat | ${{ steps.execution_heartbeat.outputs.status }} |"
echo "| Production drift | ${{ steps.production_drift.outputs.status }} |"
echo
echo "This workflow is read-only: it cannot enable a target, alter its lane, or submit an order."
} >> "$GITHUB_STEP_SUMMARY"