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
|
import os, inspect
from ci_tools.variables import in_ci
def output_ci_warning(message: str, location=None) -> None:
ci_type = in_ci()
if ci_type == 1:
if not location:
import inspect
source = inspect.stack()[1].filename
else:
source = location
print(f"##vso[task.logissue type=warning;sourcepath={source}]{message}")
elif ci_type == 2:
pass
else:
print("Unrecognized CI format, not outputting warning.")
def set_ci_variable(name: str, value: str) -> None:
"""
Sets a runtime variable in azure devops or github actions. The variable will only be available
AFTER the step which invokes this function is completed.
"""
ci_type = in_ci()
if ci_type == 1:
print(f"##vso[task.setvariable variable={name}]{value}")
elif ci_type == 2:
env_file = os.getenv("GITHUB_ENV")
with open(env_file, "a") as env_file:
env_file.write(f"{name}={value}")
else:
print(f'Unrecognized CI format, not setting variable "{name}."')
|