Skip to content

Commit

Permalink
feat: enforce auto-close milestone workflow (#22)
Browse files Browse the repository at this point in the history
* chore: move expected workflow files to subdir
  • Loading branch information
redeboer authored Jun 2, 2021
1 parent 90758d4 commit 3d10c3d
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 3 deletions.
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,6 @@ repoma =
.github/ISSUE_TEMPLATE/*
.gitpod.yml
py.typed
requirements-cron.yml
requirements-pr.yml
workflows/milestone.yml
workflows/requirements-cron.yml
workflows/requirements-pr.yml
2 changes: 2 additions & 0 deletions src/repoma/pre_commit_hooks/check_dev_files/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from repoma.pre_commit_hooks.errors import PrecommitError

from . import auto_close_milestone
from .check_labels import check_has_labels
from .cspell_config import check_cspell_config
from .editor_config_hook import check_editor_config_hook
Expand Down Expand Up @@ -44,6 +45,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
args = parser.parse_args(argv)
fix = not args.no_fix
try:
auto_close_milestone.check_workflow_file()
check_editor_config_hook()
if not args.allow_labels:
check_has_labels(fix)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# cspell:ignore mhutchie
"""Add a GitHub Action that auto-closes milestones on a new release.
See `github.com/mhutchie/update-milestone-on-release
<https://github.com/mhutchie/update-milestone-on-release>`_.
"""


import os

from repoma.pre_commit_hooks.errors import PrecommitError

__THIS_MODULE_DIR = os.path.abspath(os.path.dirname(__file__))


def check_workflow_file() -> None:
github_workflow_dir = ".github/workflows"
workflow_file = "milestone.yml"
expected_workflow_path = os.path.abspath(
f"{__THIS_MODULE_DIR}/../../workflows/{workflow_file}"
)
with open(expected_workflow_path) as stream:
expected_content = stream.read()
workflow_path = f"{github_workflow_dir}/{workflow_file}"
if not os.path.exists(workflow_path):
write_script(expected_content, path=workflow_path)
raise PrecommitError(f'Created "{workflow_path}" workflow')

with open(workflow_path) as stream:
existing_content = stream.read()
if existing_content != expected_content:
write_script(expected_content, path=workflow_path)
raise PrecommitError(f'Updated "{workflow_path}" workflow')


def write_script(content: str, path: str) -> None:
with open(path, "w") as stream:
stream.write(content)
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def update_github_workflows() -> None:

def upgrade_workflow(workflow_file: str) -> None:
expected_workflow_path = os.path.abspath(
f"{__THIS_MODULE_DIR}/../../{workflow_file}"
f"{__THIS_MODULE_DIR}/../../workflows/{workflow_file}"
)
with open(expected_workflow_path) as stream:
expected_content = stream.read()
Expand Down
14 changes: 14 additions & 0 deletions src/repoma/workflows/milestone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Close Milestone on Release

on:
release:
types: [published]

jobs:
update-milestone:
runs-on: ubuntu-latest
steps:
# cspell:ignore mhutchie
- uses: mhutchie/update-milestone-on-release@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
File renamed without changes.
File renamed without changes.

0 comments on commit 3d10c3d

Please sign in to comment.