Skip to content

Commit

Permalink
Upgrade to labeler 5.0.0 (#211)
Browse files Browse the repository at this point in the history
This also fix the matching rules, that were broken, probably because the
version before 5.0.0 didn't support the flexible glob matching or it was
misused.

Fixes #194.
  • Loading branch information
llucax authored Jan 31, 2024
2 parents 2796030 + 8996308 commit c293cdd
Show file tree
Hide file tree
Showing 15 changed files with 329 additions and 200 deletions.
134 changes: 80 additions & 54 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,74 +6,100 @@
# For more details on the configuration please see:
# https://github.com/marketplace/actions/labeler

"part:docs":
- any:
- "**/*.md"
- "docs/**"
- "examples/**"
- LICENSE
all:
- "!tests*/**"
"part:doc":
- all:
- changed-files:
- any-glob-to-any-file:
- "**/*.md"
- "docs/**"
- "examples/**"
- LICENSE
- all-globs-to-all-files:
- "!tests*/**"
- "!cookiecutter/{{cookiecutter.github_repo_name}}/**"

"part:tests":
- "**/conftest.py"
- "tests*/**"
- all:
- changed-files:
- any-glob-to-any-file:
- "**/conftest.py"
- "tests*/**"
- all-globs-to-all-files:
- "!.github/**"
- "!cookiecutter/{{cookiecutter.github_repo_name}}/**"

"part:tooling":
- any:
- "**/*.ini"
- "**/*.toml"
- "**/*.yaml"
- "**/*.yml"
- "**/conftest.py"
- ".editorconfig"
- ".git*"
- ".git*/**"
- CODEOWNERS
- MANIFEST.in
- noxfile.py
all:
- "!tests*/**"
- all:
- changed-files:
- any-glob-to-any-file:
- "**/*.ini"
- "**/*.toml"
- "**/*.yaml"
- "**/*.yml"
- "**/conftest.py"
- ".editorconfig"
- ".git*"
- ".git*/**"
- CODEOWNERS
- MANIFEST.in
- noxfile.py
- all-globs-to-all-files:
- "!.github/**"
- "!tests*/**"
- "!cookiecutter/{{cookiecutter.github_repo_name}}/**"

"part:ci":
- any:
- "**/.github/*labeler.*"
- "**/.github/dependabot.*"
- "**/.github/workflows/*"
all:
- "!tests*/**"
- all:
- changed-files:
- any-glob-to-any-file:
- ".github/**"
- all-globs-to-all-files:
- "!**/*.md"

"part:cookiecutter":
- any:
- "cookiecutter/**"
all:
- "!tests/**"
- "!tests_golden/**"
- all:
- changed-files:
- any-glob-to-any-file:
- "cookiecutter*"
- "cookiecutter*/**"
- all-globs-to-all-files:
- "!cookiecutter/{{cookiecutter.github_repo_name}}/**"

"part:template":
- changed-files:
- any-glob-to-any-file:
- "cookiecutter/{{cookiecutter.github_repo_name}}/**"

"part:mkdocs":
- any:
- "**/docs/*.py"
- "**/mkdocs.*"
- "src/frequenz/repo/config/mkdocs*"
all:
- "!tests*/**"
- all:
- changed-files:
- any-glob-to-any-file:
- "**/mkdocs.*"
- "docs/**/*.py"
- "src/frequenz/repo/config/mkdocs*"
- "src/frequenz/repo/config/mkdocs*/**"
- all-globs-to-all-files:
- "!.github/**"
- "!tests*/**"
- "!cookiecutter/{{cookiecutter.github_repo_name}}/**"

"part:nox":
- any:
- "**/noxfile.py"
- changed-files:
- any-glob-to-any-file:
- "noxfile.py"
- "src/frequenz/repo/config/nox*"
- "src/frequenz/repo/config/nox/**"
all:
- "!tests*/**"

"part:pytest":
- changed-files:
- any-glob-to-any-file:
- "src/frequenz/repo/config/pytest*"
- "src/frequenz/repo/config/pytest*/**"

"part:protobuf":
- any:
- changed-files:
- any-glob-to-any-file:
- "src/frequenz/repo/config/setuptools/grpc*"
- "src/frequenz/repo/config/setuptools/grpc*/**"
- "src/frequenz/repo/config/protobuf*"
all:
- "!tests*/**"

"part:pytest":
- any:
- "src/frequenz/repo/config/pytest"
all:
- "!tests*/**"
- "src/frequenz/repo/config/protobuf*/**"
2 changes: 1 addition & 1 deletion .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
# only use hashes to pick the action to execute (instead of tags or branches).
# For more details read:
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
uses: actions/labeler@ac9175f8a1f3625fd0d4fb234536d26811351594 # 4.3.0
uses: actions/labeler@8558fd74291d67161a8a78ce36a881fa63b766a9 # 5.0.0
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
dot: true
31 changes: 31 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,36 @@ To upgrade without regenerating the project, you can follow these steps:

Go to the repository settings -> **Rules** -> **Rulesets** -> **Protect version branches** -> **Bypass list** -> **Add bypass** -> Select **Maintain** role and change the dropdown bypass rule to use **Pull requests** instead of **Always**.

- The `labeler` action was upgraded to 5.0.0. This needs a new configuration file.

If you haven't diverged much from the default configuration (and you are not using exclusion rules), you can update the configuration file by running this script in the root of your repository:
```python
import sys
lines = []
state = "looking"
with open(".github/labeler.yml", encoding="utf-8") as fin:
for line in fin:
if "changed-files:" in line:
sys.stderr.write("Already fixed, aborting...\n")
sys.exit(1)
match state:
case "looking":
if not line.startswith(("#", " ", "\t")) and line.rstrip().endswith(":"):
line = f"{line} - changed-files:\n - any-glob-to-any-file:\n"
state = "in-label"
case "in-label":
if not line.lstrip().startswith("-"):
state = "looking"
else:
line = f" {line}"
lines.append(line)
with open(".github/labeler.yml", "w", encoding="utf-8") as fout:
fout.writelines(lines)
```
This will update the file in place, you can inspect the changes with `git diff`.
## New Features
<!-- Here goes the main new features and examples or instructions on how to use them -->
Expand All @@ -32,6 +62,7 @@ To upgrade without regenerating the project, you can follow these steps:
- Some checks that are already performed by `flake8` are now disabled in `pylint` to avoid double reporting.
- The repository ruleset `Protect version branches` has been updated to allow repository maintainers to skip protection rules in PRs.
- The `labeler` action was upgraded to 5.0.0, which allows for more complex matching rules.
## Bug Fixes
Expand Down
60 changes: 36 additions & 24 deletions cookiecutter/{{cookiecutter.github_repo_name}}/.github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,58 @@
# For example:
#
# "part:module":
# - "src/frequenz/{{cookiecutter.type}}/{{cookiecutter.name | as_identifier}}/module/**"
# - changed-files:
# - any-glob-to-any-file:
# - "src/frequenz/{{cookiecutter.type}}/{{cookiecutter.name | as_identifier}}/module/**"
#
# "part:other":
# - "src/frequenz/{{cookiecutter.type}}/{{cookiecutter.name | as_identifier}}/other/**"
# - changed-files:
# - any-glob-to-any-file:
# - "src/frequenz/{{cookiecutter.type}}/{{cookiecutter.name | as_identifier}}/other/**"
#
# # For excluding some files (in this example, label "part:complicated"
# # everything inside src/ with a .py suffix, except for src/__init__.py)
# "part:complicated":
# - any:
# - "src/**/*.py"
# - all:
# - "!src/__init__.py"
# - changed-files:
# - any-glob-to-any-file:
# - "src/**/*.py"
# - all-glob-to-all-file:
# - "!src/__init__.py"
#
# Please have in mind that that the part:xxx labels need to
# be created in the GitHub repository.

"part:docs":
- "**/*.md"
- "docs/**"
- "examples/**"
- LICENSE
- changed-files:
- any-glob-to-any-file:
- "**/*.md"
- "docs/**"
- "examples/**"
- LICENSE

"part:tests":
- "**/conftest.py"
- changed-files:
- any-glob-to-any-file:
- "**/conftest.py"
{%- if cookiecutter.type == "api" %}
- "pytests/**"
- "pytests/**"
{%- else %}
- "tests/**"
- "tests/**"
{%- endif %}

"part:tooling":
- "**/*.ini"
- "**/*.toml"
- "**/*.yaml"
- "**/*.yml"
- "**/conftest.py"
- ".editorconfig"
- ".git*"
- ".git*/**"
- "docs/*.py"
- CODEOWNERS
- MANIFEST.in
- noxfile.py
- changed-files:
- any-glob-to-any-file:
- "**/*.ini"
- "**/*.toml"
- "**/*.yaml"
- "**/*.yml"
- "**/conftest.py"
- ".editorconfig"
- ".git*"
- ".git*/**"
- "docs/*.py"
- CODEOWNERS
- MANIFEST.in
- noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
# only use hashes to pick the action to execute (instead of tags or branches).
# For more details read:
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
uses: actions/labeler@ac9175f8a1f3625fd0d4fb234536d26811351594 # 4.3.0
uses: actions/labeler@8558fd74291d67161a8a78ce36a881fa63b766a9 # 5.0.0
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
dot: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,54 @@
# For example:
#
# "part:module":
# - "src/frequenz/actor/test/module/**"
# - changed-files:
# - any-glob-to-any-file:
# - "src/frequenz/actor/test/module/**"
#
# "part:other":
# - "src/frequenz/actor/test/other/**"
# - changed-files:
# - any-glob-to-any-file:
# - "src/frequenz/actor/test/other/**"
#
# # For excluding some files (in this example, label "part:complicated"
# # everything inside src/ with a .py suffix, except for src/__init__.py)
# "part:complicated":
# - any:
# - "src/**/*.py"
# - all:
# - "!src/__init__.py"
# - changed-files:
# - any-glob-to-any-file:
# - "src/**/*.py"
# - all-glob-to-all-file:
# - "!src/__init__.py"
#
# Please have in mind that that the part:xxx labels need to
# be created in the GitHub repository.

"part:docs":
- "**/*.md"
- "docs/**"
- "examples/**"
- LICENSE
- changed-files:
- any-glob-to-any-file:
- "**/*.md"
- "docs/**"
- "examples/**"
- LICENSE

"part:tests":
- "**/conftest.py"
- "tests/**"
- changed-files:
- any-glob-to-any-file:
- "**/conftest.py"
- "tests/**"

"part:tooling":
- "**/*.ini"
- "**/*.toml"
- "**/*.yaml"
- "**/*.yml"
- "**/conftest.py"
- ".editorconfig"
- ".git*"
- ".git*/**"
- "docs/*.py"
- CODEOWNERS
- MANIFEST.in
- noxfile.py
- changed-files:
- any-glob-to-any-file:
- "**/*.ini"
- "**/*.toml"
- "**/*.yaml"
- "**/*.yml"
- "**/conftest.py"
- ".editorconfig"
- ".git*"
- ".git*/**"
- "docs/*.py"
- CODEOWNERS
- MANIFEST.in
- noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
# only use hashes to pick the action to execute (instead of tags or branches).
# For more details read:
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
uses: actions/labeler@ac9175f8a1f3625fd0d4fb234536d26811351594 # 4.3.0
uses: actions/labeler@8558fd74291d67161a8a78ce36a881fa63b766a9 # 5.0.0
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
dot: true
Loading

0 comments on commit c293cdd

Please sign in to comment.