-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathgithub_writer.py
More file actions
49 lines (40 loc) 路 1.73 KB
/
Copy pathgithub_writer.py
File metadata and controls
49 lines (40 loc) 路 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
class GitHubWriter:
def __init__(self):
self.step_summary_path = os.getenv('GITHUB_STEP_SUMMARY')
self.output_path = os.getenv('GITHUB_OUTPUT')
def write_summary(self, content):
print("> ", content)
if self.step_summary_path:
with open(self.step_summary_path, 'a') as f:
f.write(content)
def write_error(self, content):
# ::error:: makes the message show up as a red annotation on the
# workflow run page, so failures are visible without reading raw logs.
print(f"::error::{content}")
if self.step_summary_path:
with open(self.step_summary_path, 'a') as f:
f.write(f"- 馃毃 {content}\n")
def write_summary_and_fail_on_prod(self, content, env):
print("> ", content)
print(" 鈿狅笍 WARNING: This error will fail for a prod build 鈿狅笍")
if self.step_summary_path:
with open(self.step_summary_path, 'a') as f:
f.write(content)
f.write('鈿狅笍 WARNING: This error will fail for a prod build 鈿狅笍\n')
if env == "PROD":
self.write_output("script-success", "false")
raise RuntimeError(content)
def write_summary_and_fail(self, content, env):
print("> ", content)
if self.step_summary_path:
with open(self.step_summary_path, 'a') as f:
f.write(content)
self.write_output("script-success", "false")
raise RuntimeError(content)
def write_output(self, key, value):
print("GITHUB_OUTPUT:")
print(f"{key}={value}")
if self.output_path:
with open(self.output_path, 'a') as f:
f.write(f"{key}={value}\n")