opentf-toolkit-nightly 0.59.0.dev1182__py3-none-any.whl → 0.59.0.dev1200__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,132 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2019-09/schema#",
3
+ "title": "JSON SCHEMA for opentestfactory.org/v1 ExecutionResult manifests",
4
+ "type": "object",
5
+ "properties": {
6
+ "apiVersion": {
7
+ "const": "opentestfactory.org/v1"
8
+ },
9
+ "kind": {
10
+ "const": "ExecutionResult"
11
+ },
12
+ "metadata": {
13
+ "type": "object",
14
+ "properties": {
15
+ "name": {
16
+ "type": "string"
17
+ },
18
+ "workflow_id": {
19
+ "type": "string"
20
+ },
21
+ "job_id": {
22
+ "type": "string"
23
+ },
24
+ "job_origin": {
25
+ "type": "array",
26
+ "items": {
27
+ "type": "string"
28
+ }
29
+ },
30
+ "step_id": {
31
+ "type": "string"
32
+ },
33
+ "step_origin": {
34
+ "type": "array",
35
+ "items": {
36
+ "type": "string"
37
+ }
38
+ },
39
+ "step_origin_status": {
40
+ "type": "object",
41
+ "patternProperties": {
42
+ "^[a-zA-Z0-9-]+$": {
43
+ "type": "number"
44
+ }
45
+ }
46
+ },
47
+ "step_sequence_id": {
48
+ "type": "number"
49
+ },
50
+ "labels": {
51
+ "type": "object",
52
+ "patternProperties": {
53
+ "^([a-zA-Z0-9-.]+/)?[a-zA-Z0-9]([a-zA-Z0-9._-]*[a-zA-Z0-9])?$": {
54
+ "type": "string"
55
+ }
56
+ },
57
+ "minProperties": 1,
58
+ "additionalProperties": false
59
+ },
60
+ "attachments": {
61
+ "type": "object",
62
+ "minProperties": 1
63
+ }
64
+ },
65
+ "additionalProperties": true,
66
+ "required": [
67
+ "name",
68
+ "workflow_id",
69
+ "job_id",
70
+ "step_id",
71
+ "step_sequence_id"
72
+ ]
73
+ },
74
+ "attachments": {
75
+ "type": "array",
76
+ "items": {
77
+ "type": "string"
78
+ },
79
+ "minItems": 1
80
+ },
81
+ "outputs": {
82
+ "type": "object",
83
+ "patternProperties": {
84
+ "^[a-zA-Z_][a-zA-Z0-9_-]+$": {
85
+ "type": "string"
86
+ }
87
+ },
88
+ "minProperties": 1,
89
+ "additionalProperties": false
90
+ },
91
+ "logs": {
92
+ "type": "array",
93
+ "items": {
94
+ "type": "string"
95
+ }
96
+ },
97
+ "status": {
98
+ "type": "number"
99
+ },
100
+ "variables": {
101
+ "type": "object",
102
+ "patternProperties": {
103
+ "^[a-zA-Z0-9_]+$": {
104
+ "oneOf": [
105
+ {
106
+ "type": "string"
107
+ },
108
+ {
109
+ "type": "object",
110
+ "properties": {
111
+ "value": {
112
+ "type": "string"
113
+ }
114
+ },
115
+ "required": [
116
+ "value"
117
+ ],
118
+ "additionalProperties": false
119
+ }
120
+ ]
121
+ }
122
+ },
123
+ "minProperties": 1
124
+ }
125
+ },
126
+ "required": [
127
+ "apiVersion",
128
+ "kind",
129
+ "metadata"
130
+ ],
131
+ "additionalProperties": false
132
+ }
@@ -96,6 +96,31 @@
96
96
  },
97
97
  "status": {
98
98
  "type": "number"
99
+ },
100
+ "variables": {
101
+ "type": "object",
102
+ "patternProperties": {
103
+ "^[a-zA-Z0-9_]+$": {
104
+ "oneOf": [
105
+ {
106
+ "type": "string"
107
+ },
108
+ {
109
+ "type": "object",
110
+ "properties": {
111
+ "value": {
112
+ "type": "string"
113
+ }
114
+ },
115
+ "required": [
116
+ "value"
117
+ ],
118
+ "additionalProperties": false
119
+ }
120
+ ]
121
+ }
122
+ },
123
+ "minProperties": 1
99
124
  }
100
125
  },
101
126
  "required": [
@@ -127,6 +127,8 @@ REMOVE_WORKSPACE = 2
127
127
  MOVE_TO_WORKSPACE = 3
128
128
 
129
129
  HOOKS_ANNOTATIONS = 'opentestfactory.org/hooks'
130
+ OPENTF_VARIABLES_TYPE = 'application/vnd.opentestfactory.opentf-variables'
131
+ OPENTF_VARIABLES_REGEX = re.compile(r'^(export|set)\s(\"?.+)$')
130
132
 
131
133
  ## os helpers
132
134
 
@@ -219,6 +221,40 @@ def _as_log(line: str, jobstate: JobState):
219
221
  return mask(line, jobstate).rstrip()
220
222
 
221
223
 
224
+ def _get_opentf_variables(path: str):
225
+ variables = {}
226
+ with open(path, 'r') as f:
227
+ content = f.readlines()
228
+ for line in content:
229
+ if '=' not in line:
230
+ continue
231
+ line = line.strip()
232
+ if set_export := OPENTF_VARIABLES_REGEX.match(line):
233
+ expr = set_export.group(2)
234
+ if expr.startswith('"'):
235
+ expr = expr[1:-1]
236
+ key, _, value = expr.partition('=')
237
+ else:
238
+ key, _, value = line.partition('=')
239
+ variables[key] = value
240
+ return variables
241
+
242
+
243
+ def process_opentf_variables(result: Dict[str, Any]):
244
+ if attachments := result['metadata'].get('attachments'):
245
+ variables = {}
246
+ for path, data in attachments.copy().items():
247
+ if data.get('type') == OPENTF_VARIABLES_TYPE:
248
+ variables = _get_opentf_variables(path)
249
+ del result['metadata']['attachments'][path]
250
+ result['attachments'].remove(path)
251
+ if not result['metadata']['attachments']:
252
+ del result['metadata']['attachments']
253
+ if not result['attachments']:
254
+ del result['attachments']
255
+ result['variables'] = variables
256
+
257
+
222
258
  def process_upload(result: Dict[str, Any]):
223
259
  """Process ExecutionResult event containing .metadata.upload flag.
224
260
 
@@ -394,6 +430,17 @@ def process_output(
394
430
  return result
395
431
 
396
432
 
433
+ def _attach_opentf_variables(runner_os: str, script: List[str]):
434
+ if runner_os == 'windows':
435
+ script.append(
436
+ f'@if exist "%OPENTF_VARIABLES%" echo ::attach type={OPENTF_VARIABLES_TYPE}::%OPENTF_VARIABLES%'
437
+ )
438
+ else:
439
+ script.append(
440
+ f'if [ -f "$OPENTF_VARIABLES" ]; then echo "::attach type={OPENTF_VARIABLES_TYPE}::"$OPENTF_VARIABLES""; fi'
441
+ )
442
+
443
+
397
444
  def _export_opentf_workspace(runner_os: str, workspace: str, script: List[str]) -> None:
398
445
  opentf_workspace = WORKSPACE_TEMPLATE[runner_os].format(workspace=workspace)
399
446
  if runner_os == 'windows':
@@ -465,10 +512,18 @@ def _make_prolog(
465
512
  script: List[str],
466
513
  command: Dict[str, Any],
467
514
  ) -> None:
515
+ local_variables_names = (
516
+ command['metadata'].get('annotations', {}).get('local_variables_names', [])
517
+ )
468
518
  for name, value in command.get('variables', {}).items():
469
- script.append(VARIABLE_MAKER[runner_os](name, value))
519
+ if name not in local_variables_names:
520
+ script.append(VARIABLE_MAKER[runner_os](name, value))
470
521
 
471
522
  script.append(PROLOG_SCRIPTS[runner_os][LOAD_VARIABLES])
523
+ for name, value in command.get('variables', {}).items():
524
+ if name in local_variables_names:
525
+ script.append(VARIABLE_MAKER[runner_os](name, value))
526
+
472
527
  if step_sequence_id == CHANNEL_RELEASE:
473
528
  # on windows, the script ends if it is removed, so script
474
529
  # removal should be the last operation
@@ -570,6 +625,7 @@ def make_script(
570
625
  _maybe_create_workspace(metadata, runner_os, step_sequence_id, script)
571
626
  _make_prolog(runner_os, job_id, step_sequence_id, root, script, command)
572
627
  _maybe_change_directory(command, runner_os, script, prefix)
628
+ _attach_opentf_variables(runner_os, script)
573
629
 
574
630
  if command.get('shell') in (None, SHELL_DEFAULT[runner_os]):
575
631
  script += command['scripts']
opentf/toolkit/core.py CHANGED
@@ -280,12 +280,15 @@ def export_variables(*args, verbatim: bool = False) -> List[Dict[str, str]]:
280
280
 
281
281
  Returns a list of steps.
282
282
  """
283
- return [
284
- {'run': export_variable(name, value, verbatim)}
285
- for var_dict in args
286
- if var_dict
287
- for name, value in var_dict.items()
288
- ]
283
+ exports = '\n'.join(
284
+ (
285
+ export_variable(name, value, verbatim)
286
+ for var_dict in args
287
+ if var_dict
288
+ for name, value in var_dict.items()
289
+ )
290
+ )
291
+ return [{'run': exports}] if exports else []
289
292
 
290
293
 
291
294
  def validate_params_inputs(inputs: Dict[str, Any]):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: opentf-toolkit-nightly
3
- Version: 0.59.0.dev1182
3
+ Version: 0.59.0.dev1200
4
4
  Summary: OpenTestFactory Orchestrator Toolkit
5
5
  Home-page: https://gitlab.com/henixdevelopment/open-source/opentestfactory/python-toolkit
6
6
  Author: Martin Lafaix
@@ -9,6 +9,7 @@ opentf/commons/selectors.py,sha256=DEpLgRAr5HXSpSYI4liXP2hLUTvOSexFa9Vfa1xIQTk,7
9
9
  opentf/schemas/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
10
  opentf/schemas/abac.opentestfactory.org/v1alpha1/Policy.json,sha256=JXsfNAPSEYggeyaDutSQBeG38o4Bmcr70dPLWWeqIh8,2105
11
11
  opentf/schemas/opentestfactory.org/v1/ExecutionCommand.json,sha256=UtmAlTaYdPSZDeQnx-ocX8IonyEPWoNmgDkHwQwQxWE,4126
12
+ opentf/schemas/opentestfactory.org/v1/ExecutionResult.json,sha256=Etws3d5Ph6dYjQnBqNefLVFnDTYajcKFEbgXFSdD-Ks,3863
12
13
  opentf/schemas/opentestfactory.org/v1/GeneratorResult.json,sha256=sOwieyDWi6UZR7X29R9IjOR87ruSRQ4U6CM2_yT81Zk,16607
13
14
  opentf/schemas/opentestfactory.org/v1/ProviderCommand.json,sha256=EU4kvEKxlqpH2IkLZ1HdBealuG6C0YzPkAtI7dNrfHg,4427
14
15
  opentf/schemas/opentestfactory.org/v1/ProviderResult.json,sha256=Ej4zhCE3rCqCGKcaeAoIHwSJTV_7fw-rAxhJ52qA-Gs,9641
@@ -23,7 +24,7 @@ opentf/schemas/opentestfactory.org/v1alpha1/ChannelHandlerHooks.json,sha256=6K6m
23
24
  opentf/schemas/opentestfactory.org/v1alpha1/EventBusConfig.json,sha256=2aIYtA07qRoauKNy-MH25Kzg1l1Q1fjY9_4YIvlyYgw,2174
24
25
  opentf/schemas/opentestfactory.org/v1alpha1/ExecutionCommand.json,sha256=Tsqy0imNqO6Qg6B_Yw-4OeNer3xpURv-ZDaYUoZ-l1c,2702
25
26
  opentf/schemas/opentestfactory.org/v1alpha1/ExecutionError.json,sha256=tz8ZggvjSkP2S9ln77Js03LkTnMCTuRVkC1Z3w8uI8k,1347
26
- opentf/schemas/opentestfactory.org/v1alpha1/ExecutionResult.json,sha256=aF9PbJADupP_m_TfNRqpeayi1_nCj5Ll2_vDCcJWMkY,3050
27
+ opentf/schemas/opentestfactory.org/v1alpha1/ExecutionResult.json,sha256=kG-oXCVoHb0b72aYK7HR1OEFJrIKfMtWREfffqDFpYU,3875
27
28
  opentf/schemas/opentestfactory.org/v1alpha1/GeneratorCommand.json,sha256=uxbqDhP4newgz-85TnGKbchx448QEQ8WB5PXpcJy2ME,1754
28
29
  opentf/schemas/opentestfactory.org/v1alpha1/GeneratorResult.json,sha256=LkHLGt2uam1Q5Ux0zP_O9oFgxBMCjD3Th3BsfsXxd1g,6633
29
30
  opentf/schemas/opentestfactory.org/v1alpha1/InsightCollector.json,sha256=emE0My2cYBRnfA8L3_eY8yOXbSErV4TlwmQbRCgT4O8,16770
@@ -55,10 +56,10 @@ opentf/schemas/opentestfactory.org/v1beta2/ServiceConfig.json,sha256=rEvK2YWL5lG
55
56
  opentf/scripts/launch_java_service.sh,sha256=S0jAaCuv2sZy0Gf2NGBuPX-eD531rcM-b0fNyhmzSjw,2423
56
57
  opentf/scripts/startup.py,sha256=sggwEpMx7PTaSgYzs-2uCF5YZzpsncMyTlfF_G60CrE,21518
57
58
  opentf/toolkit/__init__.py,sha256=mYeJPZ92ulbTBItqEsZgF4nnuRh6G19QPY3Jxc92ifc,23028
58
- opentf/toolkit/channels.py,sha256=DUP3tBSp7sjq49SwglobG92MO2zX0vdiHGYx0ms30yA,19182
59
- opentf/toolkit/core.py,sha256=6nud1vqcfjs9swZu_Z-rbvdbejtrlSjOd8eZXIF0ChE,9795
60
- opentf_toolkit_nightly-0.59.0.dev1182.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
61
- opentf_toolkit_nightly-0.59.0.dev1182.dist-info/METADATA,sha256=Dd-nF6wo8BrUI89OeoSaZhUJPVW_KRzgzAvkF8ZNctE,1940
62
- opentf_toolkit_nightly-0.59.0.dev1182.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
63
- opentf_toolkit_nightly-0.59.0.dev1182.dist-info/top_level.txt,sha256=_gPuE6GTT6UNXy1DjtmQSfCcZb_qYA2vWmjg7a30AGk,7
64
- opentf_toolkit_nightly-0.59.0.dev1182.dist-info/RECORD,,
59
+ opentf/toolkit/channels.py,sha256=Whbt1nClU2QjKi-3DQE0rHa9yyFkdrLLJ-htyltg6qE,21385
60
+ opentf/toolkit/core.py,sha256=cscUkwdwvLkerqMRL05dgtKJ42QbBQQc28kRBiyZM9o,9883
61
+ opentf_toolkit_nightly-0.59.0.dev1200.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
62
+ opentf_toolkit_nightly-0.59.0.dev1200.dist-info/METADATA,sha256=JZPw_iSlLF4A2gYG4WyWhlHqZU_CmoLf6--KyuvQsII,1940
63
+ opentf_toolkit_nightly-0.59.0.dev1200.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
64
+ opentf_toolkit_nightly-0.59.0.dev1200.dist-info/top_level.txt,sha256=_gPuE6GTT6UNXy1DjtmQSfCcZb_qYA2vWmjg7a30AGk,7
65
+ opentf_toolkit_nightly-0.59.0.dev1200.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.2.0)
2
+ Generator: setuptools (75.3.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5