@@ -3,7 +3,6 @@ description: Perform pre-release operations for Python Libraries
33inputs :
44 version :
55 description : The published version
6- required : true
76 version_bump_script :
87 description : The version bump script
98 default : hatch version
@@ -34,28 +33,46 @@ runs:
3433 - name : Install hatch
3534 shell : bash
3635 working-directory : ${{ inputs.working_directory }}
37- run : pipx install hatch
38- - name : Check if we should push changes
36+ run : |
37+ pipx install hatch
38+ pip install build
39+ - name : Handle inputs
3940 shell : bash
41+ env :
42+ VERSION : " ${{ inputs.version }}"
43+ DRY_RUN : " ${{ inputs.dry_run }}"
4044 run : |
45+ set -eux
4146 # Handle DRY_RUN
42- if [ "${{ inputs.dry_run }} " != "true" ]; then
47+ if [ "$DRY_RUN " != "true" ]; then
4348 export PUSH_CHANGES=true
4449 else
4550 export PUSH_CHANGES=false
4651 fi
4752 echo "PUSH_CHANGES=$PUSH_CHANGES" >> $GITHUB_ENV
53+ # Handle version already bumped
54+ if [ -z "$VERSION" ]; then
55+ # Extract the version from the sdist name, which must be of the form
56+ # {name}-{version}.tar.gz according to PEP 625.
57+ python -m build --sdist .
58+ VERSION=$(ls dist/*.tar.gz | rev | cut -d'-' -f 1 | rev | sed 's/.tar.gz//g')
59+ echo "VERSION=$VERSION" >> $GITHUB_ENV
60+ rm -rf dist
61+ else
62+ echo "VERSION=$VERSION" >> $GITHUB_ENV
63+ fi
4864 - name : Set version
4965 uses : mongodb-labs/drivers-github-tools/bump-version@v2
66+ if : ${{ inputs.version }}
5067 with :
51- version : ${{ inputs.version }}
68+ version : ${{ env.VERSION }}
5269 version_bump_script : ${{ inputs.version_bump_script }}
5370 working_directory : ${{ inputs.working_directory }}
5471 push_commit : ${{ env.PUSH_CHANGES }}
5572 - name : Tag version
5673 uses : mongodb-labs/drivers-github-tools/tag-version@v2
5774 with :
58- version : ${{ inputs.version }}
75+ version : ${{ env.VERSION }}
5976 tag_template : ${{ inputs.tag_template }}
6077 tag_message_template : ${{ inputs.tag_message_template }}
6178 push_tag : ${{ env.PUSH_CHANGES }}
6683 if [ "${{ inputs.dry_run}}" == 'true' ]; then
6784 echo "version=${{ github.ref }}" >> $GITHUB_OUTPUT
6885 else
69- export VERSION=${{ inputs.version }}
86+ export VERSION=${{ env.VERSION }}
7087 export TAG=$(echo "${{ inputs.tag_template }}" | envsubst)
7188 echo "version=$TAG" >> $GITHUB_OUTPUT
7289 fi
0 commit comments