diff --git a/.github/workflows/check_release_notes.yml b/.github/workflows/check_release_notes.yml new file mode 100644 index 0000000..7cd5c5e --- /dev/null +++ b/.github/workflows/check_release_notes.yml @@ -0,0 +1,38 @@ +# This workflow will triage pull requests and apply a label based on the +# paths that are modified in the pull request. +# +# To use this workflow, you will need to set up a .github/labeler.yml +# file with configuration. For more information, see: +# https://github.com/actions/labeler + +name: Labeler +on: + pull_request: + types: [labeled, unlabeled, edited, synchronize] + +jobs: + label: + + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + + steps: + - name: Test New Action + uses: danudey/check-release-notes@main + # - name: Checkout + # uses: actions/checkout@v4 + # with: + # sparse-checkout: . + # - name: Setup Python + # uses: actions/setup-python@v5 + # with: + # python-version: '3.12' + # cache: 'pip' # caching pip dependencies + # - name: Install GitHub Python module + # id: gh-py-mod + # run: python3 -m pip install -U -r requirements.txt + # - name: Check Release Notes + # id: release-notes + # run: ./check_release_notes.py diff --git a/check_release_notes.py b/check_release_notes.py new file mode 100755 index 0000000..73afd64 --- /dev/null +++ b/check_release_notes.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 + +import os +import re +import sys +import json + +import github + +def get_env(env_name): + value = os.getenv(env_name) + # print(f"ENV {env_name} = {value}", file=sys.stdout) + return value + +def fail(message): + with open(GITHUB_RESULT_PATH, "a+") as output_file: + output_file.write(message + "\n") + # print(f'FAIL: {message}', file=sys.stderr) + print(f'::error::{message}') + +def info(message): + with open(GITHUB_RESULT_PATH, "a+") as output_file: + output_file.write(message + "\n") + # print(f'INFO: {message}', file=sys.stderr) + print(f'::notice::{message}') + + +GITHUB_EVENT_PATH = get_env("GITHUB_EVENT_PATH") +GITHUB_RESULT_PATH = get_env("GITHUB_STEP_SUMMARY") + +github_data = json.load(open(GITHUB_EVENT_PATH)) + +gh = github.Github() + +repo_name = get_env("GITHUB_REPOSITORY") +pr_number = github_data['number'] + +repo = gh.get_repo(repo_name) +pr = repo.get_pull(pr_number) + +release_note_label = repo.get_label("release-note-required") + +if release_note_label in pr.labels: + if result := re.search("(?<=```release-note\n).*?(?=\n```)", pr.body, re.DOTALL): + release_note = result.group().strip() + if not release_note: + fail('Release note is empty') + sys.exit(-1) + if release_note.lower() == "tbd": + fail('Release note contains "TBD"') + sys.exit(-1) + else: + fail('No release notes found in PR body') + sys.exit(-1) +else: + info('No release note required') + +sys.exit(0) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..b393fb0 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +PyGithub \ No newline at end of file