|
9 | 9 |
|
10 | 10 | REPO = Path(__file__).resolve().parents[2] |
11 | 11 | PRODUCTION_CLOUD_SQL_INSTANCE = "policyengine-api:us-central1:policyengine-api-data" |
| 12 | +STAGING_CLOUD_RUN_SERVICE = "policyengine-api-staging" |
12 | 13 | DEDICATED_CLOUD_RUN_RUNTIME_SERVICE_ACCOUNT = ( |
13 | 14 | "policyengine-api-cr-runtime@policyengine-api.iam.gserviceaccount.com" |
14 | 15 | ) |
@@ -384,6 +385,67 @@ def test_promote_cloud_run_tag_dry_run_shifts_service_traffic_to_tag(): |
384 | 385 | assert "--to-latest" not in result.stdout |
385 | 386 |
|
386 | 387 |
|
| 388 | +def test_push_workflow_isolates_staging_cloud_run_service(): |
| 389 | + workflow = _push_workflow() |
| 390 | + staging_deploy = _workflow_job_block(workflow, "deploy-cloud-run-staging") |
| 391 | + staging_promote = _workflow_job_block(workflow, "promote-cloud-run-staging") |
| 392 | + production_deploy = _workflow_job_block(workflow, "deploy-cloud-run-candidate") |
| 393 | + |
| 394 | + staging_service_env = f"CLOUD_RUN_SERVICE: {STAGING_CLOUD_RUN_SERVICE}" |
| 395 | + assert staging_service_env in staging_deploy |
| 396 | + assert staging_service_env in staging_promote |
| 397 | + assert STAGING_CLOUD_RUN_SERVICE not in production_deploy |
| 398 | + |
| 399 | + |
| 400 | +def test_build_cloud_run_image_uri_is_independent_of_service_override(): |
| 401 | + result = _run_script( |
| 402 | + ".github/scripts/build_cloud_run_image.sh", |
| 403 | + _script_env( |
| 404 | + GITHUB_SHA="1234567890abcdef", |
| 405 | + GITHUB_RUN_NUMBER="42", |
| 406 | + CLOUD_RUN_SERVICE=STAGING_CLOUD_RUN_SERVICE, |
| 407 | + ), |
| 408 | + ) |
| 409 | + |
| 410 | + assert result.returncode == 0, result.stderr |
| 411 | + assert ( |
| 412 | + "us-central1-docker.pkg.dev/policyengine-api/policyengine-api/" |
| 413 | + "policyengine-api:1234567890abcdef" |
| 414 | + ) in result.stdout |
| 415 | + assert f"{STAGING_CLOUD_RUN_SERVICE}:" not in result.stdout |
| 416 | + |
| 417 | + |
| 418 | +def test_deploy_cloud_run_candidate_dry_run_targets_service_override(): |
| 419 | + result = _run_script( |
| 420 | + ".github/scripts/deploy_cloud_run_candidate.sh", |
| 421 | + _script_env( |
| 422 | + **_required_runtime_env(), |
| 423 | + CLOUD_RUN_IMAGE_URI="us-central1-docker.pkg.dev/project/repo/api:sha", |
| 424 | + CLOUD_RUN_TAG="stage3-test", |
| 425 | + CLOUD_RUN_SERVICE=STAGING_CLOUD_RUN_SERVICE, |
| 426 | + ), |
| 427 | + ) |
| 428 | + |
| 429 | + assert result.returncode == 0, result.stderr |
| 430 | + assert f"gcloud run deploy {STAGING_CLOUD_RUN_SERVICE}" in result.stdout |
| 431 | + |
| 432 | + |
| 433 | +def test_promote_cloud_run_tag_dry_run_targets_service_override(): |
| 434 | + result = _run_script( |
| 435 | + ".github/scripts/promote_cloud_run_tag.sh", |
| 436 | + _script_env( |
| 437 | + CLOUD_RUN_TAG="stage3-test", |
| 438 | + CLOUD_RUN_SERVICE=STAGING_CLOUD_RUN_SERVICE, |
| 439 | + ), |
| 440 | + ) |
| 441 | + |
| 442 | + assert result.returncode == 0, result.stderr |
| 443 | + assert ( |
| 444 | + f"gcloud run services update-traffic {STAGING_CLOUD_RUN_SERVICE}" |
| 445 | + in result.stdout |
| 446 | + ) |
| 447 | + |
| 448 | + |
387 | 449 | def test_push_workflow_tests_app_engine_and_cloud_run_staging_tracks(): |
388 | 450 | workflow = _push_workflow() |
389 | 451 | app_engine_tests = _workflow_job_block(workflow, "integration-tests-staging") |
|
0 commit comments