GRM-51: refactor: convert shell scripts and inline workflow scripts to Python
This commit is contained in:
@@ -172,6 +172,17 @@ def get_latest_tag() -> str:
|
||||
return result.stdout.strip()
|
||||
|
||||
|
||||
def _write_github_output(key: str, value: str) -> None:
|
||||
"""Append a key=value line to the $GITHUB_OUTPUT file."""
|
||||
import os
|
||||
|
||||
gh_output = os.environ.get("GITHUB_OUTPUT")
|
||||
if not gh_output:
|
||||
raise click.ClickException("GITHUB_OUTPUT environment variable is not set")
|
||||
with open(gh_output, "a") as f: # noqa: PTH123
|
||||
f.write(f"{key}={value}\n")
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.option("--base", default=None, help="Base ref (default: latest tag).")
|
||||
@click.option("--head", default="HEAD", help="Head ref (default: HEAD).")
|
||||
@@ -182,10 +193,22 @@ def get_latest_tag() -> str:
|
||||
default="all",
|
||||
help="Check specific category: all (default), ansible, or user-facing.",
|
||||
)
|
||||
def main(base: str | None, head: str, quiet: bool, check: str) -> None:
|
||||
@click.option(
|
||||
"--github-output",
|
||||
"github_output",
|
||||
is_flag=True,
|
||||
default=False,
|
||||
help="Write results to $GITHUB_OUTPUT file (for CI workflow steps).",
|
||||
)
|
||||
def main(base: str | None, head: str, quiet: bool, check: str, github_output: bool) -> None:
|
||||
if base is None:
|
||||
base = get_latest_tag()
|
||||
if not base:
|
||||
if github_output:
|
||||
_write_github_output("ansible-changed", "true")
|
||||
_write_github_output("user-facing-changed", "true")
|
||||
click.echo("No tags found — treating all changes as user-facing.")
|
||||
return
|
||||
if quiet:
|
||||
click.echo("true")
|
||||
else:
|
||||
@@ -194,12 +217,26 @@ def main(base: str | None, head: str, quiet: bool, check: str) -> None:
|
||||
|
||||
files = get_changed_files(base, head)
|
||||
if not files:
|
||||
if github_output:
|
||||
_write_github_output("ansible-changed", "false")
|
||||
_write_github_output("user-facing-changed", "false")
|
||||
click.echo(f"No changes between {base} and {head}.")
|
||||
return
|
||||
if quiet:
|
||||
click.echo("false")
|
||||
else:
|
||||
click.echo(_("No changes between {base} and {head}.", base=base, head=head))
|
||||
return
|
||||
|
||||
if github_output:
|
||||
ansible_files = [f for f in files if f.startswith("ansible/") or f == ".ansible-lint"]
|
||||
user_files = [f for f in files if is_user_facing(f)]
|
||||
_write_github_output("ansible-changed", "true" if ansible_files else "false")
|
||||
_write_github_output("user-facing-changed", "true" if user_files else "false")
|
||||
click.echo(f"Ansible files changed: {bool(ansible_files)}")
|
||||
click.echo(f"User-facing files changed: {bool(user_files)}")
|
||||
return
|
||||
|
||||
if check == "ansible":
|
||||
# Check only for Ansible-related file changes
|
||||
ansible_files = [f for f in files if f.startswith("ansible/") or f == ".ansible-lint"]
|
||||
|
||||
Reference in New Issue
Block a user