Skip to content

Commit 678c52d

Browse files
authored
Merge pull request ClickHouse#77373 from ClickHouse/ci_support_gh_vars_in_praktika
CI: Support GH Vars in praktika
2 parents 4ffc74b + f10d0df commit 678c52d

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

ci/praktika/parser.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class JobAddonYaml:
4949
job_to_config: Dict[str, JobYaml]
5050
artifact_to_config: Dict[str, ArtifactYaml]
5151
secret_names_gh: List[str]
52+
variable_names_gh: List[str]
5253
enable_cache: bool
5354
cron_schedules: List[str]
5455
dispatch_inputs: List[Workflow.Config.InputConfig]
@@ -74,6 +75,7 @@ def __init__(self, config: Workflow.Config):
7475
branches=[],
7576
jobs=[],
7677
secret_names_gh=[],
78+
variable_names_gh=[],
7779
job_to_config={},
7880
artifact_to_config={},
7981
enable_cache=False,
@@ -249,9 +251,10 @@ def parse(self):
249251

250252
# populate secrets
251253
for secret_config in self.config.secrets:
252-
if secret_config.is_gh():
254+
if secret_config.is_gh_secret():
253255
self.workflow_yaml_config.secret_names_gh.append(secret_config.name)
254-
256+
elif secret_config.is_gh_var():
257+
self.workflow_yaml_config.variable_names_gh.append(secret_config.name)
255258
return self
256259

257260

ci/praktika/secret.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,25 @@ class Type:
99
AWS_SSM_VAR = "aws parameter"
1010
AWS_SSM_SECRET = "aws secret"
1111
GH_SECRET = "gh secret"
12+
GH_VAR = "gh var"
1213

1314
@dataclasses.dataclass
1415
class Config:
1516
name: str
1617
type: str
1718

18-
def is_gh(self):
19+
def is_gh_secret(self):
1920
return self.type == Secret.Type.GH_SECRET
2021

22+
def is_gh_var(self):
23+
return self.type == Secret.Type.GH_VAR
24+
2125
def get_value(self):
2226
if self.type == Secret.Type.AWS_SSM_VAR:
2327
return self.get_aws_ssm_var()
2428
if self.type == Secret.Type.AWS_SSM_SECRET:
2529
return self.get_aws_ssm_secret()
26-
elif self.type == Secret.Type.GH_SECRET:
30+
elif self.type in (Secret.Type.GH_SECRET, Secret.Type.GH_VAR):
2731
return self.get_gh_secret()
2832
else:
2933
assert False, f"Not supported secret type, secret [{self}]"

ci/praktika/yaml_generator.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ class Templates:
6262
TEMPLATE_ENV_SECRET = """\
6363
{SECRET_NAME}: ${{{{{{{{ secrets.{SECRET_NAME} }}}}}}}}
6464
"""
65+
TEMPLATE_ENV_GH_VAR = """\
66+
{VAR_NAME}: ${{{{{{{{ vars.{VAR_NAME} }}}}}}}}
67+
"""
6568

6669
TEMPLATE_SCHEDULE = """\
6770
# generated by praktika
@@ -166,6 +169,13 @@ class Templates:
166169
)\
167170
"""
168171

172+
TEMPLATE_SETUP_ENV_VARS = """\
173+
export {VAR_NAME}=$(cat<<'EOF'
174+
${{{{ vars.{VAR_NAME} }}}}
175+
EOF
176+
)\
177+
"""
178+
169179
TEMPLATE_SETUP_ENVS_INPUTS = """\
170180
cat > {WORKFLOW_INPUTS_FILE} << 'EOF'
171181
${{{{ toJson(github.event.inputs) }}}}
@@ -313,6 +323,10 @@ def generate(self):
313323
SECRET_NAME=secret
314324
)
315325
)
326+
for var in self.workflow_config.variable_names_gh:
327+
secrets_envs.append(
328+
YamlGenerator.Templates.TEMPLATE_SETUP_ENV_VARS.format(VAR_NAME=var)
329+
)
316330
if self.workflow_config.event == Workflow.Event.DISPATCH:
317331
secrets_envs.append(
318332
YamlGenerator.Templates.TEMPLATE_SETUP_ENVS_INPUTS.format(
@@ -419,12 +433,17 @@ def generate(self):
419433
), f"Invalid or Not implemented event [{self.workflow_config.event}]"
420434

421435
SECRET_ENVS = ""
436+
GH_VAR_ENVS = ""
422437
for secret in self.parser.config.secrets:
423-
if secret.is_gh():
438+
if secret.is_gh_secret():
424439
SECRET_ENVS += YamlGenerator.Templates.TEMPLATE_ENV_SECRET.format(
425440
SECRET_NAME=secret.name
426441
)
427-
format_kwargs["ENV_SECRETS"] = SECRET_ENVS
442+
elif secret.is_gh_var():
443+
GH_VAR_ENVS += YamlGenerator.Templates.TEMPLATE_ENV_GH_VAR.format(
444+
VAR_NAME=secret.name
445+
)
446+
format_kwargs["ENV_SECRETS"] = GH_VAR_ENVS + SECRET_ENVS
428447

429448
template_1 = base_template.strip().format(
430449
NAME=self.workflow_config.name,

0 commit comments

Comments
 (0)