From 367cdb51ca2edb9b3f4547faf749c5d1f727cef6 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 8 Apr 2025 07:59:29 -0500 Subject: [PATCH 01/15] PYTHON-5188 Make the input version optional --- python/post-publish/action.yml | 21 ++++++++++++++++----- python/pre-publish/action.yml | 15 ++++++++++----- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/python/post-publish/action.yml b/python/post-publish/action.yml index f7eeb1e..591312c 100644 --- a/python/post-publish/action.yml +++ b/python/post-publish/action.yml @@ -4,7 +4,6 @@ description: Perform post-release operations for Python Libraries inputs: version: description: The published version - required: true following_version: description: The following (dev) version required: false @@ -56,6 +55,18 @@ runs: with: name: all-dist-${{ github.run_id }} path: dist/ + - name: Ensure we have the package version + shell: bash + run: | + # Handle version already bumped + if [ -z "${{ inputs.version }} ]; + # Extract the version from the sdist name, which must be of the from + # {name}-{version}.tar.gz according to PEP 625. + VERSION=$(ls dist/*.tar.gz | rev | cut -d'-' -f 1 | rev | sed 's/.tar.gz//g') + echo "VERSION=$VERSION" >> $GITHUB_ENV + else + echo "VERSION=${{ inputs.version}}" >> $GITHUB_ENV + fi - name: Create detached signature for dist files uses: mongodb-labs/drivers-github-tools/gpg-sign@v2 with: @@ -68,8 +79,8 @@ runs: - uses: mongodb-labs/drivers-github-tools/full-report@v2 with: product_name: ${{ inputs.product_name }} - release_version: ${{ inputs.version }} - sarif_report_target_ref: ${{ inputs.version }} + release_version: ${{ env.VERSION }} + sarif_report_target_ref: ${{ env.VERSION }} dist_filenames: dist/* kondukto_sub_project: ${{ inputs.kondukto_sub_project }} sbom_in_path: ${{ inputs.sbom_in_path }} @@ -79,7 +90,7 @@ runs: token: ${{ inputs.token }} - uses: mongodb-labs/drivers-github-tools/upload-s3-assets@v2 with: - version: ${{ inputs.version }} + version: ${{ env.VERSION }} product_name: ${{ inputs.product_name }} dry_run: ${{ inputs.dry_run }} - name: Run GitHub Publish script @@ -88,7 +99,7 @@ runs: run: ${{ github.action_path }}/post-publish.sh env: GH_TOKEN: ${{ inputs.token }} - VERSION: ${{ inputs.version }} + VERSION: ${{ env.VERSION }} TAG_TEMPLATE: ${{ inputs.tag_template }} PRODUCT_NAME: ${{ inputs.product_name }} DRY_RUN: ${{ inputs.dry_run }} diff --git a/python/pre-publish/action.yml b/python/pre-publish/action.yml index 1d4955d..7a8e4b1 100644 --- a/python/pre-publish/action.yml +++ b/python/pre-publish/action.yml @@ -3,7 +3,6 @@ description: Perform pre-release operations for Python Libraries inputs: version: description: The published version - required: true version_bump_script: description: The version bump script default: hatch version @@ -35,7 +34,7 @@ runs: shell: bash working-directory: ${{ inputs.working_directory }} run: pipx install hatch - - name: Check if we should push changes + - name: Handle inputs shell: bash run: | # Handle DRY_RUN @@ -45,17 +44,23 @@ runs: export PUSH_CHANGES=false fi echo "PUSH_CHANGES=$PUSH_CHANGES" >> $GITHUB_ENV + # Handle version already bumped + if [ -z "${{ inputs.version }} ]; + echo "VERSION=$(hatch project metadata version)" >> $GITHUB_ENV + else + echo "VERSION=${{ inputs.version}}" >> $GITHUB_ENV + fi - name: Set version uses: mongodb-labs/drivers-github-tools/bump-version@v2 with: - version: ${{ inputs.version }} + version: ${{ env.VERSION }} version_bump_script: ${{ inputs.version_bump_script }} working_directory: ${{ inputs.working_directory }} push_commit: ${{ env.PUSH_CHANGES }} - name: Tag version uses: mongodb-labs/drivers-github-tools/tag-version@v2 with: - version: ${{ inputs.version }} + version: ${{ env.VERSION }} tag_template: ${{ inputs.tag_template }} tag_message_template: ${{ inputs.tag_message_template }} push_tag: ${{ env.PUSH_CHANGES }} @@ -66,7 +71,7 @@ runs: if [ "${{ inputs.dry_run}}" == 'true' ]; then echo "version=${{ github.ref }}" >> $GITHUB_OUTPUT else - export VERSION=${{ inputs.version }} + export VERSION=${{ env.VERSION }} export TAG=$(echo "${{ inputs.tag_template }}" | envsubst) echo "version=$TAG" >> $GITHUB_OUTPUT fi \ No newline at end of file From a6d2ef30b6e5aa1eb948a3daab24cda1d39d2f49 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 8 Apr 2025 08:31:01 -0500 Subject: [PATCH 02/15] fix syntax --- python/post-publish/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/post-publish/action.yml b/python/post-publish/action.yml index 591312c..da6f437 100644 --- a/python/post-publish/action.yml +++ b/python/post-publish/action.yml @@ -59,7 +59,7 @@ runs: shell: bash run: | # Handle version already bumped - if [ -z "${{ inputs.version }} ]; + if [ -z "${{ inputs.version }}" ]; # Extract the version from the sdist name, which must be of the from # {name}-{version}.tar.gz according to PEP 625. VERSION=$(ls dist/*.tar.gz | rev | cut -d'-' -f 1 | rev | sed 's/.tar.gz//g') From 77c808e4b1a531d0e639577dd0002935c08d3e78 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 8 Apr 2025 08:36:07 -0500 Subject: [PATCH 03/15] fix syntax --- python/post-publish/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/post-publish/action.yml b/python/post-publish/action.yml index da6f437..bcc48df 100644 --- a/python/post-publish/action.yml +++ b/python/post-publish/action.yml @@ -59,7 +59,7 @@ runs: shell: bash run: | # Handle version already bumped - if [ -z "${{ inputs.version }}" ]; + if [ -z "${{ inputs.version }}" ]; then # Extract the version from the sdist name, which must be of the from # {name}-{version}.tar.gz according to PEP 625. VERSION=$(ls dist/*.tar.gz | rev | cut -d'-' -f 1 | rev | sed 's/.tar.gz//g') From 4ac71dda5643f357ac4ae566c8ceb84dbafef916 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 8 Apr 2025 08:42:42 -0500 Subject: [PATCH 04/15] fix syntax --- python/post-publish/post-publish.sh | 2 +- python/pre-publish/action.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python/post-publish/post-publish.sh b/python/post-publish/post-publish.sh index e7ff904..d424ff3 100755 --- a/python/post-publish/post-publish.sh +++ b/python/post-publish/post-publish.sh @@ -29,4 +29,4 @@ else fi # Handle push_changes output. -echo "push_changes=$PUSH_CHANGES" >> $GITHUB_OUTPUT \ No newline at end of file +echo "push_changes=$PUSH_CHANGES" >> $GITHUB_OUTPUT diff --git a/python/pre-publish/action.yml b/python/pre-publish/action.yml index 7a8e4b1..b6f401c 100644 --- a/python/pre-publish/action.yml +++ b/python/pre-publish/action.yml @@ -45,7 +45,7 @@ runs: fi echo "PUSH_CHANGES=$PUSH_CHANGES" >> $GITHUB_ENV # Handle version already bumped - if [ -z "${{ inputs.version }} ]; + if [ -z "${{ inputs.version }}" ]; then echo "VERSION=$(hatch project metadata version)" >> $GITHUB_ENV else echo "VERSION=${{ inputs.version}}" >> $GITHUB_ENV From 58c7abe14057c9e4dc249867e3ab912f370f012f Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 8 Apr 2025 08:46:11 -0500 Subject: [PATCH 05/15] fix set version handling --- python/pre-publish/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/python/pre-publish/action.yml b/python/pre-publish/action.yml index b6f401c..44ee82b 100644 --- a/python/pre-publish/action.yml +++ b/python/pre-publish/action.yml @@ -52,6 +52,7 @@ runs: fi - name: Set version uses: mongodb-labs/drivers-github-tools/bump-version@v2 + if: ${{ inputs.version }} with: version: ${{ env.VERSION }} version_bump_script: ${{ inputs.version_bump_script }} From 113766b2336015f25160e8a4c1c975186c4327d6 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 8 Apr 2025 08:47:19 -0500 Subject: [PATCH 06/15] debug --- python/pre-publish/action.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/pre-publish/action.yml b/python/pre-publish/action.yml index 44ee82b..8525db5 100644 --- a/python/pre-publish/action.yml +++ b/python/pre-publish/action.yml @@ -46,7 +46,9 @@ runs: echo "PUSH_CHANGES=$PUSH_CHANGES" >> $GITHUB_ENV # Handle version already bumped if [ -z "${{ inputs.version }}" ]; then - echo "VERSION=$(hatch project metadata version)" >> $GITHUB_ENV + VERSION=$(hatch project metadata version) + echo $VERSION + echo "VERSION=$VERSION" >> $GITHUB_ENV else echo "VERSION=${{ inputs.version}}" >> $GITHUB_ENV fi From 2ab6b0caf7ddfd0c1243e136e963179b17f211e0 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 8 Apr 2025 08:49:00 -0500 Subject: [PATCH 07/15] debug --- python/pre-publish/action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/pre-publish/action.yml b/python/pre-publish/action.yml index 8525db5..cdb9d81 100644 --- a/python/pre-publish/action.yml +++ b/python/pre-publish/action.yml @@ -37,6 +37,7 @@ runs: - name: Handle inputs shell: bash run: | + set -eux # Handle DRY_RUN if [ "${{ inputs.dry_run }}" != "true" ]; then export PUSH_CHANGES=true @@ -46,6 +47,7 @@ runs: echo "PUSH_CHANGES=$PUSH_CHANGES" >> $GITHUB_ENV # Handle version already bumped if [ -z "${{ inputs.version }}" ]; then + which hatch VERSION=$(hatch project metadata version) echo $VERSION echo "VERSION=$VERSION" >> $GITHUB_ENV From ae73af5c98c1dc972dfc76dbb17e10b4cfdb0b78 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 8 Apr 2025 08:50:57 -0500 Subject: [PATCH 08/15] debug --- python/pre-publish/action.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/pre-publish/action.yml b/python/pre-publish/action.yml index cdb9d81..0eb9886 100644 --- a/python/pre-publish/action.yml +++ b/python/pre-publish/action.yml @@ -33,7 +33,9 @@ runs: - name: Install hatch shell: bash working-directory: ${{ inputs.working_directory }} - run: pipx install hatch + run: | + pipx install hatch + pipx inject hatch hatchling - name: Handle inputs shell: bash run: | From 61ff405c824f08d5de454933aaf4b0e9691f73c7 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 8 Apr 2025 08:53:15 -0500 Subject: [PATCH 09/15] debug --- python/pre-publish/action.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/python/pre-publish/action.yml b/python/pre-publish/action.yml index 0eb9886..0f0ccee 100644 --- a/python/pre-publish/action.yml +++ b/python/pre-publish/action.yml @@ -35,7 +35,7 @@ runs: working-directory: ${{ inputs.working_directory }} run: | pipx install hatch - pipx inject hatch hatchling + pip install build - name: Handle inputs shell: bash run: | @@ -49,10 +49,12 @@ runs: echo "PUSH_CHANGES=$PUSH_CHANGES" >> $GITHUB_ENV # Handle version already bumped if [ -z "${{ inputs.version }}" ]; then - which hatch - VERSION=$(hatch project metadata version) - echo $VERSION + python -m build --sdist . + # Extract the version from the sdist name, which must be of the from + # {name}-{version}.tar.gz according to PEP 625. + VERSION=$(ls dist/*.tar.gz | rev | cut -d'-' -f 1 | rev | sed 's/.tar.gz//g') echo "VERSION=$VERSION" >> $GITHUB_ENV + rm -rf dist else echo "VERSION=${{ inputs.version}}" >> $GITHUB_ENV fi From b93a40b3ec8c2c6ad1483aa999c2b60691eb7606 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 8 Apr 2025 12:30:07 -0500 Subject: [PATCH 10/15] address code scan --- python/post-publish/action.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/python/post-publish/action.yml b/python/post-publish/action.yml index bcc48df..9868c1f 100644 --- a/python/post-publish/action.yml +++ b/python/post-publish/action.yml @@ -57,15 +57,17 @@ runs: path: dist/ - name: Ensure we have the package version shell: bash + env: + VERSION: "${{ inputs.version }}" run: | # Handle version already bumped - if [ -z "${{ inputs.version }}" ]; then + if [ -z "${VERSION}" ]; then # Extract the version from the sdist name, which must be of the from # {name}-{version}.tar.gz according to PEP 625. VERSION=$(ls dist/*.tar.gz | rev | cut -d'-' -f 1 | rev | sed 's/.tar.gz//g') echo "VERSION=$VERSION" >> $GITHUB_ENV else - echo "VERSION=${{ inputs.version}}" >> $GITHUB_ENV + echo "VERSION=${VERSION}" >> $GITHUB_ENV fi - name: Create detached signature for dist files uses: mongodb-labs/drivers-github-tools/gpg-sign@v2 From bdd6d760d716509c1c2e0f662e1389d874a4eeee Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 8 Apr 2025 12:31:42 -0500 Subject: [PATCH 11/15] cleanup --- python/post-publish/action.yml | 4 ++-- python/pre-publish/action.yml | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/python/post-publish/action.yml b/python/post-publish/action.yml index 9868c1f..b7a4bfb 100644 --- a/python/post-publish/action.yml +++ b/python/post-publish/action.yml @@ -61,13 +61,13 @@ runs: VERSION: "${{ inputs.version }}" run: | # Handle version already bumped - if [ -z "${VERSION}" ]; then + if [ -z "$VERSION" ]; then # Extract the version from the sdist name, which must be of the from # {name}-{version}.tar.gz according to PEP 625. VERSION=$(ls dist/*.tar.gz | rev | cut -d'-' -f 1 | rev | sed 's/.tar.gz//g') echo "VERSION=$VERSION" >> $GITHUB_ENV else - echo "VERSION=${VERSION}" >> $GITHUB_ENV + echo "VERSION={VERSION" >> $GITHUB_ENV fi - name: Create detached signature for dist files uses: mongodb-labs/drivers-github-tools/gpg-sign@v2 diff --git a/python/pre-publish/action.yml b/python/pre-publish/action.yml index 0f0ccee..0e59d88 100644 --- a/python/pre-publish/action.yml +++ b/python/pre-publish/action.yml @@ -38,6 +38,8 @@ runs: pip install build - name: Handle inputs shell: bash + env: + VERSION: "${{ inputs.version }}" run: | set -eux # Handle DRY_RUN @@ -48,15 +50,13 @@ runs: fi echo "PUSH_CHANGES=$PUSH_CHANGES" >> $GITHUB_ENV # Handle version already bumped - if [ -z "${{ inputs.version }}" ]; then - python -m build --sdist . - # Extract the version from the sdist name, which must be of the from + if [ -z "$VERSION" ]; then + # Extract the version from the sdist name, which must be of the from # {name}-{version}.tar.gz according to PEP 625. VERSION=$(ls dist/*.tar.gz | rev | cut -d'-' -f 1 | rev | sed 's/.tar.gz//g') echo "VERSION=$VERSION" >> $GITHUB_ENV - rm -rf dist else - echo "VERSION=${{ inputs.version}}" >> $GITHUB_ENV + echo "VERSION=$VERSION" >> $GITHUB_ENV fi - name: Set version uses: mongodb-labs/drivers-github-tools/bump-version@v2 From bfdab724f94a7003999e4df851eea34cb7297810 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 8 Apr 2025 13:01:51 -0500 Subject: [PATCH 12/15] cleanup --- python/pre-publish/action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/pre-publish/action.yml b/python/pre-publish/action.yml index 0e59d88..a9baab8 100644 --- a/python/pre-publish/action.yml +++ b/python/pre-publish/action.yml @@ -53,8 +53,10 @@ runs: if [ -z "$VERSION" ]; then # Extract the version from the sdist name, which must be of the from # {name}-{version}.tar.gz according to PEP 625. + python -m build --sdist . VERSION=$(ls dist/*.tar.gz | rev | cut -d'-' -f 1 | rev | sed 's/.tar.gz//g') echo "VERSION=$VERSION" >> $GITHUB_ENV + rm -rf dist else echo "VERSION=$VERSION" >> $GITHUB_ENV fi From 9b7b5f3a9300155b6f3a9a64937bb48b1e4df4ea Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 8 Apr 2025 13:03:14 -0500 Subject: [PATCH 13/15] cleanup --- python/post-publish/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/post-publish/action.yml b/python/post-publish/action.yml index b7a4bfb..2abb2a8 100644 --- a/python/post-publish/action.yml +++ b/python/post-publish/action.yml @@ -67,7 +67,7 @@ runs: VERSION=$(ls dist/*.tar.gz | rev | cut -d'-' -f 1 | rev | sed 's/.tar.gz//g') echo "VERSION=$VERSION" >> $GITHUB_ENV else - echo "VERSION={VERSION" >> $GITHUB_ENV + echo "VERSION=$VERSION" >> $GITHUB_ENV fi - name: Create detached signature for dist files uses: mongodb-labs/drivers-github-tools/gpg-sign@v2 From abad185e79c09b60c61f3c716e64a977d782e9d6 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 8 Apr 2025 13:04:11 -0500 Subject: [PATCH 14/15] address code scan --- python/pre-publish/action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/pre-publish/action.yml b/python/pre-publish/action.yml index a9baab8..48606df 100644 --- a/python/pre-publish/action.yml +++ b/python/pre-publish/action.yml @@ -40,10 +40,11 @@ runs: shell: bash env: VERSION: "${{ inputs.version }}" + DRY_RUN: "${{ inputs.dry_run }}" run: | set -eux # Handle DRY_RUN - if [ "${{ inputs.dry_run }}" != "true" ]; then + if [ "$DRY_RUN" != "true" ]; then export PUSH_CHANGES=true else export PUSH_CHANGES=false From 3a20ed2a83e27c865d4d68ea3bb6d4ea0eb11494 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 8 Apr 2025 13:35:12 -0500 Subject: [PATCH 15/15] spelling --- python/post-publish/action.yml | 2 +- python/pre-publish/action.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python/post-publish/action.yml b/python/post-publish/action.yml index 2abb2a8..ef0fb3c 100644 --- a/python/post-publish/action.yml +++ b/python/post-publish/action.yml @@ -62,7 +62,7 @@ runs: run: | # Handle version already bumped if [ -z "$VERSION" ]; then - # Extract the version from the sdist name, which must be of the from + # Extract the version from the sdist name, which must be of the form # {name}-{version}.tar.gz according to PEP 625. VERSION=$(ls dist/*.tar.gz | rev | cut -d'-' -f 1 | rev | sed 's/.tar.gz//g') echo "VERSION=$VERSION" >> $GITHUB_ENV diff --git a/python/pre-publish/action.yml b/python/pre-publish/action.yml index 48606df..914aa87 100644 --- a/python/pre-publish/action.yml +++ b/python/pre-publish/action.yml @@ -52,7 +52,7 @@ runs: echo "PUSH_CHANGES=$PUSH_CHANGES" >> $GITHUB_ENV # Handle version already bumped if [ -z "$VERSION" ]; then - # Extract the version from the sdist name, which must be of the from + # Extract the version from the sdist name, which must be of the form # {name}-{version}.tar.gz according to PEP 625. python -m build --sdist . VERSION=$(ls dist/*.tar.gz | rev | cut -d'-' -f 1 | rev | sed 's/.tar.gz//g')