Skip to content

Commit 9ad9393

Browse files
authored
PYTHON-5188 Make version optional for Python releases (#76)
1 parent 2855668 commit 9ad9393

File tree

3 files changed

+43
-13
lines changed

3 files changed

+43
-13
lines changed

python/post-publish/action.yml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ description: Perform post-release operations for Python Libraries
44
inputs:
55
version:
66
description: The published version
7-
required: true
87
following_version:
98
description: The following (dev) version
109
required: false
@@ -56,6 +55,20 @@ runs:
5655
with:
5756
name: all-dist-${{ github.run_id }}
5857
path: dist/
58+
- name: Ensure we have the package version
59+
shell: bash
60+
env:
61+
VERSION: "${{ inputs.version }}"
62+
run: |
63+
# Handle version already bumped
64+
if [ -z "$VERSION" ]; then
65+
# Extract the version from the sdist name, which must be of the form
66+
# {name}-{version}.tar.gz according to PEP 625.
67+
VERSION=$(ls dist/*.tar.gz | rev | cut -d'-' -f 1 | rev | sed 's/.tar.gz//g')
68+
echo "VERSION=$VERSION" >> $GITHUB_ENV
69+
else
70+
echo "VERSION=$VERSION" >> $GITHUB_ENV
71+
fi
5972
- name: Create detached signature for dist files
6073
uses: mongodb-labs/drivers-github-tools/gpg-sign@v2
6174
with:
@@ -68,8 +81,8 @@ runs:
6881
- uses: mongodb-labs/drivers-github-tools/full-report@v2
6982
with:
7083
product_name: ${{ inputs.product_name }}
71-
release_version: ${{ inputs.version }}
72-
sarif_report_target_ref: ${{ inputs.version }}
84+
release_version: ${{ env.VERSION }}
85+
sarif_report_target_ref: ${{ env.VERSION }}
7386
dist_filenames: dist/*
7487
kondukto_sub_project: ${{ inputs.kondukto_sub_project }}
7588
sbom_in_path: ${{ inputs.sbom_in_path }}
@@ -79,7 +92,7 @@ runs:
7992
token: ${{ inputs.token }}
8093
- uses: mongodb-labs/drivers-github-tools/upload-s3-assets@v2
8194
with:
82-
version: ${{ inputs.version }}
95+
version: ${{ env.VERSION }}
8396
product_name: ${{ inputs.product_name }}
8497
dry_run: ${{ inputs.dry_run }}
8598
- name: Run GitHub Publish script
@@ -88,7 +101,7 @@ runs:
88101
run: ${{ github.action_path }}/post-publish.sh
89102
env:
90103
GH_TOKEN: ${{ inputs.token }}
91-
VERSION: ${{ inputs.version }}
104+
VERSION: ${{ env.VERSION }}
92105
TAG_TEMPLATE: ${{ inputs.tag_template }}
93106
PRODUCT_NAME: ${{ inputs.product_name }}
94107
DRY_RUN: ${{ inputs.dry_run }}

python/post-publish/post-publish.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ else
2929
fi
3030

3131
# Handle push_changes output.
32-
echo "push_changes=$PUSH_CHANGES" >> $GITHUB_OUTPUT
32+
echo "push_changes=$PUSH_CHANGES" >> $GITHUB_OUTPUT

python/pre-publish/action.yml

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ description: Perform pre-release operations for Python Libraries
33
inputs:
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 }}
@@ -66,7 +83,7 @@ runs:
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

Comments
 (0)