mirror of
https://github.com/jupyter/docker-stacks.git
synced 2025-10-17 15:02:57 +00:00
Simplify github workflow commands
This commit is contained in:
11
tagging/github_set_env.py
Normal file
11
tagging/github_set_env.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# Copyright (c) Jupyter Development Team.
|
||||||
|
# Distributed under the terms of the Modified BSD License.
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def github_set_env(env_name, env_value):
|
||||||
|
if not os.environ.get("GITHUB_ACTIONS") or not os.environ.get("GITHUB_ENV"):
|
||||||
|
return
|
||||||
|
|
||||||
|
with open(os.environ["GITHUB_ENV"], "a") as f:
|
||||||
|
f.write(f"{env_name}={env_value}\n")
|
@@ -1,41 +0,0 @@
|
|||||||
"""
|
|
||||||
GitHub Workflow Commands (gwc) for GitHub Actions can help us pass information
|
|
||||||
from a Workflow's Job's various build steps to others via "output" and improve
|
|
||||||
the presented logs when viewed via the GitHub web based UI.
|
|
||||||
|
|
||||||
Reference: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions
|
|
||||||
|
|
||||||
Workflow commands relies on emitting messages:
|
|
||||||
|
|
||||||
print("::{command name} parameter1={data},parameter2={data}::{command value}")
|
|
||||||
|
|
||||||
The functions defined in this file will only emit such messages if found to be
|
|
||||||
in a GitHub CI environment.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
def _gwc(command_name, command_value="", **params):
|
|
||||||
if not os.environ.get("GITHUB_ACTIONS"):
|
|
||||||
return
|
|
||||||
|
|
||||||
# Assume non-string values are meant to be dumped as JSON
|
|
||||||
if not isinstance(command_value, str):
|
|
||||||
command_value = json.dumps(command_value)
|
|
||||||
print(f"dumped json: {command_value}")
|
|
||||||
|
|
||||||
if params:
|
|
||||||
comma_sep_params = ",".join([f"{k}={v}" for k, v in params.items()])
|
|
||||||
print(f"::{command_name} {comma_sep_params}::{command_value}")
|
|
||||||
else:
|
|
||||||
print(f"::{command_name}::{command_value}")
|
|
||||||
|
|
||||||
|
|
||||||
def _gwc_set_env(env_name, env_value):
|
|
||||||
if not os.environ.get("GITHUB_ACTIONS") or not os.environ.get("GITHUB_ENV"):
|
|
||||||
return
|
|
||||||
|
|
||||||
with open(os.environ["GITHUB_ENV"], "a") as f:
|
|
||||||
f.write(f"{env_name}={env_value}\n")
|
|
@@ -6,7 +6,7 @@ import logging
|
|||||||
from plumbum.cmd import docker
|
from plumbum.cmd import docker
|
||||||
from .docker_runner import DockerRunner
|
from .docker_runner import DockerRunner
|
||||||
from .get_taggers_and_manifests import get_taggers_and_manifests
|
from .get_taggers_and_manifests import get_taggers_and_manifests
|
||||||
from .github_workflow_commands import _gwc_set_env
|
from .github_set_env import github_set_env
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -39,7 +39,7 @@ def tag_image(short_image_name: str, owner: str) -> None:
|
|||||||
if tags:
|
if tags:
|
||||||
env_name = f'{short_image_name.replace("-", "_")}_EXTRA_TAG_ARGS'
|
env_name = f'{short_image_name.replace("-", "_")}_EXTRA_TAG_ARGS'
|
||||||
docker_build_tag_args = "-t " + " -t ".join(tags)
|
docker_build_tag_args = "-t " + " -t ".join(tags)
|
||||||
_gwc_set_env(env_name, docker_build_tag_args)
|
github_set_env(env_name, docker_build_tag_args)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Reference in New Issue
Block a user