Skip to content

Commit

Permalink
fix: If parent workflow was skipped, dismiss all CI labels
Browse files Browse the repository at this point in the history
  • Loading branch information
FHeilmann committed Dec 31, 2023
1 parent f5e156f commit 54e4c99
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.6
hooks:
- id: ruff
- id: ruff-format
- id: ruff
2 changes: 1 addition & 1 deletion voron_toolkit/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
CI_ERROR_LABEL: str = "Warning: CI Error"
READY_FOR_CI_LABEL: str = "Ready for CI"
PR_COMMENT_TAG: str = "<!-- voron_docker_toolkit -->"
ALL_CI_LABELS: list[str] = [CI_PASSED_LABEL, CI_FAILURE_LABEL, CI_ERROR_LABEL]
ALL_CI_LABELS: list[str] = [CI_PASSED_LABEL, CI_FAILURE_LABEL, CI_ERROR_LABEL, READY_FOR_CI_LABEL]


class ExtendedResult(NamedTuple):
Expand Down
26 changes: 19 additions & 7 deletions voron_toolkit/utils/pr_helper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import contextlib
import os
import sys
import tempfile
Expand All @@ -14,7 +13,6 @@
CI_ERROR_LABEL,
CI_FAILURE_LABEL,
CI_PASSED_LABEL,
READY_FOR_CI_LABEL,
VORONUSERS_PR_COMMENT_SECTIONS,
ExtendedResultEnum,
ItemResult,
Expand Down Expand Up @@ -158,6 +156,9 @@ def _get_pr_number(self: Self) -> int:
sys.exit(255)
return int(Path(self.tmp_path, "pr_number.txt").read_text())

def _check_if_parent_workflow_skipped(self: Self) -> bool:
return bool(Path(self.tmp_path, "ci_skipped.txt").exists())

def run(self: Self) -> None:
logger.info("Downloading artifact '{}' from workflow '{}'", self.artifact_name, self.workflow_run_id)
with tempfile.TemporaryDirectory() as tmpdir:
Expand All @@ -177,8 +178,9 @@ def run(self: Self) -> None:
return

pr_number: int = self._get_pr_number()
parent_workflow_skipped: bool = self._check_if_parent_workflow_skipped()
logger.info("Post Processing PR #{}", pr_number)
if pr_number > 0:
if pr_number > 0 and not parent_workflow_skipped:
labels_to_set: set[str] = self._parse_artifact_and_get_labels()
labels_on_pr: list[str] = GithubActionHelper.get_labels_on_pull_request(
repo=self.github_repository,
Expand All @@ -188,10 +190,6 @@ def run(self: Self) -> None:

updated_labels: list[str] = [*labels_to_set, *labels_to_preserve]

# Make sure to remove the "Ready for CI" label if it is present
with contextlib.suppress(ValueError):
updated_labels.remove(READY_FOR_CI_LABEL)

GithubActionHelper.set_labels_on_pull_request(
repo=self.github_repository,
pull_request_number=pr_number,
Expand All @@ -203,6 +201,20 @@ def run(self: Self) -> None:
pull_request_number=pr_number,
comment_body=pr_comment,
)
else:
logger.info("Workflow {} for PR #{} was skipped. Dismissing all labels!", self.workflow_run_id, pr_number)
GithubActionHelper.set_labels_on_pull_request(
repo=self.github_repository,
pull_request_number=pr_number,
labels=[
label
for label in GithubActionHelper.get_labels_on_pull_request(
repo=self.github_repository,
pull_request_number=pr_number,
)
if label not in ALL_CI_LABELS
],
)


def main() -> None:
Expand Down

0 comments on commit 54e4c99

Please sign in to comment.