13
13
from functools import cached_property
14
14
from pathlib import Path
15
15
from textwrap import dedent
16
- from typing import ClassVar , List , Optional , Set
16
+ from typing import Any , ClassVar , Dict , List , Optional , Set
17
17
18
18
import requests # type: ignore
19
19
import semver
@@ -445,7 +445,7 @@ async def _run(self, current_acceptance_tests_result: StepResult) -> StepResult:
445
445
446
446
447
447
class LiveTestSuite (Enum ):
448
- ALL = "all "
448
+ ALL = "live "
449
449
REGRESSION = "regression"
450
450
VALIDATION = "validation"
451
451
@@ -557,13 +557,10 @@ def __init__(self, context: ConnectorContext) -> None:
557
557
self .connector_image = context .docker_image .split (":" )[0 ]
558
558
options = self .context .run_step_options .step_params .get (CONNECTOR_TEST_STEP_ID .CONNECTOR_LIVE_TESTS , {})
559
559
560
- self .connection_id = self .context .run_step_options .get_item_or_default (options , "connection-id" , None )
561
- self .pr_url = self .context .run_step_options .get_item_or_default (options , "pr-url" , None )
562
-
563
- if not self .connection_id and self .pr_url :
564
- raise ValueError ("`connection-id` and `pr-url` are required to run live tests." )
565
-
566
560
self .test_suite = self .context .run_step_options .get_item_or_default (options , "test-suite" , LiveTestSuite .ALL .value )
561
+ self .connection_id = self ._get_connection_id (options )
562
+ self .pr_url = self ._get_pr_url (options )
563
+
567
564
self .test_dir = self .test_suite_to_dir [LiveTestSuite (self .test_suite )]
568
565
self .control_version = self .context .run_step_options .get_item_or_default (options , "control-version" , None )
569
566
self .target_version = self .context .run_step_options .get_item_or_default (options , "target-version" , "dev" )
@@ -573,7 +570,30 @@ def __init__(self, context: ConnectorContext) -> None:
573
570
self .connection_subset = self .context .run_step_options .get_item_or_default (options , "connection-subset" , "sandboxes" )
574
571
self .run_id = os .getenv ("GITHUB_RUN_ID" ) or str (int (time .time ()))
575
572
573
+ def _get_connection_id (self , options : Dict [str , List [Any ]]) -> Optional [str ]:
574
+ if self .context .is_pr :
575
+ connection_id = self ._get_connection_from_connection_options ()
576
+ self .logger .info (
577
+ f"Context is { self .context .ci_context } ; got connection_id={ connection_id } from metadata.yaml liveTests connectionOptions."
578
+ )
579
+ else :
580
+ connection_id = self .context .run_step_options .get_item_or_default (options , "connection-id" , None )
581
+ self .logger .info (f"Context is { self .context .ci_context } ; got connection_id={ connection_id } from input options." )
582
+ return connection_id
583
+
584
+ def _get_pr_url (self , options : Dict [str , List [Any ]]) -> Optional [str ]:
585
+ if self .context .is_pr :
586
+ pull_request = self .context .pull_request .url if self .context .pull_request else None
587
+ self .logger .info (f"Context is { self .context .ci_context } ; got pull_request={ pull_request } from context." )
588
+ else :
589
+ pull_request = self .context .run_step_options .get_item_or_default (options , "pr-url" , None )
590
+ self .logger .info (f"Context is { self .context .ci_context } ; got pull_request={ pull_request } from input options." )
591
+ return pull_request
592
+
576
593
def _validate_job_can_run (self ) -> None :
594
+ assert self .connection_id , "`connection-id` is required to run live tests."
595
+ assert self .pr_url , "`pr_url` is required to run live tests."
596
+
577
597
connector_type = self .context .connector .metadata .get ("connectorType" )
578
598
connector_subtype = self .context .connector .metadata .get ("connectorSubtype" )
579
599
assert connector_type == "source" , f"Live tests can only run against source connectors, got `connectorType={ connector_type } `."
@@ -582,6 +602,24 @@ def _validate_job_can_run(self) -> None:
582
602
self .connection_subset == "sandboxes"
583
603
), f"Live tests for database sources may only be run against sandbox connections, got `connection_subset={ self .connection_subset } `."
584
604
605
+ if self .context .is_pr :
606
+ connection_id_is_valid = False
607
+ for test_suite in self .context .connector .metadata .get ("connectorTestSuitesOptions" , []):
608
+ if test_suite ["suite" ] == "liveTests" :
609
+ assert self .connection_id in [option ["connectionId" ] for option in test_suite .get ("connectionOptions" , [])]
610
+ connection_id_is_valid = True
611
+ break
612
+ assert connection_id_is_valid , f"Connection ID { self .connection_id } is not a valid sandbox connection ID."
613
+
614
+ def _get_connection_from_connection_options (self ) -> Optional [str ]:
615
+ for test_suite in self .context .connector .metadata .get ("connectorTestSuitesOptions" , []):
616
+ if test_suite ["suite" ] == "liveTests" :
617
+ for option in test_suite .get ("connectionOptions" , []):
618
+ connection_id = option ["connectionId" ]
619
+ connection_name = option ["connectionName" ]
620
+ self .logger .info (f"Using connection { connection_name } ; connectionId={ connection_id } " )
621
+ return connection_id
622
+
585
623
async def _run (self , connector_under_test_container : Container ) -> StepResult :
586
624
"""Run the regression test suite.
587
625
@@ -676,16 +714,17 @@ async def _build_test_container(self, target_container_id: str) -> Container:
676
714
]
677
715
)
678
716
.with_secret_variable (
679
- "CI_GITHUB_ACCESS_TOKEN " ,
717
+ "CI_GITHUB_MAINTENANCE_TOKEN " ,
680
718
self .context .dagger_client .set_secret (
681
- "CI_GITHUB_ACCESS_TOKEN" , self .context .ci_github_access_token .value if self .context .ci_github_access_token else ""
719
+ "CI_GITHUB_MAINTENANCE_TOKEN" ,
720
+ self .context .ci_github_maintenance_token .value if self .context .ci_github_maintenance_token else "" ,
682
721
),
683
722
)
684
723
.with_exec (
685
724
[
686
725
"/bin/sh" ,
687
726
"-c" ,
688
- f"poetry config http-basic.airbyte-platform-internal-source { self .github_user } $CI_GITHUB_ACCESS_TOKEN " ,
727
+ f"poetry config http-basic.airbyte-platform-internal-source { self .github_user } $CI_GITHUB_MAINTENANCE_TOKEN " ,
689
728
]
690
729
)
691
730
# Add GCP credentials from the environment and point google to their location (also required for connection-retriever)
0 commit comments