From 055bd4bc2ceb19d8f5b61b1b279e83c521cf5386 Mon Sep 17 00:00:00 2001 From: Pigbibi <20649888+Pigbibi@users.noreply.github.com> Date: Thu, 16 Apr 2026 03:00:25 +0800 Subject: [PATCH] Allow bundled strategy config in env sync --- .github/workflows/sync-cloud-run-env.yml | 46 +++++++++++++++++++++-- tests/test_sync_cloud_run_env_workflow.sh | 7 +++- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/.github/workflows/sync-cloud-run-env.yml b/.github/workflows/sync-cloud-run-env.yml index 2b8b4b6..9157780 100644 --- a/.github/workflows/sync-cloud-run-env.yml +++ b/.github/workflows/sync-cloud-run-env.yml @@ -78,7 +78,10 @@ jobs: import os import subprocess import sys - from us_equity_strategies import resolve_canonical_profile + from pathlib import Path + + from quant_platform_kit.common.strategies import derive_strategy_artifact_paths + from us_equity_strategies import get_strategy_catalog, resolve_canonical_profile profile = os.environ.get("STRATEGY_PROFILE", "").strip().lower() if not profile: @@ -97,6 +100,16 @@ jobs: if not selected.get("eligible") or not selected.get("enabled"): raise SystemExit(f"STRATEGY_PROFILE={profile!r} is not eligible/enabled: {selected}") + artifact_paths = derive_strategy_artifact_paths( + get_strategy_catalog(), + canonical_profile, + repo_root=Path.cwd(), + ) + has_bundled_strategy_config = bool( + artifact_paths.bundled_config_path is not None + and Path(artifact_paths.bundled_config_path).exists() + ) + output_path = os.environ["GITHUB_OUTPUT"] with open(output_path, "a", encoding="utf-8") as output: output.write( @@ -108,6 +121,9 @@ jobs: output.write( f"requires_strategy_config_path={str(bool(selected.get('requires_strategy_config_path'))).lower()}\n" ) + output.write( + f"has_bundled_strategy_config={str(has_bundled_strategy_config).lower()}\n" + ) PY - name: Validate HK env sync inputs @@ -116,6 +132,7 @@ jobs: REQUIRES_SNAPSHOT_ARTIFACTS: ${{ steps.strategy_requirements.outputs.requires_snapshot_artifacts }} REQUIRES_SNAPSHOT_MANIFEST_PATH: ${{ steps.strategy_requirements.outputs.requires_snapshot_manifest_path }} REQUIRES_STRATEGY_CONFIG_PATH: ${{ steps.strategy_requirements.outputs.requires_strategy_config_path }} + HAS_BUNDLED_STRATEGY_CONFIG: ${{ steps.strategy_requirements.outputs.has_bundled_strategy_config }} run: | set -euo pipefail @@ -155,7 +172,9 @@ jobs: missing_vars+=("LONGBRIDGE_FEATURE_SNAPSHOT_MANIFEST_PATH") fi - if [ "${REQUIRES_STRATEGY_CONFIG_PATH:-}" = "true" ] && [ -z "${LONGBRIDGE_STRATEGY_CONFIG_PATH:-}" ]; then + if [ "${REQUIRES_STRATEGY_CONFIG_PATH:-}" = "true" ] \ + && [ -z "${LONGBRIDGE_STRATEGY_CONFIG_PATH:-}" ] \ + && [ "${HAS_BUNDLED_STRATEGY_CONFIG:-}" != "true" ]; then missing_vars+=("LONGBRIDGE_STRATEGY_CONFIG_PATH") fi @@ -355,7 +374,10 @@ jobs: import os import subprocess import sys - from us_equity_strategies import resolve_canonical_profile + from pathlib import Path + + from quant_platform_kit.common.strategies import derive_strategy_artifact_paths + from us_equity_strategies import get_strategy_catalog, resolve_canonical_profile profile = os.environ.get("STRATEGY_PROFILE", "").strip().lower() if not profile: @@ -374,6 +396,16 @@ jobs: if not selected.get("eligible") or not selected.get("enabled"): raise SystemExit(f"STRATEGY_PROFILE={profile!r} is not eligible/enabled: {selected}") + artifact_paths = derive_strategy_artifact_paths( + get_strategy_catalog(), + canonical_profile, + repo_root=Path.cwd(), + ) + has_bundled_strategy_config = bool( + artifact_paths.bundled_config_path is not None + and Path(artifact_paths.bundled_config_path).exists() + ) + output_path = os.environ["GITHUB_OUTPUT"] with open(output_path, "a", encoding="utf-8") as output: output.write( @@ -385,6 +417,9 @@ jobs: output.write( f"requires_strategy_config_path={str(bool(selected.get('requires_strategy_config_path'))).lower()}\n" ) + output.write( + f"has_bundled_strategy_config={str(has_bundled_strategy_config).lower()}\n" + ) PY - name: Validate SG env sync inputs @@ -393,6 +428,7 @@ jobs: REQUIRES_SNAPSHOT_ARTIFACTS: ${{ steps.strategy_requirements.outputs.requires_snapshot_artifacts }} REQUIRES_SNAPSHOT_MANIFEST_PATH: ${{ steps.strategy_requirements.outputs.requires_snapshot_manifest_path }} REQUIRES_STRATEGY_CONFIG_PATH: ${{ steps.strategy_requirements.outputs.requires_strategy_config_path }} + HAS_BUNDLED_STRATEGY_CONFIG: ${{ steps.strategy_requirements.outputs.has_bundled_strategy_config }} run: | set -euo pipefail @@ -432,7 +468,9 @@ jobs: missing_vars+=("LONGBRIDGE_FEATURE_SNAPSHOT_MANIFEST_PATH") fi - if [ "${REQUIRES_STRATEGY_CONFIG_PATH:-}" = "true" ] && [ -z "${LONGBRIDGE_STRATEGY_CONFIG_PATH:-}" ]; then + if [ "${REQUIRES_STRATEGY_CONFIG_PATH:-}" = "true" ] \ + && [ -z "${LONGBRIDGE_STRATEGY_CONFIG_PATH:-}" ] \ + && [ "${HAS_BUNDLED_STRATEGY_CONFIG:-}" != "true" ]; then missing_vars+=("LONGBRIDGE_STRATEGY_CONFIG_PATH") fi diff --git a/tests/test_sync_cloud_run_env_workflow.sh b/tests/test_sync_cloud_run_env_workflow.sh index 7a17358..4ba69f7 100644 --- a/tests/test_sync_cloud_run_env_workflow.sh +++ b/tests/test_sync_cloud_run_env_workflow.sh @@ -15,11 +15,13 @@ grep -Fq 'uses: actions/setup-python@v5' "$workflow_file" grep -Fq 'python -m pip install -r requirements.txt' "$workflow_file" grep -Fq 'id: strategy_requirements' "$workflow_file" grep -Fq 'scripts/print_strategy_profile_status.py' "$workflow_file" -grep -Fq 'from us_equity_strategies import resolve_canonical_profile' "$workflow_file" +grep -Fq 'from quant_platform_kit.common.strategies import derive_strategy_artifact_paths' "$workflow_file" +grep -Fq 'from us_equity_strategies import get_strategy_catalog, resolve_canonical_profile' "$workflow_file" grep -Fq 'canonical_profile = resolve_canonical_profile(profile)' "$workflow_file" grep -Fq 'requires_snapshot_artifacts=' "$workflow_file" grep -Fq 'requires_snapshot_manifest_path=' "$workflow_file" grep -Fq 'requires_strategy_config_path=' "$workflow_file" +grep -Fq 'has_bundled_strategy_config=' "$workflow_file" grep -Fq 'Wait for Cloud Run deployment of current commit' "$workflow_file" grep -Fq 'target_sha="${GITHUB_SHA}"' "$workflow_file" 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" grep -Fq 'REQUIRES_SNAPSHOT_ARTIFACTS: ${{ steps.strategy_requirements.outputs.requires_snapshot_artifacts }}' "$workflow_file" grep -Fq 'REQUIRES_SNAPSHOT_MANIFEST_PATH: ${{ steps.strategy_requirements.outputs.requires_snapshot_manifest_path }}' "$workflow_file" grep -Fq 'REQUIRES_STRATEGY_CONFIG_PATH: ${{ steps.strategy_requirements.outputs.requires_strategy_config_path }}' "$workflow_file" +grep -Fq 'HAS_BUNDLED_STRATEGY_CONFIG: ${{ steps.strategy_requirements.outputs.has_bundled_strategy_config }}' "$workflow_file" grep -Fq 'if [ "${REQUIRES_SNAPSHOT_ARTIFACTS:-}" = "true" ] && [ -z "${LONGBRIDGE_FEATURE_SNAPSHOT_PATH:-}" ]; then' "$workflow_file" grep -Fq 'if [ "${REQUIRES_SNAPSHOT_MANIFEST_PATH:-}" = "true" ] && [ -z "${LONGBRIDGE_FEATURE_SNAPSHOT_MANIFEST_PATH:-}" ]; then' "$workflow_file" -grep -Fq 'if [ "${REQUIRES_STRATEGY_CONFIG_PATH:-}" = "true" ] && [ -z "${LONGBRIDGE_STRATEGY_CONFIG_PATH:-}" ]; then' "$workflow_file" +grep -Fq '&& [ "${HAS_BUNDLED_STRATEGY_CONFIG:-}" != "true" ]; then' "$workflow_file" grep -Fq 'secret_pairs+=("TELEGRAM_TOKEN=${TELEGRAM_TOKEN_SECRET_NAME}:latest")' "$workflow_file" grep -Fq 'secret_pairs+=("LONGPORT_APP_KEY=${LONGPORT_APP_KEY_SECRET_NAME}:latest")' "$workflow_file" grep -Fq 'secret_pairs+=("LONGPORT_APP_SECRET=${LONGPORT_APP_SECRET_SECRET_NAME}:latest")' "$workflow_file"