Skip to content

Commit

Permalink
Hopefully fixed test workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
mephenor committed May 6, 2024
1 parent 2d90729 commit c2d6d65
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/monorepo_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Generate list of changed services
id: services-changed
run: |
echo "affected=$(python3 ./scripts/get_affected_services.py)" >> $GITHUB_OUTPUT
echo "affected=$(python3 ./scripts/get_affected_services.py --full)" >> $GITHUB_OUTPUT
test:
if: ${{needs.check-changes.outputs.services}} != "[]"
Expand Down
26 changes: 18 additions & 8 deletions scripts/get_affected_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,14 @@ def get_top_level_changes(files: list[str]) -> list[str]:
return [file for file in files if not file.startswith("services/")]


def files_in_diff(full: bool, target: str) -> list[str]:
def files_in_diff(full: bool) -> list[str]:
"""List files in diff."""
# Command to list names of changed files
change_range = f"{target}...HEAD" if full else "HEAD HEAD~1"
if full:
base = get_parent_branch()
else:
base = "HEAD~1"
change_range = f"{base}...HEAD"
command = f"git diff --name-only {change_range}"

# Execute the command and capture the output
Expand All @@ -93,16 +97,22 @@ def on_main_branch() -> bool:
return branch_name == "main"


def get_parent_branch() -> str:
"""Get parent branch name"""
command = r'git show-branch | sed "s/].*//" | grep "\*" | grep -v "$(git rev-parse --abbrev-ref HEAD)" | head -n1 | sed "s/^.*\[//"'
output = subprocess.run(
command, shell=True, text=True, capture_output=True, check=True
)
branch_name = output.stdout.strip()
return branch_name


def main(
*,
full: bool = typer.Option(
True,
False,
help="If set, runs for all changes in branch. Otherwise runs for current commit.",
),
target: str = typer.Option(
"main",
help='Which branch to compare against. Defaults to "main". Has no effect if full=False.',
),
):
"""Determine if changes require running CI checks for all or a subset of services.
Expand All @@ -111,7 +121,7 @@ def main(
if on_main_branch():
return

files = files_in_diff(full=full, target=target)
files = files_in_diff(full)

# In practice, changes should affect either one or all services, but that is not
# assumed to always hold true.
Expand Down

0 comments on commit c2d6d65

Please sign in to comment.