Skip to content

Commit

Permalink
All jelle suggestions
Browse files Browse the repository at this point in the history
- Fix bug missing lines ending with --> in CHANGES.md to delete ...
- Update ci to run out of scripts dir too
- Update test_tuple_calver
  • Loading branch information
cooperlees committed Oct 29, 2023
1 parent 728a5f1 commit 8fcfe5e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/release_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ jobs:
run: |
python -m pip install --upgrade pip setuptools wheel
- name: Run Unitests via coverage + print report
- name: Run unit tests via coverage + print report
run: |
python -m pip install coverage
coverage run release_tests.py
coverage report -m
coverage run scripts/release_tests.py
coverage report --show-missing
26 changes: 13 additions & 13 deletions docs/contributing/release_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ The 10,000 foot view of the release process is that you prepare a release PR and
publish a [GitHub Release]. This triggers [release automation](#release-workflows) that
builds all release artifacts and publishes them to the various platforms we publish to.

We now have a `release.py` script to help with cutting the release PRs.
We now have a `scripts/release.py` script to help with cutting the release PRs.

- `python3 release.py --help` is your friend.
- `release.py` has only been tested in Python 3.12 (so get with the times :D)
- `python3 scripts/release.py --help` is your friend.
- `release.py` has only been tested in Python 3.12 (so get with the times :D)

To cut a release:

Expand All @@ -45,17 +45,17 @@ To cut a release:
- Example: the first release in January, 2022 → `22.1.0`
- `release.py` will calculate this and log to stderr for you copy paste pleasure
1. File a PR editing `CHANGES.md` and the docs to version the latest changes
- Run `python3 release.py [--debug]` to generate most changes
- Run `python3 scripts/release.py [--debug]` to generate most changes
- Sub headings in the template, if they have no bullet points need manual removal
_PR welcome to improve :D_
1. If `release.py` fail manually edit; otherwise, yay, skip this step!
1. Replace the `## Unreleased` header with the version number
2. Remove any empty sections for the current release
3. (_optional_) Read through and copy-edit the changelog (eg. by moving entries,
1. Remove any empty sections for the current release
1. (_optional_) Read through and copy-edit the changelog (eg. by moving entries,
fixing typos, or rephrasing entries)
4. Double-check that no changelog entries since the last release were put in the
1. Double-check that no changelog entries since the last release were put in the
wrong section (e.g., run `git diff <last release> CHANGES.md`)
5. Update references to the latest version in
1. Update references to the latest version in
{doc}`/integrations/source_version_control` and
{doc}`/usage_and_configuration/the_basics`
- Example PR: [GH-3139]
Expand All @@ -65,17 +65,17 @@ To cut a release:
1. [Draft a new GitHub Release][new-release]
1. Click `Choose a tag` and type in the version number, then select the
`Create new tag: YY.M.N on publish` option that appears
2. Verify that the new tag targets the `main` branch
3. You can leave the release title blank, GitHub will default to the tag name
4. Copy and paste the _raw changelog Markdown_ for the current release into the
1. Verify that the new tag targets the `main` branch
1. You can leave the release title blank, GitHub will default to the tag name
1. Copy and paste the _raw changelog Markdown_ for the current release into the
description box
1. Publish the GitHub Release, triggering [release automation](#release-workflows) that
will handle the rest
1. Once CI is done add + commit (git push - No review) a new empty template for the next
release to CHANGES.md _(Template is able to be copy pasted from release.py should we
fail)_
1. `python3 release.py --add-changes-template|-a [--debug]`
2. Should that fail, please return to copy + paste
1. `python3 scripts/release.py --add-changes-template|-a [--debug]`
1. Should that fail, please return to copy + paste
1. At this point, you're basically done. It's good practice to go and [watch and verify
that all the release workflows pass][black-actions], although you will receive a
GitHub notification should something fail.
Expand Down
18 changes: 9 additions & 9 deletions release.py → scripts/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,13 @@ def get_git_tags(versions_only: bool = True) -> List[str]:
return git_tags


def int_calver(calver: str) -> int:
"""Convert a calver string into an hex base 16 integer for sorting
- So we can support hexadecimal chars"""
# Return 0 for all alpha + beta releases as we can ignore them
# TODO: Support sorting alhpa/beta releases correctly
def tuple_calver(calver: str) -> tuple[int, ...]: # mypy can't notice maxsplit below
"""Convert a calver string into a tuple of ints for sorting"""
try:
return int(calver.capitalize().replace(".", ""))
return tuple(map(int, calver.split(".", maxsplit=2)))
except ValueError:
return 0
return (0, 0, 0)


class SourceFiles:
Expand Down Expand Up @@ -151,7 +150,7 @@ def cleanup_changes_template_for_release(self) -> None:
# Remove all comments (subheadings are harder - Human required still)
no_comments_changes = []
for line in versioned_changes.splitlines():
if line.startswith("<!--"):
if line.startswith("<!--") or line.endswith("-->"):
continue
no_comments_changes.append(line)

Expand All @@ -162,7 +161,7 @@ def cleanup_changes_template_for_release(self) -> None:

def get_current_version(self) -> str:
"""Get the latest git (version) tag as latest version"""
return sorted(get_git_tags(), key=lambda k: int_calver(k))[-1]
return sorted(get_git_tags(), key=lambda k: tuple_calver(k))[-1]

def get_next_version(self) -> str:
"""Workout the year and month + version number we need to move to"""
Expand Down Expand Up @@ -229,7 +228,8 @@ def parse_args() -> argparse.Namespace:
def main() -> int:
args = parse_args()

sf = SourceFiles(Path(__file__).parent)
# Need parent.parent cause script is in scripts/ directory
sf = SourceFiles(Path(__file__).parent.parent)

if args.add_changes_template:
return sf.add_template_to_changes()
Expand Down
12 changes: 6 additions & 6 deletions release_tests.py → scripts/release_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing import Any
from unittest.mock import Mock, patch

from release import SourceFiles, int_calver
from release import SourceFiles, tuple_calver # type: ignore


class FakeDateTime:
Expand Down Expand Up @@ -57,11 +57,11 @@ def test_get_next_version(self, mocked_git_tags: Mock) -> None:
" month",
)

def test_int_calver(self) -> None:
first_month_release = int_calver("69.1.0")
second_month_release = int_calver("69.1.1")
self.assertEqual(6910, first_month_release)
self.assertEqual(6911, second_month_release)
def test_tuple_calver(self) -> None:
first_month_release = tuple_calver("69.1.0")
second_month_release = tuple_calver("69.1.1")
self.assertEqual((69, 1, 0), first_month_release)
self.assertEqual((0, 0, 0), tuple_calver("69.1.1a0")) # Hack for alphas/betas
self.assertTrue(first_month_release < second_month_release)


Expand Down

0 comments on commit 8fcfe5e

Please sign in to comment.