Skip to content

Commit 33a99bb

Browse files
committed
Allow bundled strategy config in env sync
1 parent 7013ad1 commit 33a99bb

2 files changed

Lines changed: 47 additions & 6 deletions

File tree

.github/workflows/sync-cloud-run-env.yml

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ jobs:
7878
import os
7979
import subprocess
8080
import sys
81-
from us_equity_strategies import resolve_canonical_profile
81+
from pathlib import Path
82+
83+
from quant_platform_kit.common.strategies import derive_strategy_artifact_paths
84+
from us_equity_strategies import get_strategy_catalog, resolve_canonical_profile
8285
8386
profile = os.environ.get("STRATEGY_PROFILE", "").strip().lower()
8487
if not profile:
@@ -97,6 +100,16 @@ jobs:
97100
if not selected.get("eligible") or not selected.get("enabled"):
98101
raise SystemExit(f"STRATEGY_PROFILE={profile!r} is not eligible/enabled: {selected}")
99102
103+
artifact_paths = derive_strategy_artifact_paths(
104+
get_strategy_catalog(),
105+
canonical_profile,
106+
repo_root=Path.cwd(),
107+
)
108+
has_bundled_strategy_config = bool(
109+
artifact_paths.bundled_config_path is not None
110+
and Path(artifact_paths.bundled_config_path).exists()
111+
)
112+
100113
output_path = os.environ["GITHUB_OUTPUT"]
101114
with open(output_path, "a", encoding="utf-8") as output:
102115
output.write(
@@ -108,6 +121,9 @@ jobs:
108121
output.write(
109122
f"requires_strategy_config_path={str(bool(selected.get('requires_strategy_config_path'))).lower()}\n"
110123
)
124+
output.write(
125+
f"has_bundled_strategy_config={str(has_bundled_strategy_config).lower()}\n"
126+
)
111127
PY
112128
113129
- name: Validate HK env sync inputs
@@ -116,6 +132,7 @@ jobs:
116132
REQUIRES_SNAPSHOT_ARTIFACTS: ${{ steps.strategy_requirements.outputs.requires_snapshot_artifacts }}
117133
REQUIRES_SNAPSHOT_MANIFEST_PATH: ${{ steps.strategy_requirements.outputs.requires_snapshot_manifest_path }}
118134
REQUIRES_STRATEGY_CONFIG_PATH: ${{ steps.strategy_requirements.outputs.requires_strategy_config_path }}
135+
HAS_BUNDLED_STRATEGY_CONFIG: ${{ steps.strategy_requirements.outputs.has_bundled_strategy_config }}
119136
run: |
120137
set -euo pipefail
121138
@@ -155,7 +172,9 @@ jobs:
155172
missing_vars+=("LONGBRIDGE_FEATURE_SNAPSHOT_MANIFEST_PATH")
156173
fi
157174
158-
if [ "${REQUIRES_STRATEGY_CONFIG_PATH:-}" = "true" ] && [ -z "${LONGBRIDGE_STRATEGY_CONFIG_PATH:-}" ]; then
175+
if [ "${REQUIRES_STRATEGY_CONFIG_PATH:-}" = "true" ] \
176+
&& [ -z "${LONGBRIDGE_STRATEGY_CONFIG_PATH:-}" ] \
177+
&& [ "${HAS_BUNDLED_STRATEGY_CONFIG:-}" != "true" ]; then
159178
missing_vars+=("LONGBRIDGE_STRATEGY_CONFIG_PATH")
160179
fi
161180
@@ -355,7 +374,10 @@ jobs:
355374
import os
356375
import subprocess
357376
import sys
358-
from us_equity_strategies import resolve_canonical_profile
377+
from pathlib import Path
378+
379+
from quant_platform_kit.common.strategies import derive_strategy_artifact_paths
380+
from us_equity_strategies import get_strategy_catalog, resolve_canonical_profile
359381
360382
profile = os.environ.get("STRATEGY_PROFILE", "").strip().lower()
361383
if not profile:
@@ -374,6 +396,16 @@ jobs:
374396
if not selected.get("eligible") or not selected.get("enabled"):
375397
raise SystemExit(f"STRATEGY_PROFILE={profile!r} is not eligible/enabled: {selected}")
376398
399+
artifact_paths = derive_strategy_artifact_paths(
400+
get_strategy_catalog(),
401+
canonical_profile,
402+
repo_root=Path.cwd(),
403+
)
404+
has_bundled_strategy_config = bool(
405+
artifact_paths.bundled_config_path is not None
406+
and Path(artifact_paths.bundled_config_path).exists()
407+
)
408+
377409
output_path = os.environ["GITHUB_OUTPUT"]
378410
with open(output_path, "a", encoding="utf-8") as output:
379411
output.write(
@@ -385,6 +417,9 @@ jobs:
385417
output.write(
386418
f"requires_strategy_config_path={str(bool(selected.get('requires_strategy_config_path'))).lower()}\n"
387419
)
420+
output.write(
421+
f"has_bundled_strategy_config={str(has_bundled_strategy_config).lower()}\n"
422+
)
388423
PY
389424
390425
- name: Validate SG env sync inputs
@@ -393,6 +428,7 @@ jobs:
393428
REQUIRES_SNAPSHOT_ARTIFACTS: ${{ steps.strategy_requirements.outputs.requires_snapshot_artifacts }}
394429
REQUIRES_SNAPSHOT_MANIFEST_PATH: ${{ steps.strategy_requirements.outputs.requires_snapshot_manifest_path }}
395430
REQUIRES_STRATEGY_CONFIG_PATH: ${{ steps.strategy_requirements.outputs.requires_strategy_config_path }}
431+
HAS_BUNDLED_STRATEGY_CONFIG: ${{ steps.strategy_requirements.outputs.has_bundled_strategy_config }}
396432
run: |
397433
set -euo pipefail
398434
@@ -432,7 +468,9 @@ jobs:
432468
missing_vars+=("LONGBRIDGE_FEATURE_SNAPSHOT_MANIFEST_PATH")
433469
fi
434470
435-
if [ "${REQUIRES_STRATEGY_CONFIG_PATH:-}" = "true" ] && [ -z "${LONGBRIDGE_STRATEGY_CONFIG_PATH:-}" ]; then
471+
if [ "${REQUIRES_STRATEGY_CONFIG_PATH:-}" = "true" ] \
472+
&& [ -z "${LONGBRIDGE_STRATEGY_CONFIG_PATH:-}" ] \
473+
&& [ "${HAS_BUNDLED_STRATEGY_CONFIG:-}" != "true" ]; then
436474
missing_vars+=("LONGBRIDGE_STRATEGY_CONFIG_PATH")
437475
fi
438476

tests/test_sync_cloud_run_env_workflow.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ grep -Fq 'uses: actions/setup-python@v5' "$workflow_file"
1515
grep -Fq 'python -m pip install -r requirements.txt' "$workflow_file"
1616
grep -Fq 'id: strategy_requirements' "$workflow_file"
1717
grep -Fq 'scripts/print_strategy_profile_status.py' "$workflow_file"
18-
grep -Fq 'from us_equity_strategies import resolve_canonical_profile' "$workflow_file"
18+
grep -Fq 'from quant_platform_kit.common.strategies import derive_strategy_artifact_paths' "$workflow_file"
19+
grep -Fq 'from us_equity_strategies import get_strategy_catalog, resolve_canonical_profile' "$workflow_file"
1920
grep -Fq 'canonical_profile = resolve_canonical_profile(profile)' "$workflow_file"
2021
grep -Fq 'requires_snapshot_artifacts=' "$workflow_file"
2122
grep -Fq 'requires_snapshot_manifest_path=' "$workflow_file"
2223
grep -Fq 'requires_strategy_config_path=' "$workflow_file"
24+
grep -Fq 'has_bundled_strategy_config=' "$workflow_file"
2325
grep -Fq 'Wait for Cloud Run deployment of current commit' "$workflow_file"
2426
grep -Fq 'target_sha="${GITHUB_SHA}"' "$workflow_file"
2527
grep -Fq "gcloud run services describe \"\${CLOUD_RUN_SERVICE}\" --region \"\${CLOUD_RUN_REGION}\" --format='value(spec.template.metadata.labels.commit-sha)'" "$workflow_file"
@@ -59,9 +61,10 @@ grep -Fq 'missing_vars+=("LONGBRIDGE_STRATEGY_CONFIG_PATH")' "$workflow_file"
5961
grep -Fq 'REQUIRES_SNAPSHOT_ARTIFACTS: ${{ steps.strategy_requirements.outputs.requires_snapshot_artifacts }}' "$workflow_file"
6062
grep -Fq 'REQUIRES_SNAPSHOT_MANIFEST_PATH: ${{ steps.strategy_requirements.outputs.requires_snapshot_manifest_path }}' "$workflow_file"
6163
grep -Fq 'REQUIRES_STRATEGY_CONFIG_PATH: ${{ steps.strategy_requirements.outputs.requires_strategy_config_path }}' "$workflow_file"
64+
grep -Fq 'HAS_BUNDLED_STRATEGY_CONFIG: ${{ steps.strategy_requirements.outputs.has_bundled_strategy_config }}' "$workflow_file"
6265
grep -Fq 'if [ "${REQUIRES_SNAPSHOT_ARTIFACTS:-}" = "true" ] && [ -z "${LONGBRIDGE_FEATURE_SNAPSHOT_PATH:-}" ]; then' "$workflow_file"
6366
grep -Fq 'if [ "${REQUIRES_SNAPSHOT_MANIFEST_PATH:-}" = "true" ] && [ -z "${LONGBRIDGE_FEATURE_SNAPSHOT_MANIFEST_PATH:-}" ]; then' "$workflow_file"
64-
grep -Fq 'if [ "${REQUIRES_STRATEGY_CONFIG_PATH:-}" = "true" ] && [ -z "${LONGBRIDGE_STRATEGY_CONFIG_PATH:-}" ]; then' "$workflow_file"
67+
grep -Fq '&& [ "${HAS_BUNDLED_STRATEGY_CONFIG:-}" != "true" ]; then' "$workflow_file"
6568
grep -Fq 'secret_pairs+=("TELEGRAM_TOKEN=${TELEGRAM_TOKEN_SECRET_NAME}:latest")' "$workflow_file"
6669
grep -Fq 'secret_pairs+=("LONGPORT_APP_KEY=${LONGPORT_APP_KEY_SECRET_NAME}:latest")' "$workflow_file"
6770
grep -Fq 'secret_pairs+=("LONGPORT_APP_SECRET=${LONGPORT_APP_SECRET_SECRET_NAME}:latest")' "$workflow_file"

0 commit comments

Comments
 (0)