1
1
#
2
2
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
3
3
#
4
+ import xml .etree .ElementTree as ET
4
5
from abc import ABC
5
6
from datetime import datetime
6
7
from typing import Any , ClassVar , List , Optional , Tuple , cast
7
8
8
9
import pipelines .dagger .actions .system .docker
10
+ import requests
9
11
from dagger import CacheSharingMode , CacheVolume , Container , ExecError
10
12
from pipelines .airbyte_ci .connectors .context import ConnectorContext
11
13
from pipelines .consts import AMAZONCORRETTO_IMAGE
@@ -32,6 +34,9 @@ class GradleTask(Step, ABC):
32
34
GRADLE_DEP_CACHE_PATH = "/root/gradle-cache"
33
35
GRADLE_HOME_PATH = "/root/.gradle"
34
36
STATIC_GRADLE_OPTIONS = ("--no-daemon" , "--no-watch-fs" , "--build-cache" , "--scan" , "--console=plain" )
37
+ CDK_MAVEN_METADATA_URL = (
38
+ "https://airbyte.mycloudrepo.io/public/repositories/airbyte-public-jars/io/airbyte/cdk/airbyte-cdk-core/maven-metadata.xml"
39
+ )
35
40
gradle_task_name : ClassVar [str ]
36
41
bind_to_docker_host : ClassVar [bool ] = False
37
42
mount_connector_secrets : ClassVar [bool ] = False
@@ -65,6 +70,14 @@ def _get_gradle_command(self, task: str, *args: Any, task_options: Optional[List
65
70
task_options = task_options or []
66
71
return f"./gradlew { ' ' .join (self .gradle_task_options + args )} { task } { ' ' .join (task_options )} "
67
72
73
+ def get_last_cdk_update_time (self ) -> str :
74
+ response = requests .get (self .CDK_MAVEN_METADATA_URL )
75
+ response .raise_for_status ()
76
+ last_updated = ET .fromstring (response .text ).find (".//lastUpdated" )
77
+ if last_updated is None or last_updated .text is None :
78
+ raise ValueError (f"Could not find the lastUpdated field in the CDK maven metadata at { self .CDK_MAVEN_METADATA_URL } " )
79
+ return last_updated .text
80
+
68
81
async def _run (self , * args : Any , ** kwargs : Any ) -> StepResult :
69
82
include = [
70
83
".root" ,
@@ -150,6 +163,8 @@ async def _run(self, *args: Any, **kwargs: Any) -> StepResult:
150
163
gradle_container_base
151
164
# Mount the whole repo.
152
165
.with_directory ("/airbyte" , self .context .get_repo_dir ("." ))
166
+ # Burst the cache if a new CDK version was released.
167
+ .with_env_variable ("CDK_LAST_UPDATE" , self .get_last_cdk_update_time ())
153
168
# Update the cache in place by executing a gradle task which will update all dependencies.
154
169
.with_exec (
155
170
sh_dash_c (
0 commit comments