-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated the github_env to accomodate ubuntu
- Loading branch information
1 parent
42047d9
commit 643d84d
Showing
1 changed file
with
16 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,33 @@ | ||
import os | ||
import platform | ||
|
||
|
||
def set_env_var(key: str, value: str, delimiter: str='~'): | ||
""" | ||
Set the GitHub env variable of 'key' to 'value' using | ||
the method specified here: | ||
https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable | ||
Support both Windows and Ubuntu machines provided by GitHub Actions. | ||
Note: This assumes that we are on a Windows machine. | ||
:param: key, the name of the env variable. | ||
:param: value, the value of the env variable. | ||
:param: delimiter, the delimiter that you want to use | ||
to write to the file. Only applicable if the 'value' contains | ||
'\n' character aka a multiline string. | ||
""" | ||
print('echo "{key}={value}" >> %GITHUB_ENV%') | ||
print(platform.system()) | ||
|
||
if "\n" in value: | ||
os.system(f'echo "{key}<<{delimiter}" >> %GITHUB_ENV%') | ||
os.system(f'echo {value} >> %GITHUB_ENV%') | ||
os.system(f'echo "{delimiter}" >> %GITHUB_ENV%') | ||
if platform.system() == "Windows": | ||
if "\n" in value: | ||
os.system(f'echo "{key}<<{delimiter}" >> %GITHUB_ENV%') | ||
os.system(f'echo {value} >> %GITHUB_ENV%') | ||
os.system(f'echo "{delimiter}" >> %GITHUB_ENV%') | ||
else: | ||
os.system(f'echo "{key}={value}" >> %GITHUB_ENV%') | ||
else: | ||
os.system(f'echo "{key}={value}" >> %GITHUB_ENV%') | ||
if "\n" in value: | ||
os.system(f'echo "{key}<<{delimiter}" >> $GITHUB_ENV') | ||
os.system(f'echo {value} >> $GITHUB_ENV') | ||
os.system(f'echo "{delimiter}" >> $GITHUB_ENV') | ||
else: | ||
os.system(f'echo "{key}={value}" >> $GITHUB_ENV') |