Skip to content

Commit c994e90

Browse files
authored
Add build and check docs tasks, fix gh release issue, add release checklist
* fixes #133, fixes #134 * add build and check docs tasks * clean up tests
1 parent a002516 commit c994e90

File tree

8 files changed

+239
-20
lines changed

8 files changed

+239
-20
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,19 @@ jobs:
4343
poetry-version: "1.8.5"
4444
- name: "Linting: ruff"
4545
run: "poetry run invoke ruff --action lint"
46-
# Temporarily disabled due to issues with the docs build and needing best practices for NTC python builds.
47-
# check-docs-build:
48-
# runs-on: "ubuntu-24.04"
49-
# env:
50-
# INVOKE_JDIFF_LOCAL: "True"
51-
# steps:
52-
# - name: "Check out repository code"
53-
# uses: "actions/checkout@v4"
54-
# - name: "Setup environment"
55-
# uses: "networktocode/gh-action-setup-poetry-environment@v6"
56-
# with:
57-
# poetry-version: "1.8.5"
58-
# - name: "Check Docs Build"
59-
# run: "poetry run invoke build-and-check-docs"
46+
check-docs-build:
47+
runs-on: "ubuntu-22.04"
48+
env:
49+
INVOKE_JDIFF_LOCAL: "True"
50+
steps:
51+
- name: "Check out repository code"
52+
uses: "actions/checkout@v4"
53+
- name: "Setup environment"
54+
uses: "networktocode/gh-action-setup-poetry-environment@v6"
55+
with:
56+
poetry-version: "1.8.5"
57+
- name: "Check Docs Build"
58+
run: "poetry run invoke build-and-check-docs"
6059
poetry:
6160
runs-on: "ubuntu-24.04"
6261
env:
@@ -190,12 +189,12 @@ jobs:
190189
steps:
191190
- name: "Check out repository code"
192191
uses: "actions/checkout@v4"
193-
- name: "Set up Python"
194-
uses: "actions/setup-python@v5"
192+
- name: "Setup environment"
193+
uses: "networktocode/gh-action-setup-poetry-environment@v6"
195194
with:
196-
python-version: "3.9"
197-
- name: "Install Python Packages"
198-
run: "pip install poetry"
195+
poetry-version: "1.8.5"
196+
python-version: "3.12"
197+
poetry-install-options: "--no-root"
199198
- name: "Set env"
200199
run: "echo RELEASE_VERSION=${GITHUB_REF:10} >> $GITHUB_ENV"
201200
- name: "Run Poetry Version"

changes/.gitkeep

Whitespace-only changes.

changes/133.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix GitHub release failing in CI pipeline.

changes/134.added

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added documentation on the release checklist and process for the library.

docs/dev/dev_environment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ To either stop or destroy the development environment use the following options.
4545

4646
## Poetry
4747

48-
Poetry is used in lieu of the "virtualenv" commands and is leveraged in both environments. The virtual environment will provide all of the Python packages required to manage the development environment such as **Invoke**. See the [Local Development Environment](#local-poetry-development-environment) section to see how to install Jdiff if you're going to be developing locally (i.e. not using the Docker container).
48+
Poetry is used in lieu of the "virtualenv" commands and is leveraged in both environments. The virtual environment will provide all of the Python packages required to manage the development environment such as **Invoke**. See the [Local Development Environment](#docker-development-environment) section to see how to install Jdiff if you're going to be developing locally (i.e. not using the Docker container).
4949

5050
The `pyproject.toml` file outlines all of the relevant dependencies for the project:
5151

docs/dev/release_checklist.md

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
# Release Checklist
2+
3+
This document is intended for library maintainers and outlines the steps to perform when releasing a new version of the library.
4+
5+
!!! important
6+
Before starting, make sure your **local** `develop`, `main` are all up to date with upstream!
7+
8+
```
9+
git fetch
10+
git switch develop && git pull
11+
```
12+
13+
Choose your own adventure:
14+
15+
- Patch release from `develop`? Jump [here](#all-releases-from-develop).
16+
- Minor release? Continue with [Minor Version Bumps](#minor-version-bumps) and then [All Releases from `develop`](#all-releases-from-develop).
17+
18+
## Minor Version Bumps
19+
20+
### Update Requirements
21+
22+
Every minor version release should refresh `poetry.lock`, so that it lists the most recent stable release of each package. To do this:
23+
24+
0. Run `poetry update --dry-run` to have Poetry automatically tell you what package updates are available and the versions it would upgrade to. This requires an existing environment created from the lock file (i.e. via `poetry install`).
25+
1. Review each requirement's release notes for any breaking or otherwise noteworthy changes.
26+
2. Run `poetry update <package>` to update the package versions in `poetry.lock` as appropriate.
27+
3. If a required package requires updating to a new release not covered in the version constraints for a package as defined in `pyproject.toml`, (e.g. `Django ~3.1.7` would never install `Django >=4.0.0`), update it manually in `pyproject.toml`.
28+
4. Run `poetry install` to install the refreshed versions of all required packages.
29+
5. Run all tests (`poetry run invoke tests`) and check that the UI and API function as expected.
30+
31+
### Update Documentation
32+
33+
If there are any changes to the compatibility matrix (such as a bump in the minimum supported Nautobot version), update it accordingly.
34+
35+
Commit any resulting changes from the following sections to the documentation before proceeding with the release.
36+
37+
!!! tip
38+
Fire up the documentation server in your development environment with `poetry run mkdocs serve`! This allows you to view the documentation site locally (the link is in the output of the command) and automatically rebuilds it as you make changes.
39+
40+
### Verify the Installation and Upgrade Steps
41+
42+
Follow the [installation instructions](../admin/install.md) to perform a new production installation of the library. If possible, also test the [upgrade process](../admin/upgrade.md) from the previous released version.
43+
44+
The goal of this step is to walk through the entire install process *as documented* to make sure nothing there needs to be changed or updated, to catch any errors or omissions in the documentation, and to ensure that it is current with each release.
45+
46+
---
47+
48+
## All Releases from `develop`
49+
50+
### Verify CI Build Status
51+
52+
Ensure that continuous integration testing on the `develop` branch is completing successfully.
53+
54+
### Bump the Version
55+
56+
Update the package version using `poetry version` if necessary. This command shows the current version of the project or bumps the version of the project and writes the new version back to `pyproject.toml` if a valid bump rule is provided.
57+
58+
The new version must be a valid semver string or a valid bump rule: `patch`, `minor`, `major`, `prepatch`, `preminor`, `premajor`, `prerelease`. Always try to use a bump rule when you can.
59+
60+
Display the current version with no arguments:
61+
62+
```no-highlight
63+
> poetry version
64+
jdiff 1.0.0-beta.2
65+
```
66+
67+
Bump pre-release versions using `prerelease`:
68+
69+
```no-highlight
70+
> poetry version prerelease
71+
Bumping version from 1.0.0-beta.2 to 1.0.0-beta.3
72+
```
73+
74+
For major versions, use `major`:
75+
76+
```no-highlight
77+
> poetry version major
78+
Bumping version from 1.0.0-beta.2 to 1.0.0
79+
```
80+
81+
For patch versions, use `minor`:
82+
83+
```no-highlight
84+
> poetry version minor
85+
Bumping version from 1.0.0 to 1.1.0
86+
```
87+
88+
And lastly, for patch versions, you guessed it, use `patch`:
89+
90+
```no-highlight
91+
> poetry version patch
92+
Bumping version from 1.1.0 to 1.1.1
93+
```
94+
95+
Please see the [official Poetry documentation on `version`](https://python-poetry.org/docs/cli/#version) for more information.
96+
97+
### Update the Changelog
98+
99+
!!! important
100+
The changelog must adhere to the [Keep a Changelog](https://keepachangelog.com/) style guide.
101+
102+
This guide uses `1.4.2` as the new version in its examples, so change it to match the version you bumped to in the previous step! Every. single. time. you. copy/paste commands :)
103+
104+
First, create a release branch off of `develop` (`git switch -c release-1.4.2 develop`).
105+
106+
> You will need to have the project's poetry environment built at this stage, as the towncrier command runs **locally only**. If you don't have it, run `poetry install` first.
107+
108+
Generate release notes with `invoke generate-release-notes --version 1.4.2` and answer `yes` to the prompt `Is it okay if I remove those files? [Y/n]:`. This will update the release notes in `docs/admin/release_notes/version_X.Y.md`, stage that file in git, and `git rm` all the fragments that have now been incorporated into the release notes.
109+
110+
There are two possibilities:
111+
112+
1. If you're releasing a new major or minor version, rename the `version_X.Y.md` file accordingly (e.g. rename to `docs/admin/release_notes/version_1.4.md`). Update the `Release Overview` and add this new page to the table of contents within `mkdocs.yml`.
113+
2. If you're releasing a patch version, copy your version's section from the `version_X.Y.md` file into the already existing `docs/admin/release_notes/version_1.4.md` file. Delete the `version_X.Y.md` file.
114+
115+
Stage all the changes (`git add`) and check the diffs to verify all of the changes are correct (`git diff --cached`).
116+
117+
Commit `git commit -m "Release v1.4.2"` and `git push` the staged changes.
118+
119+
### Submit Release Pull Request
120+
121+
Submit a pull request titled `Release v1.4.2` to merge your release branch into `main`. Copy the documented release notes into the pull request's body.
122+
123+
!!! important
124+
Do not squash merge this branch into `main`. Make sure to select `Create a merge commit` when merging in GitHub.
125+
126+
Once CI has completed on the PR, merge it.
127+
128+
### Create a New Release in GitHub
129+
130+
Draft a [new release](https://github.com/networktocode/jdiff/releases/new) with the following parameters.
131+
132+
* **Tag:** Input current version (e.g. `v1.4.2`) and select `Create new tag: v1.4.2 on publish`
133+
* **Target:** `main`
134+
* **Title:** Version and date (e.g. `v1.4.2 - 2024-04-02`)
135+
136+
Click "Generate Release Notes" and edit the auto-generated content as follows:
137+
138+
- Change the entries generated by GitHub to only the usernames of the contributors. e.g. `* Updated dockerfile by @ntc_user in https://github.com/networktocode/jdiff/pull/123` -> `* @ntc_user`.
139+
- This should give you the list for the new `Contributors` section.
140+
- Make sure there are no duplicated entries.
141+
- Replace the content of the `What's Changed` section with the description of changes from the release PR (what towncrier generated).
142+
- If it exists, leave the `New Contributors` list as it is.
143+
144+
The release notes should look as follows:
145+
146+
```markdown
147+
## What's Changed
148+
149+
**Towncrier generated Changed/Fixed/Housekeeping etc. sections here**
150+
151+
## Contributors
152+
153+
* @alice
154+
* @bob
155+
156+
## New Contributors
157+
158+
* @bob
159+
160+
**Full Changelog**: https://github.com/networktocode/jdiff/compare/v1.4.1...v1.4.2
161+
```
162+
163+
Publish the release!
164+
165+
### Create a PR from `main` back to `develop`
166+
167+
First, sync your `main` branch with upstream changes: `git switch main && git pull`.
168+
169+
Create a new branch from `main` called `release-1.4.2-to-develop` and use `poetry version prepatch` to bump the development version to the next release.
170+
171+
For example, if you just released `v1.4.2`:
172+
173+
```no-highlight
174+
> git switch -c release-1.4.2-to-develop main
175+
Switched to a new branch 'release-1.4.2-to-develop'
176+
177+
> poetry version prepatch
178+
Bumping version from 1.4.2 to 1.4.3a1
179+
180+
> git add pyproject.toml && git commit -m "Bump version"
181+
182+
> git push
183+
```
184+
185+
!!! important
186+
Do not squash merge this branch into `develop`. Make sure to select `Create a merge commit` when merging in GitHub.
187+
188+
Open a new PR from `release-1.4.2-to-develop` against `develop`, wait for CI to pass, and merge it.
189+
190+
### Final checks
191+
192+
At this stage, the CI should be running or finished for the `v1.4.2` tag and a package successfully published to PyPI and added into the GitHub Release. Double check that's the case.
193+
194+
Documentation should also have been built for the tag on ReadTheDocs and if you're reading this page online, refresh it and look for the new version in the little version fly-out menu down at the bottom right of the page.
195+
196+
All done!

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ nav:
138138
- Extending the Library: "dev/extending.md"
139139
- Contributing to the Library: "dev/contributing.md"
140140
- Development Environment: "dev/dev_environment.md"
141+
- Release Checklist: "dev/release_checklist.md"
141142
- Architecture Decisions: "dev/arch_decision.md"
142143
- Code Reference:
143144
- Jdiff: "code-reference/jdiff/__init__.md"

tasks.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"""Tasks for use with Invoke."""
22

3+
import re
4+
from pathlib import Path
5+
36
from invoke import Collection, Exit
47
from invoke import task as invoke_task
58

@@ -230,6 +233,24 @@ def tests(context):
230233
print("All tests have passed!")
231234

232235

236+
@task
237+
def build_and_check_docs(context):
238+
"""Build documentation to be available within Nautobot."""
239+
command = "mkdocs build --no-directory-urls --strict"
240+
run_command(context, command)
241+
242+
# Check for the existence of a release notes file for the current version if it's not a prerelease.
243+
version = context.run("poetry version --short", hide=True)
244+
match = re.match(r"^(\d+)\.(\d+)\.\d+$", version.stdout.strip())
245+
if match:
246+
major = match.group(1)
247+
minor = match.group(2)
248+
release_notes_file = Path(__file__).parent / "docs" / "admin" / "release_notes" / f"version_{major}.{minor}.md"
249+
if not release_notes_file.exists():
250+
print(f"Release notes file `version_{major}.{minor}.md` does not exist.")
251+
raise Exit(code=1)
252+
253+
233254
@task
234255
def docs(context):
235256
"""Build and serve docs locally for development."""

0 commit comments

Comments
 (0)