Skip to content

Commit

Permalink
include in generate_github_workflows.py
Browse files Browse the repository at this point in the history
  • Loading branch information
tgolsson committed Nov 2, 2023
1 parent 9840c2b commit d343c84
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 12 deletions.
28 changes: 16 additions & 12 deletions .github/workflows/check_labels.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
name: PR Validation
on:
pull_request:
types:
- opened
- reopened
- labeled
- unlabeled
# 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-20.04
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
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
57 changes: 57 additions & 0 deletions src/python/pants_release/generate_github_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import yaml
from pants_release.common import die

from pants.util.strutil import softwrap

HEADER = dedent(
"""\
# GENERATED, DO NOT EDIT!
Expand Down Expand Up @@ -1524,6 +1526,41 @@ 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 @@ -1694,12 +1731,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

0 comments on commit d343c84

Please sign in to comment.