diff --git a/python/post-publish/action.yml b/python/post-publish/action.yml index f7eeb1e..ef0fb3c 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,20 @@ runs: with: name: all-dist-${{ github.run_id }} path: dist/ + - name: Ensure we have the package version + shell: bash + env: + VERSION: "${{ inputs.version }}" + run: | + # Handle version already bumped + if [ -z "$VERSION" ]; then + # 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 + else + echo "VERSION=$VERSION" >> $GITHUB_ENV + fi - name: Create detached signature for dist files uses: mongodb-labs/drivers-github-tools/gpg-sign@v2 with: @@ -68,8 +81,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 +92,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 +101,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/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 1d4955d..914aa87 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 @@ -34,28 +33,46 @@ runs: - name: Install hatch shell: bash working-directory: ${{ inputs.working_directory }} - run: pipx install hatch - - name: Check if we should push changes + run: | + pipx install hatch + pip install build + - name: Handle inputs 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 fi 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 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') + echo "VERSION=$VERSION" >> $GITHUB_ENV + rm -rf dist + else + echo "VERSION=$VERSION" >> $GITHUB_ENV + fi - name: Set version uses: mongodb-labs/drivers-github-tools/bump-version@v2 + if: ${{ inputs.version }} 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 +83,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