From 8fcfe5e5fbdf98d12ffbbfb4d088ac6197495b2a Mon Sep 17 00:00:00 2001 From: Cooper Ry Lees Date: Sun, 29 Oct 2023 11:12:38 -0700 Subject: [PATCH] All jelle suggestions - Fix bug missing lines ending with --> in CHANGES.md to delete ... - Update ci to run out of scripts dir too - Update test_tuple_calver --- .github/workflows/release_tests.yml | 6 ++--- docs/contributing/release_process.md | 26 ++++++++++---------- release.py => scripts/release.py | 18 +++++++------- release_tests.py => scripts/release_tests.py | 12 ++++----- 4 files changed, 31 insertions(+), 31 deletions(-) rename release.py => scripts/release.py (92%) rename release_tests.py => scripts/release_tests.py (84%) diff --git a/.github/workflows/release_tests.yml b/.github/workflows/release_tests.yml index a15b57b991e..74729445052 100644 --- a/.github/workflows/release_tests.yml +++ b/.github/workflows/release_tests.yml @@ -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 diff --git a/docs/contributing/release_process.md b/docs/contributing/release_process.md index eb07806c216..c66ffae8ace 100644 --- a/docs/contributing/release_process.md +++ b/docs/contributing/release_process.md @@ -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: @@ -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 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] @@ -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. diff --git a/release.py b/scripts/release.py similarity index 92% rename from release.py rename to scripts/release.py index 89f41b70a63..d588429c2d3 100755 --- a/release.py +++ b/scripts/release.py @@ -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: @@ -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(""): continue no_comments_changes.append(line) @@ -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""" @@ -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() diff --git a/release_tests.py b/scripts/release_tests.py similarity index 84% rename from release_tests.py rename to scripts/release_tests.py index bc143a3d947..bd72cb4b48a 100644 --- a/release_tests.py +++ b/scripts/release_tests.py @@ -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: @@ -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)