Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split check labels to action with label-based triggers #20064

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
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
29 changes: 29 additions & 0 deletions .github/workflows/check_labels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# GENERATED, DO NOT EDIT!
# To change, edit `src/python/pants_release/generate_github_workflows.py` and run:
# ./pants run src/python/pants_release/generate_github_workflows.py


jobs:
check_labels:
if: github.repository_owner == 'pantsbuild'
name: Ensure PR has a category label
runs-on:
- ubuntu-latest
steps:
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
name: Ensure category label
uses: mheap/[email protected]
with:
count: 1
labels: category:new feature, category:user api change, category:plugin api
change, category:performance, category:bugfix, category:documentation, category:internal
mode: exactly
name: PR Validation
'on':
pull_request:
types:
- opened
- reopened
- labeled
- unlabeled
18 changes: 0 additions & 18 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -546,22 +546,6 @@ jobs:
name: logs-wheels-and-pex-macOS11-ARM64
path: .pants.d/workdir/*.log
timeout-minutes: 90
check_labels:
if: github.repository_owner == 'pantsbuild'
name: Ensure PR has a category label
runs-on:
- ubuntu-20.04
steps:
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: github.event_name == 'pull_request'
name: Ensure category label
uses: mheap/[email protected]
with:
count: 1
labels: category:new feature, category:user api change, category:plugin api change, category:performance, category:bugfix,
category:documentation, category:internal
mode: exactly
classify_changes:
if: github.repository_owner == 'pantsbuild'
name: Classify changes
Expand Down Expand Up @@ -657,15 +641,13 @@ jobs:
name: Set Merge OK
needs:
- classify_changes
- check_labels
- bootstrap_pants_linux_arm64
- bootstrap_pants_linux_x86_64
- bootstrap_pants_macos11_x86_64
- build_wheels_linux_arm64
- build_wheels_linux_x86_64
- build_wheels_macos10_15_x86_64
- build_wheels_macos11_arm64
- check_labels
- classify_changes
- lint_python
- test_python_linux_arm64
Expand Down
90 changes: 57 additions & 33 deletions src/python/pants_release/generate_github_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,29 +145,6 @@ def classify_changes() -> Jobs:
}


def ensure_category_label() -> Sequence[Step]:
"""Check that exactly one category label is present on a pull request."""
return [
{
"if": "github.event_name == 'pull_request'",
"name": "Ensure category label",
"uses": "mheap/[email protected]",
"env": {"GITHUB_TOKEN": gha_expr("secrets.GITHUB_TOKEN")},
"with": {
"mode": "exactly",
"count": 1,
"labels": softwrap(
"""
category:new feature, category:user api change,
category:plugin api change, category:performance, category:bugfix,
category:documentation, category:internal
"""
),
},
}
]


def checkout(
*,
fetch_depth: int = 10,
Expand Down Expand Up @@ -950,14 +927,7 @@ def build_wheels_jobs(*, for_deploy_ref: str | None = None, needs: list[str] | N

def test_workflow_jobs() -> Jobs:
linux_x86_64_helper = Helper(Platform.LINUX_X86_64)
jobs: dict[str, Any] = {
"check_labels": {
"name": "Ensure PR has a category label",
"runs-on": linux_x86_64_helper.runs_on(),
"if": IS_PANTS_OWNER,
"steps": ensure_category_label(),
},
}
jobs: dict[str, Any] = {}
jobs.update(**linux_x86_64_test_jobs())
jobs.update(**linux_arm64_test_jobs())
jobs.update(**macos11_x86_64_test_jobs())
Expand Down Expand Up @@ -1556,6 +1526,40 @@ def gen_goals(use_default_version: bool) -> Sequence[object]:
return PublicReposOutput(jobs=jobs, inputs=inputs, run_name=run_name)


@dataclass
class CheckLabelsOutput:
jobs: Jobs


def check_labels() -> CheckLabelsOutput:
steps = [
{
"name": "Ensure category label",
"env": {"GITHUB_TOKEN": gha_expr("secrets.GITHUB_TOKEN")},
"uses": "mheap/[email protected]",
"with": {
"count": 1,
"labels": softwrap(
"""
category:new feature, category:user api change, category:plugin api change,
category:performance, category:bugfix, category:documentation, category:internal
"""
),
"mode": "exactly",
},
}
]

job = {
"name": "Ensure PR has a category label",
"if": IS_PANTS_OWNER,
"runs-on": ["ubuntu-latest"],
"steps": steps,
}

return CheckLabelsOutput({"check_labels": job})


# ----------------------------------------------------------------------
# Main file
# ----------------------------------------------------------------------
Expand Down Expand Up @@ -1593,7 +1597,7 @@ def merge_ok(pr_jobs: list[str]) -> Jobs:
# NB: This always() condition is critical, as it ensures that this job is run even if
# jobs it depends on are skipped.
"if": "always() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled')",
"needs": ["classify_changes", "check_labels"] + sorted(pr_jobs),
"needs": ["classify_changes"] + sorted(pr_jobs),
"outputs": {"merge_ok": f"{gha_expr('steps.set_merge_ok.outputs.merge_ok')}"},
"steps": [
{
Expand Down Expand Up @@ -1635,7 +1639,7 @@ def generate() -> dict[Path, str]:
pr_jobs = test_workflow_jobs()
pr_jobs.update(**classify_changes())
for key, val in pr_jobs.items():
if key in {"check_labels", "classify_changes"}:
if key in {"classify_changes"}:
continue
needs = val.get("needs", [])
if isinstance(needs, str):
Expand Down Expand Up @@ -1726,12 +1730,32 @@ def generate() -> dict[Path, str]:
Dumper=NoAliasDumper,
)

check_labels_output = check_labels()
check_labels_yaml = yaml.dump(
{
"name": "PR Validation",
"on": {
"pull_request": {
"types": [
"opened",
"reopened",
"labeled",
"unlabeled",
]
}
},
"jobs": check_labels_output.jobs,
},
Dumper=NoAliasDumper,
)

return {
Path(".github/workflows/audit.yaml"): f"{HEADER}\n\n{audit_yaml}",
Path(".github/workflows/cache_comparison.yaml"): f"{HEADER}\n\n{cache_comparison_yaml}",
Path(".github/workflows/test.yaml"): f"{HEADER}\n\n{test_yaml}",
Path(".github/workflows/release.yaml"): f"{HEADER}\n\n{release_yaml}",
Path(".github/workflows/public_repos.yaml"): f"{HEADER}\n\n{public_repos_yaml}",
Path(".github/workflows/check_labels.yaml"): f"{HEADER}\n\n{check_labels_yaml}",
}


Expand Down
Loading