Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .github/actions/update-viablestrict/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ inputs:
considered stable
required: true
type: string
exclude-checks:
Copy link
Contributor

@huydhn huydhn Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be default to an empty string to safely roll out this change, then we can just use --exclude-checks "${{ inputs.requires }}" and update the script logic to handle empty string

description: |
The list of jobs to exclude from consideration when determining if a
commit is green
required: false
type: string
secret-bot-token:
description: The token to use to push to the stable protected branch
required: true
Expand Down Expand Up @@ -90,10 +96,16 @@ runs:

TEST_INFRA_PATH="${GITHUB_ACTION_PATH}/../../.."

exclude_checks_arg=""
if [ -n "${{ inputs.exclude-checks }}" ]; then
exclude_checks_arg="--exclude-checks \"${{ inputs.exclude-checks }}\""
fi

output=$(python ${TEST_INFRA_PATH}/tools/scripts/fetch_latest_green_commit.py \
--required-checks "${{ inputs.requires }}" \
--viable-strict-branch "viable/strict" \
--main-branch "master")
--main-branch "master" \
$exclude_checks_arg)
echo "latest_viable_sha=$output" >> "${GITHUB_OUTPUT}"
echo $output

Expand Down
36 changes: 32 additions & 4 deletions tools/scripts/fetch_latest_green_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,15 @@ def is_unstable(job: dict[str, Any]) -> bool:


def is_green(
commit: str, requires: List[str], results: List[Dict[str, Any]]
commit: str,
requires: List[str],
results: List[Dict[str, Any]],
excludes: Optional[List[str]] = None,
) -> Tuple[bool, str]:
workflow_checks = get_commit_results(commit, results)

regex = {check: False for check in requires}
excludes = excludes or []

for check in workflow_checks:
jobName = check["name"]
Expand All @@ -124,6 +128,16 @@ def is_green(

workflow_name = check["workflowName"]
conclusion = check["conclusion"]

# Skip excluded checks
excluded = False
for exclude_check in excludes:
if re.match(exclude_check, workflow_name, flags=re.IGNORECASE):
excluded = True
break
if excluded:
continue

for required_check in regex:
if re.match(required_check, workflow_name, flags=re.IGNORECASE):
if conclusion not in ["success", "skipped"]:
Expand All @@ -142,11 +156,14 @@ def is_green(


def get_latest_green_commit(
commits: List[str], requires: List[str], results: List[Dict[str, Any]]
commits: List[str],
requires: List[str],
results: List[Dict[str, Any]],
excludes: Optional[List[str]] = None,
) -> Optional[str]:
for commit in commits:
eprint(f"Checking {commit}")
green, msg = is_green(commit, requires, results)
green, msg = is_green(commit, requires, results, excludes)
if green:
eprint("GREEN")
return commit
Expand All @@ -160,6 +177,7 @@ def parse_args() -> Any:

parser = ArgumentParser("Return the latest green commit from a PyTorch repo")
parser.add_argument("--required-checks", type=str)
parser.add_argument("--exclude-checks", type=str)
parser.add_argument("--viable-strict-branch", type=str, default="viable/strict")
parser.add_argument("--main-branch", type=str, default="main")
return parser.parse_args()
Expand All @@ -174,7 +192,17 @@ def main() -> None:
required_checks = json.loads(args.required_checks)
except json.JSONDecodeError:
required_checks = args.required_checks.split(",")
latest_viable_commit = get_latest_green_commit(commits, required_checks, results)

exclude_checks = None
if args.exclude_checks:
try:
exclude_checks = json.loads(args.exclude_checks)
except json.JSONDecodeError:
exclude_checks = args.exclude_checks.split(",")

latest_viable_commit = get_latest_green_commit(
commits, required_checks, results, exclude_checks
)
print(latest_viable_commit)


Expand Down