-
Notifications
You must be signed in to change notification settings - Fork 3
/
github_writer.py
46 lines (33 loc) · 1.34 KB
/
github_writer.py
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
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_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
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
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")