primitive 0.1.78__py3-none-any.whl → 0.1.80__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.
primitive/__about__.py CHANGED
@@ -1,4 +1,4 @@
1
1
  # SPDX-FileCopyrightText: 2024-present Dylan Stein <dylan@primitive.tech>
2
2
  #
3
3
  # SPDX-License-Identifier: MIT
4
- __version__ = "0.1.78"
4
+ __version__ = "0.1.80"
@@ -138,8 +138,7 @@ class Agent(BaseAction):
138
138
  runner = AgentRunner(
139
139
  primitive=self.primitive,
140
140
  source_dir=source_dir,
141
- job_id=job_run["id"],
142
- job_slug=job_run["job"]["slug"],
141
+ job_run=job_run,
143
142
  max_log_size=500 * 1024,
144
143
  )
145
144
  except Exception as e:
@@ -24,6 +24,7 @@ class Process:
24
24
  self.stdout_thread = None
25
25
  self.stderr_thread = None
26
26
  self._errors = 0
27
+ self._warnings = 0
27
28
 
28
29
  def start(self):
29
30
  # Start the process
@@ -53,6 +54,7 @@ class Process:
53
54
  self._errors += 1
54
55
  elif "warning" in raw_data.lower():
55
56
  logger.warning(raw_data)
57
+ self._warnings += 1
56
58
  else:
57
59
  logger.info(raw_data)
58
60
  elif key.fileobj is self.process.stderr:
@@ -117,3 +119,7 @@ class Process:
117
119
  @property
118
120
  def errors(self) -> int:
119
121
  return self._errors
122
+
123
+ @property
124
+ def warnings(self) -> int:
125
+ return self._warnings
primitive/agent/runner.py CHANGED
@@ -4,6 +4,7 @@ import typing
4
4
  from pathlib import Path, PurePath
5
5
  from time import sleep
6
6
  from typing import Dict, Iterable, List, Optional, TypedDict, Callable
7
+ from enum import IntEnum
7
8
 
8
9
  import yaml
9
10
  from loguru import logger
@@ -39,22 +40,29 @@ class JobDescription(TypedDict):
39
40
  steps: List[JobStep]
40
41
 
41
42
 
43
+ # NOTE This must match FailureLevel subclass in JobSettings model
44
+ class FailureLevel(IntEnum):
45
+ ERROR = 1
46
+ WARNING = 2
47
+
48
+
42
49
  class AgentRunner:
43
50
  def __init__(
44
51
  self,
45
52
  primitive: "primitive.client.Primitive",
46
53
  source_dir: Path,
47
- job_id: str,
48
- job_slug: str,
54
+ job_run: Dict,
49
55
  max_log_size: int = 10 * 1024 * 1024,
50
56
  log_to_file: bool = True,
51
57
  ) -> None:
52
58
  self.primitive = primitive
53
59
  self.source_dir = source_dir
54
60
  self.workdir = "."
55
- self.job_id = job_id
56
- self.job_slug = job_slug
61
+ self.job_id = job_run["id"]
62
+ self.job_slug = job_run["job"]["slug"]
57
63
  self.max_log_size = max_log_size
64
+ self.parse_logs = job_run["jobSettings"]["parseLogs"]
65
+ self.failure_level = job_run["jobSettings"]["failureLevel"]
58
66
  self.log_to_file = log_to_file
59
67
 
60
68
  # Enable and configure logger
@@ -140,7 +148,8 @@ class AgentRunner:
140
148
  logger.error(f"{self.job_slug} concluded with error(s)")
141
149
  return
142
150
 
143
- total_job_errors = 0
151
+ fail_level_detected = False
152
+ total_parsed_levels = {FailureLevel.ERROR: 0, FailureLevel.WARNING: 0}
144
153
  for step in self.steps():
145
154
  logger.info(f"Beginning step {step['name']}")
146
155
 
@@ -183,7 +192,16 @@ class AgentRunner:
183
192
  status_thread.start()
184
193
 
185
194
  returncode = proc.wait()
186
- total_job_errors += proc.errors
195
+
196
+ if proc.errors > 0 and self.failure_level >= FailureLevel.ERROR:
197
+ fail_level_detected = True
198
+
199
+ if proc.warnings > 0 and self.failure_level >= FailureLevel.WARNING:
200
+ fail_level_detected = True
201
+
202
+ total_parsed_levels[FailureLevel.ERROR] += proc.errors
203
+ total_parsed_levels[FailureLevel.WARNING] += proc.warnings
204
+
187
205
  status_thread.join()
188
206
 
189
207
  self.collect_artifacts(step)
@@ -195,11 +213,18 @@ class AgentRunner:
195
213
  logger.error(f"{self.job_slug} concluded with error(s)")
196
214
  return
197
215
 
198
- if total_job_errors > 0:
216
+ if fail_level_detected and self.parse_logs:
199
217
  self.primitive.jobs.job_run_update(
200
218
  self.job_id, status="request_completed", conclusion="failure"
201
219
  )
202
- logger.error(f"{self.job_slug} concluded with error(s)")
220
+
221
+ logger.error(
222
+ (
223
+ f"{self.job_slug} concluded"
224
+ f" with {total_parsed_levels[FailureLevel.ERROR]} error(s)"
225
+ f" and {total_parsed_levels[FailureLevel.WARNING]} warning(s)"
226
+ )
227
+ )
203
228
  return
204
229
 
205
230
  self.primitive.jobs.job_run_update(
@@ -30,6 +30,8 @@ fragment JobRunFragment on JobRun {
30
30
  jobSettings {
31
31
  containerArgs
32
32
  rootDirectory
33
+ parseLogs
34
+ failureLevel
33
35
  }
34
36
  gitCommit {
35
37
  sha
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: primitive
3
- Version: 0.1.78
3
+ Version: 0.1.80
4
4
  Project-URL: Documentation, https://github.com//primitivecorp/primitive-cli#readme
5
5
  Project-URL: Issues, https://github.com//primitivecorp/primitive-cli/issues
6
6
  Project-URL: Source, https://github.com//primitivecorp/primitive-cli
@@ -1,13 +1,13 @@
1
- primitive/__about__.py,sha256=8gbR_hS2TXmTT8fMyHO_YgVOC1s2J-DqRmh7UU5Z5dU,130
1
+ primitive/__about__.py,sha256=MuDJ1utcALDmUQcdbvjxA6n2_Yo25uRsjxiWT-AdSTo,130
2
2
  primitive/__init__.py,sha256=bwKdgggKNVssJFVPfKSxqFMz4IxSr54WWbmiZqTMPNI,106
3
3
  primitive/cli.py,sha256=CiI60bG3UZyNFuLTpchr0KeJRG5SALj455Ob11CegGE,2412
4
4
  primitive/client.py,sha256=PPyIQRvKKSqCF9RRF5mJJ4Vqqolpzy1YXqffNLKIvAA,2390
5
5
  primitive/agent/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- primitive/agent/actions.py,sha256=Hosy2o2FntfBtcNqqHuMFq9dm99EVfySy0v2JGeufvc,6474
6
+ primitive/agent/actions.py,sha256=YUlpi4VCQQTMpoNwDg9meW4liWtdzXCweEm9gD8MXYw,6408
7
7
  primitive/agent/commands.py,sha256=-dVDilELfkGfbZB7qfEPs77Dm1oT62qJj4tsIk4KoxI,254
8
- primitive/agent/process.py,sha256=4dpuO4cZg_SYi0kCoZJrm-ugB_mAnxYWaNbIyUHkoII,3395
8
+ primitive/agent/process.py,sha256=32eoj0W1-LG-9xxeHia-jk9jTah1cnmjCYnvczgXYGU,3538
9
9
  primitive/agent/provision.py,sha256=rmwnro1K5F8mwtd45XAq7RVQmpDWnbBCQ8X_qgWhm3M,1546
10
- primitive/agent/runner.py,sha256=rJq-UE1ONc2uMdymxAes72q9kiSQPESvOOfgpSxXEIg,8199
10
+ primitive/agent/runner.py,sha256=2xGv_Lcr536RjJySC4fX8MxAb4yF8IywHC047VKAfuM,9168
11
11
  primitive/agent/uploader.py,sha256=OkgwXhWKoECOJnW_ZmpzmUS_cpb-orC_uebNcmf5byw,2948
12
12
  primitive/auth/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  primitive/auth/actions.py,sha256=MPsG9LcKcOPwA7gZ9Ewk0PZJhTQvIrGfODdz4GxSzgA,999
@@ -50,7 +50,7 @@ primitive/jobs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
50
50
  primitive/jobs/actions.py,sha256=CtyO-Z9614TgIoXJJX1QGsoll0fgpBIjG9PJH5JwCQs,4901
51
51
  primitive/jobs/commands.py,sha256=MxPCkBEYW_eLNqgCRYeyj7ZcLOFAWfpVZlqDR2Y_S0o,830
52
52
  primitive/jobs/graphql/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
53
- primitive/jobs/graphql/fragments.py,sha256=xtT168P-ChEj3UhSXxFiYPgYuMDyey9bXYkk-TtM3a4,542
53
+ primitive/jobs/graphql/fragments.py,sha256=GZ_rVc_pc3MfC8EhCY_X9rjeNUdiwEytdqrknHYWO-E,573
54
54
  primitive/jobs/graphql/mutations.py,sha256=8ASvCmwQh7cMeeiykOdYaYVryG8FRIuVF6v_J8JJZuw,219
55
55
  primitive/jobs/graphql/queries.py,sha256=BrU_GnLjK0bTAmWsLSmGEUea7EM8MqTKxN1Qp6sSjwc,1597
56
56
  primitive/organizations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -90,8 +90,8 @@ primitive/utils/memory_size.py,sha256=4xfha21kW82nFvOTtDFx9Jk2ZQoEhkfXii-PGNTpIU
90
90
  primitive/utils/printer.py,sha256=f1XUpqi5dkTL3GWvYRUGlSwtj2IxU1q745T4Fxo7Tn4,370
91
91
  primitive/utils/shell.py,sha256=j7E1YwgNWw57dFHVfEbqRNVcPHX0xDefX2vFSNgeI_8,1648
92
92
  primitive/utils/verible.py,sha256=Zb5NUISvcaIgEvgCDBWr-GCoceMa79Tcwvr5Wl9lfnA,2252
93
- primitive-0.1.78.dist-info/METADATA,sha256=Lg0DHnkK_9k1gZyRk-BfxOf_Vu6EfgLkBarZTAyiGww,3642
94
- primitive-0.1.78.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
95
- primitive-0.1.78.dist-info/entry_points.txt,sha256=p1K8DMCWka5FqLlqP1sPek5Uovy9jq8u51gUsP-z334,48
96
- primitive-0.1.78.dist-info/licenses/LICENSE.txt,sha256=B8kmQMJ2sxYygjCLBk770uacaMci4mPSoJJ8WoDBY_c,1098
97
- primitive-0.1.78.dist-info/RECORD,,
93
+ primitive-0.1.80.dist-info/METADATA,sha256=_o8ysAq3wRYyuzFNeawg8t3UodjR21Pc9xZBksVPxWI,3642
94
+ primitive-0.1.80.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
95
+ primitive-0.1.80.dist-info/entry_points.txt,sha256=p1K8DMCWka5FqLlqP1sPek5Uovy9jq8u51gUsP-z334,48
96
+ primitive-0.1.80.dist-info/licenses/LICENSE.txt,sha256=B8kmQMJ2sxYygjCLBk770uacaMci4mPSoJJ8WoDBY_c,1098
97
+ primitive-0.1.80.dist-info/RECORD,,