|
| 1 | +name: Reusable Drift Check |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + strategy_domain: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + snapshot_repository: |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + snapshot_checkout_path: |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + python_version: |
| 16 | + required: false |
| 17 | + type: string |
| 18 | + default: "3.11" |
| 19 | + ai_gateway_service_url: |
| 20 | + required: false |
| 21 | + type: string |
| 22 | + default: "" |
| 23 | + secrets: |
| 24 | + codex_audit_service_url: |
| 25 | + required: false |
| 26 | + |
| 27 | +permissions: |
| 28 | + contents: read |
| 29 | + issues: write |
| 30 | + id-token: write |
| 31 | + |
| 32 | +jobs: |
| 33 | + drift: |
| 34 | + runs-on: ubuntu-latest |
| 35 | + timeout-minutes: 15 |
| 36 | + env: |
| 37 | + FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true" |
| 38 | + STRATEGY_DOMAIN: ${{ inputs.strategy_domain }} |
| 39 | + QUANT_PROJECTS_ROOT: ${{ github.workspace }}/external |
| 40 | + LIFECYCLE_PERFORMANCE_BUCKET: ${{ vars.LIFECYCLE_PERFORMANCE_BUCKET || '' }} |
| 41 | + LIFECYCLE_LOCAL_ROOT: ${{ github.workspace }}/data/lifecycle_store |
| 42 | + |
| 43 | + steps: |
| 44 | + - name: Resolve QuantPlatformKit ref |
| 45 | + id: quant-platform-kit-ref |
| 46 | + shell: bash |
| 47 | + run: | |
| 48 | + set -euo pipefail |
| 49 | + workflow_ref="${{ github.workflow_ref }}" |
| 50 | + ref="${workflow_ref##*@}" |
| 51 | + case "$ref" in |
| 52 | + refs/heads/*) |
| 53 | + ref="${ref#refs/heads/}" |
| 54 | + ;; |
| 55 | + refs/tags/*) |
| 56 | + ref="${ref#refs/tags/}" |
| 57 | + ;; |
| 58 | + esac |
| 59 | + if [ -z "$ref" ]; then |
| 60 | + ref="main" |
| 61 | + fi |
| 62 | + echo "ref=$ref" >> "$GITHUB_OUTPUT" |
| 63 | +
|
| 64 | + - name: Validate trusted caller |
| 65 | + shell: bash |
| 66 | + run: | |
| 67 | + set -euo pipefail |
| 68 | + caller_repo="${{ github.repository }}" |
| 69 | + snapshot_repo="${{ inputs.snapshot_repository }}" |
| 70 | + case "$caller_repo" in |
| 71 | + QuantStrategyLab/CnEquityStrategies|QuantStrategyLab/HkEquityStrategies|QuantStrategyLab/UsEquityStrategies|QuantStrategyLab/CryptoStrategies) |
| 72 | + ;; |
| 73 | + *) |
| 74 | + echo "::error::Untrusted reusable workflow caller: $caller_repo" |
| 75 | + exit 1 |
| 76 | + ;; |
| 77 | + esac |
| 78 | + if [ "$snapshot_repo" != "$caller_repo" ]; then |
| 79 | + echo "::error::snapshot_repository must match caller repository: $snapshot_repo" |
| 80 | + exit 1 |
| 81 | + fi |
| 82 | +
|
| 83 | + - name: Checkout |
| 84 | + uses: actions/checkout@v6 |
| 85 | + |
| 86 | + - name: Checkout snapshot pipeline repo |
| 87 | + uses: actions/checkout@v6 |
| 88 | + with: |
| 89 | + repository: ${{ inputs.snapshot_repository }} |
| 90 | + ref: main |
| 91 | + path: ${{ inputs.snapshot_checkout_path }} |
| 92 | + |
| 93 | + - name: Checkout QuantPlatformKit |
| 94 | + uses: actions/checkout@v6 |
| 95 | + with: |
| 96 | + repository: QuantStrategyLab/QuantPlatformKit |
| 97 | + ref: ${{ steps.quant-platform-kit-ref.outputs.ref }} |
| 98 | + path: external/QuantPlatformKit |
| 99 | + |
| 100 | + - name: Set up Python |
| 101 | + uses: actions/setup-python@v6 |
| 102 | + with: |
| 103 | + python-version: ${{ inputs.python_version }} |
| 104 | + |
| 105 | + - name: Install dependencies |
| 106 | + run: | |
| 107 | + set -euo pipefail |
| 108 | + python -m pip install --upgrade pip |
| 109 | + python -m pip install -e . pandas |
| 110 | + python -m pip install --no-deps -e external/QuantPlatformKit |
| 111 | +
|
| 112 | + - name: Build lifecycle performance snapshots |
| 113 | + run: quant-lifecycle monitor --domain ${{ inputs.strategy_domain }} |
| 114 | + |
| 115 | + - name: Validate lifecycle prerequisites |
| 116 | + run: quant-lifecycle doctor --domain ${{ inputs.strategy_domain }} --require-snapshot --require-backtest --max-freshness-days 7 |
| 117 | + |
| 118 | + - name: Run drift detection |
| 119 | + run: quant-lifecycle drift --domain ${{ inputs.strategy_domain }} --no-alerts |
| 120 | + |
| 121 | + - name: Sync drift alerts to GitHub Issues |
| 122 | + env: |
| 123 | + GH_TOKEN: ${{ github.token }} |
| 124 | + GITHUB_REPOSITORY: ${{ github.repository }} |
| 125 | + run: | |
| 126 | + python - <<'PY' |
| 127 | + from quant_platform_kit.strategy_lifecycle.codex_integration import create_issues_for_domain |
| 128 | + results = create_issues_for_domain("${{ inputs.strategy_domain }}") |
| 129 | + created = [item for item in results if item.get("issue_url")] |
| 130 | + print({"created_issues": len(created), "results": len(results)}) |
| 131 | + PY |
| 132 | +
|
| 133 | + - name: Checkout AIAuditBridge |
| 134 | + uses: actions/checkout@v6 |
| 135 | + with: |
| 136 | + repository: QuantStrategyLab/AIAuditBridge |
| 137 | + ref: 9ff297375acbc54afa910d828248812212b5d7f2 |
| 138 | + path: external/AIAuditBridge |
| 139 | + |
| 140 | + - name: Dual-review critical drift |
| 141 | + env: |
| 142 | + AIAUDIT_BRIDGE_ROOT: external/AIAuditBridge |
| 143 | + CODEX_AUDIT_SERVICE_URL: ${{ secrets.codex_audit_service_url }} |
| 144 | + AI_GATEWAY_SERVICE_URL: ${{ inputs.ai_gateway_service_url }} |
| 145 | + run: | |
| 146 | + script="external/AIAuditBridge/scripts/run_drift_dual_review.py" |
| 147 | + if [ ! -f "$script" ]; then |
| 148 | + echo "::notice::dual-review scripts unavailable; skipping until AIAuditBridge is merged" |
| 149 | + exit 0 |
| 150 | + fi |
| 151 | + if [ -z "${CODEX_AUDIT_SERVICE_URL:-}" ]; then |
| 152 | + echo "::notice::CODEX_AUDIT_SERVICE_URL not configured; skipping dual-review dispatch" |
| 153 | + exit 0 |
| 154 | + fi |
| 155 | + PYTHONPATH=external/AIAuditBridge python "$script" \ |
| 156 | + --domain "${STRATEGY_DOMAIN}" --dispatch |
0 commit comments