Skip to content

Commit

Permalink
feat(version-cmd): pass NEW_VERSION & useful env vars to build command
Browse files Browse the repository at this point in the history
  • Loading branch information
codejedi365 committed May 6, 2024
1 parent ef54abf commit ee6b246
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions semantic_release/cli/commands/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
log = logging.getLogger(__name__)

if TYPE_CHECKING: # pragma: no cover
from typing import ContextManager, Iterable
from typing import ContextManager, Iterable, Mapping

from git import Repo
from git.refs.tag import Tag
Expand Down Expand Up @@ -135,7 +135,9 @@ def apply_version_to_source_files(
return paths


def shell(cmd: str, *, check: bool = True) -> subprocess.CompletedProcess:
def shell(
cmd: str, *, env: Mapping[str, str] | None = None, check: bool = True
) -> subprocess.CompletedProcess:
shell: str | None
try:
shell, _ = shellingham.detect_shell()
Expand All @@ -149,6 +151,7 @@ def shell(cmd: str, *, check: bool = True) -> subprocess.CompletedProcess:

return subprocess.run(
[shell, "-c" if shell != "cmd" else "/c", cmd], # noqa: S603
env=(env or {}),
check=check,
)

Expand Down Expand Up @@ -507,7 +510,35 @@ def version( # noqa: C901
"[bold green]:hammer_and_wrench: Running build command: "
+ build_command
)
shell(build_command, check=True)
shell(
build_command,
check=True,
env=dict(
filter(
lambda k_v: k_v[1] is not None, # type: ignore
{
"NEW_VERSION": str(new_version),
"PATH": os.getenv("PATH", ""),
"HOME": os.getenv("HOME", None),
"VIRTUAL_ENV": os.getenv("VIRTUAL_ENV", None),
# affects build decisions
"CI": os.getenv("CI", None),
# Identifies which CI environment
"GITHUB_ACTIONS": os.getenv("GITHUB_ACTIONS", None),
"GITLAB_CI": os.getenv("GITLAB_CI", None),
"GITEA_ACTIONS": os.getenv("GITEA_ACTIONS", None),
"BITBUCKET_CI": (
str(True).lower()
if os.getenv("BITBUCKET_REPO_FULL_NAME", None)
else None
),
"PSR_DOCKER_GITHUB_ACTION": os.getenv(
"PSR_DOCKER_GITHUB_ACTION", None
),
}.items(),
)
),
)
except subprocess.CalledProcessError as exc:
ctx.fail(str(exc))

Expand Down

0 comments on commit ee6b246

Please sign in to comment.