diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index cd90af3..2536e80 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -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 @@ -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: | @@ -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 @@ -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: | diff --git a/release/developmental_release.py b/release/developmental_release.py index 9c34cd2..eb283f6 100644 --- a/release/developmental_release.py +++ b/release/developmental_release.py @@ -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]) @@ -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' @@ -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)