Skip to content

Commit 287e0bc

Browse files
authored
CLOUDP-295785 - GitHub Actions workflow that checks for changelogs (#263)
# Summary This pull request introduces workflows to automate the validation and generation of release notes. It includes new script `scripts/release/check_changelog.py` for validating changelog file in PRs, created GitHub Actions workflow that calls validation script and another one to create release notes preview. ### GitHub Actions Workflows * Added `.github/workflows/preview_release_notes.yml` to generate and preview release notes for pull requests and pushes to `master` and `release-*` branches. * Added `.github/workflows/require_changelog.yml` to validate the inclusion of changelog entries in pull requests. The requirement can be skipped by labelling PR with `skip-changelog`. Underneath the workflow uses `scripts/release/check_changelog.py` script. * Introduced `.github/actions/setup-ubuntu-host/action.yml` to set up an Ubuntu runner with Python and necessary dependencies for workflows. * Updated Pull Request template * Updated CONTRIBUTING.md ## Proof of Work ### Changelog requirement validation When changelog exists -> https://github.com/mongodb/mongodb-kubernetes/actions/runs/16319921866/attempts/1#summary-46094783625 ``` Changelog entries found and validated ``` When changelog does not exist -> https://github.com/mongodb/mongodb-kubernetes/actions/runs/16322098714/attempts/1#summary-46102343972 ``` No changelog entries found. Exiting with error due to no changelog entries found. ``` When changelog does not exist and the `skip-changelog` label was added -> https://github.com/mongodb/mongodb-kubernetes/actions/runs/16322136466/attempts/1#summary-46102478174 ``` No changelog entries found. ``` ### Release notes generation Comment with Release Notes preview -> #263 (comment). GHA job summary -> https://github.com/mongodb/mongodb-kubernetes/actions/runs/16322098704/attempts/1#summary-46102343937 ## Checklist - [x] Have you linked a jira ticket and/or is the ticket in the title? - [x] Have you checked whether your jira ticket required DOCSP changes? - [x] Have you checked for release_note changes? ## Reminder (Please remove this when merging) - Please try to Approve or Reject Changes the PR, keep PRs in review as short as possible - Our Short Guide for PRs: [Link](https://docs.google.com/document/d/1T93KUtdvONq43vfTfUt8l92uo4e4SEEvFbIEKOxGr44/edit?tab=t.0) - Remember the following Communication Standards - use comment prefixes for clarity: * **blocking**: Must be addressed before approval. * **follow-up**: Can be addressed in a later PR or ticket. * **q**: Clarifying question. * **nit**: Non-blocking suggestions. * **note**: Side-note, non-actionable. Example: Praise * --> no prefix is considered a question
1 parent 2f21ada commit 287e0bc

File tree

6 files changed

+232
-4
lines changed

6 files changed

+232
-4
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: 'Setup Ubuntu Runner Host'
2+
inputs:
3+
python-version:
4+
description: 'Python version to use'
5+
required: true
6+
runs:
7+
using: "composite"
8+
steps:
9+
- name: setup python
10+
uses: actions/setup-python@v5
11+
with:
12+
python-version: ${{inputs.python-version}}
13+
cache: 'pip' # caching pip dependencies
14+
- name: Install dependencies
15+
shell: bash
16+
run: |
17+
sudo apt-get install libldap2-dev libsasl2-dev # Required for python-ldap
18+
pip install --upgrade pip
19+
pip install -r requirements.txt

.github/pull_request_template.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
<!-- Enter your proof that it works here.-->
88

99
## Checklist
10+
1011
- [ ] Have you linked a jira ticket and/or is the ticket in the title?
1112
- [ ] Have you checked whether your jira ticket required DOCSP changes?
12-
- [ ] Have you checked for release_note changes?
13+
- [ ] Have you added changelog file?
14+
- use `skip-changelog` label if not needed
15+
- refer
16+
to [Changelog files and Release Notes](https://github.com/mongodb/mongodb-kubernetes/blob/master/CONTRIBUTING.md#changelog-files-and-release-notes)
17+
section in CONTRIBUTING.md for more details
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Preview Release Notes
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- release-*
7+
pull_request:
8+
branches:
9+
- master
10+
- release-*
11+
12+
jobs:
13+
preview_release_notes:
14+
name: Preview Release Notes
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
pull-requests: write
19+
steps:
20+
- name: Check out repository
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: '0'
24+
- name: Setup host
25+
uses: ./.github/actions/setup-ubuntu-host
26+
with:
27+
python-version: '${{ vars.PYTHON_VERSION }}'
28+
- name: Generate Release Notes
29+
id: generate_release_notes
30+
run: python -m scripts.release.release_notes -s $INITIAL_COMMIT_SHA -v $INITIAL_VERSION -o release_notes_tmp.md
31+
env:
32+
INITIAL_COMMIT_SHA: ${{ vars.RELEASE_INITIAL_COMMIT_SHA }}
33+
INITIAL_VERSION: ${{ vars.RELEASE_INITIAL_VERSION }}
34+
- name: Add disclaimer to release notes preview
35+
run: |
36+
echo -e "_:warning: (this preview might not be accurate if the PR is not rebased on current master branch)_\n" > release_notes_preview.md
37+
cat release_notes_tmp.md >> release_notes_preview.md
38+
- name: Summarize results
39+
run: cat release_notes_preview.md >> $GITHUB_STEP_SUMMARY
40+
- name: Update PR comment
41+
# If the PR is from a fork, we cannot update the comment using read only permissions
42+
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
43+
run: gh issue comment $ISSUE --edit-last --create-if-none --body-file release_notes_preview.md
44+
env:
45+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
ISSUE: ${{ github.event.pull_request.html_url }}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Validate Changelog Requirement
2+
on:
3+
pull_request:
4+
branches:
5+
- master
6+
- release-*
7+
types:
8+
- opened
9+
- synchronize
10+
- reopened
11+
- labeled
12+
- unlabeled
13+
14+
jobs:
15+
validate-changelog:
16+
name: Check for valid changelog entry
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
steps:
21+
- name: Check out repository
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: '0'
25+
- name: Setup host
26+
uses: ./.github/actions/setup-ubuntu-host
27+
with:
28+
python-version: '${{ vars.PYTHON_VERSION }}'
29+
- name: Check if changelog entry file was added in this PR
30+
run: |
31+
set -o pipefail
32+
python -m scripts.release.check_changelog -b $BASE_SHA -f $FAIL_ON_NO_CHANGES | tee >> $GITHUB_STEP_SUMMARY
33+
env:
34+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
35+
FAIL_ON_NO_CHANGES: ${{ !contains(github.event.pull_request.labels.*.name, 'skip-changelog') }}

CONTRIBUTING.md

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,51 @@
11
# Summary
2+
23
Contributing to the Mongodb Controllers for Kubernetes (MCK) project
3-
Pull requests are always welcome, and the MCK dev team appreciates any help the community can give to help make MongoDB better.
4+
Pull requests are always welcome, and the MCK dev team appreciates any help the community can give to help make MongoDB
5+
better.
6+
7+
## PR Prerequisites
48

5-
# PR Prerequisites
6-
* Please ensure you have signed our Contributor Agreement. You can find it [here](https://www.mongodb.com/legal/contributor-agreement).
9+
* Please ensure you have signed our Contributor Agreement. You can find
10+
it [here](https://www.mongodb.com/legal/contributor-agreement).
711
* Please ensure that all commits are signed.
12+
* Create a changelog file that will describe the changes you made. Use the `skip-changelog` label if your changes do not
13+
require a changelog entry.
14+
15+
## Changelog files and Release Notes
16+
17+
Each Pull Request usually has a changelog file that describes the changes made in the PR using Markdown syntax.
18+
Changelog files are placed in the `changelog/` directory and used to generate the Release Notes for the
19+
upcoming release. Preview of the Release Notes is automatically added as comment to each Pull Request.
20+
The changelog file needs to follow the naming convention
21+
`YYYYMMDD-<change_kind>-<short-description>.md`. To create changelog file please use the
22+
`scripts/release/create_changelog.py` script. Example usage:
23+
24+
```console
25+
python3 -m scripts.release.create_changelog --kind fix "Fix that I want to describe in the changelog"
26+
```
27+
28+
For more options, run the script with `--help`:
29+
30+
```console
31+
python3 -m scripts.release.create_changelog --help
32+
usage: create_changelog.py [-h] [-c ] [-d ] [-e] -k title
33+
34+
Utility to easily create a new changelog entry file.
35+
36+
positional arguments:
37+
title Title for the changelog entry
38+
39+
options:
40+
-h, --help show this help message and exit
41+
-c, --changelog-path
42+
Path to the changelog directory relative to a current working directory. Default is 'changelog/'
43+
-d, --date Date in 'YYYY-MM-DD' format to use for the changelog entry. Default is today's date
44+
-e, --editor Open the created changelog entry in the default editor (if set, otherwise uses 'vi'). Default is True
45+
-k, --kind Kind of the changelog entry:
46+
- 'prelude' for prelude entries
47+
- 'breaking' for breaking change entries
48+
- 'feature' for feature entries
49+
- 'fix' for bugfix entries
50+
- 'other' for other entries
51+
```

scripts/release/check_changelog.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import argparse
2+
import pathlib
3+
4+
from git import Repo
5+
6+
from scripts.release.changelog import DEFAULT_CHANGELOG_PATH, get_changelog_entries
7+
8+
9+
def str2bool(v):
10+
if isinstance(v, bool):
11+
return v
12+
if v.lower() in ("yes", "true", "t", "y", "1"):
13+
return True
14+
elif v.lower() in ("no", "false", "f", "n", "0"):
15+
return False
16+
else:
17+
raise argparse.ArgumentTypeError("Boolean value expected.")
18+
19+
20+
if __name__ == "__main__":
21+
parser = argparse.ArgumentParser(
22+
description="Check if there are changelog entries",
23+
formatter_class=argparse.RawTextHelpFormatter,
24+
)
25+
parser.add_argument(
26+
"-p",
27+
"--path",
28+
default=".",
29+
metavar="",
30+
action="store",
31+
type=pathlib.Path,
32+
help="Path to the Git repository. Default is the current directory '.'",
33+
)
34+
parser.add_argument(
35+
"-c",
36+
"--changelog-path",
37+
default=DEFAULT_CHANGELOG_PATH,
38+
metavar="",
39+
action="store",
40+
type=str,
41+
help=f"Path to the changelog directory relative to the repository root. Default is '{DEFAULT_CHANGELOG_PATH}'",
42+
)
43+
parser.add_argument(
44+
"-b",
45+
"--base-sha",
46+
metavar="",
47+
action="store",
48+
required=True,
49+
type=str,
50+
help="Base commit SHA to compare against. This should be the SHA of the base branch the Pull Request is targeting.",
51+
)
52+
parser.add_argument(
53+
"-f",
54+
"--fail-on-no-changes",
55+
default=True,
56+
metavar="",
57+
action="store",
58+
type=str2bool,
59+
nargs="?",
60+
help="Fail if no changelog entries are found. Default is True.",
61+
)
62+
args = parser.parse_args()
63+
64+
repo = Repo(args.path)
65+
base_commit = repo.commit(args.base_sha)
66+
67+
try:
68+
changelog = get_changelog_entries(base_commit, repo, args.changelog_path)
69+
except Exception as e:
70+
print(f"Error retrieving changelog entries. Possible validation issues: {e}")
71+
exit(1)
72+
73+
if not changelog:
74+
print("No changelog entries found.")
75+
if args.fail_on_no_changes:
76+
print("Exiting with error due to no changelog entries found.")
77+
exit(1)
78+
else:
79+
print("Changelog entries found and validated")

0 commit comments

Comments
 (0)