Skip to content

Commit

Permalink
Also print existing development release version
Browse files Browse the repository at this point in the history
  • Loading branch information
movermeyer committed Oct 13, 2023
1 parent 3303a26 commit 837bf41
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
- name: Generate the next developmental release version
# If there is a developmental release in Test PyPI for the requested version, increment the number. Else 1. Save in $GITHUB_ENV
run: |
curl https://test.pypi.org/pypi/backports-datetime-fromisoformat/json | python release/developmental_release.py ${{ env.version_from_release_tag }} | sed 's/^/developmental_release_version=/' >> $GITHUB_ENV
curl https://test.pypi.org/pypi/backports-datetime-fromisoformat/json | python release/developmental_release.py ${{ env.version_from_release_tag }} | tail -n 1 | sed 's/^/developmental_release_version=/' >> $GITHUB_ENV
- name: Determine which version to use
run: echo "version_to_use=`if [ '${{ github.event_name }}' == 'workflow_dispatch' ]; then echo '${{ env.developmental_release_version }}'; else echo '${{ env.version_from_release_tag }}'; fi`" >> $GITHUB_ENV
Expand Down Expand Up @@ -261,7 +261,7 @@ jobs:

- name: Get the latest developmental release for this version from Test PyPI
run: |
curl https://test.pypi.org/pypi/backports-datetime-fromisoformat/json | python -c 'import json, sys; from packaging import version; contents = sys.stdin.read(); parsed = json.loads(contents); new_release_number = version.parse("${{ env.version_from_release_tag }}"); existing_releases = [version.parse(x) for x in parsed["releases"].keys()]; developmental_release_version = max([x for x in existing_releases if x.release == new_release_number.release and x.is_devrelease], default=version.parse("0.0.0")); test_pypi_release_exists = new_release_number in existing_releases; print(f"test_pypi_developmental_release_version={developmental_release_version}\ntest_pypi_release_exists={test_pypi_release_exists}"); ' >> $GITHUB_ENV
curl https://test.pypi.org/pypi/backports-datetime-fromisoformat/json | python release/developmental_release.py ${{ env.version_from_release_tag }} | head -n 1 | sed 's/^/test_pypi_developmental_release_version=/' >> $GITHUB_ENV
- name: Get the latest version from PyPI
run: |
Expand All @@ -272,7 +272,6 @@ jobs:
echo 'Ref: `${{ env.event_ref }}`'
echo 'Version to use: `${{ env.version_to_use }}`'
echo 'Developmental release version in Test PyPI `${{ env.test_pypi_developmental_release_version }}`'
echo 'Version exists in Test PyPI? `${{ env.test_pypi_release_exists }}`'
echo 'Version in PyPI `${{ env.pypi_version }}`'
- name: Verify that there exists a developmental release for this version in Test PyPI
Expand All @@ -282,10 +281,6 @@ jobs:
run: |
[[ ${{ env.test_pypi_developmental_release_version }} != 0.0.0 ]]
- name: Verify that the release has been uploaded to Test PyPI
run: |
[[ ${{ env.test_pypi_release_exists }} == True ]]
- name: Verify that the `version_from_release_tag` is present in the CHANGELOG
# TODO: Use something like `changelog-cli` to extract the correct version number
run: |
Expand Down
11 changes: 8 additions & 3 deletions release/developmental_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ def non_developmental_version(version: Version):
post = f".post{version.post}" if version.post else ""
return parse(f"{epoch}{release}{pre}{post}")

def existing_developmental_release_version(new: Version, existing_releases: Iterator[Version]) -> Version:
return max([x for x in existing_releases if x.is_devrelease and non_developmental_version(x) == new], default=None)

def new_developmental_release_version(new: Version, existing_releases: Iterator[Version]) -> Version:
existing = max([x for x in existing_releases if x.is_devrelease and non_developmental_version(x) == new], default=parse("0.0.0"))
dev_number = existing.dev + 1 if existing.is_devrelease and new.release == existing.release else 1
existing = existing_developmental_release_version(new, existing_releases)
dev_number = existing.dev + 1 if existing is not None else 1

epoch = f"{new.epoch}!" if new.epoch else ""
release = ".".join([str(x) for x in new.release])
Expand All @@ -32,7 +34,6 @@ def new_developmental_release_version(new: Version, existing_releases: Iterator[
dev = f".dev{dev_number}"
return parse(f"{epoch}{release}{pre}{post}{dev}")


if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Generates the next developmental release version number based on existing releases'
Expand All @@ -43,5 +44,9 @@ def new_developmental_release_version(new: Version, existing_releases: Iterator[

contents = sys.stdin.read()
existing_releases = _releases(contents)

existing = existing_developmental_release_version(parse(args.new_version), existing_releases) or "0.0.0"
print(existing)

dev_version = new_developmental_release_version(parse(args.new_version), existing_releases)
print(dev_version)

0 comments on commit 837bf41

Please sign in to comment.