-
Notifications
You must be signed in to change notification settings - Fork 8
INTPYTHON-589 Add automated release support for MongoDB-Labs Projects #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
|
|
||
| name: Python Labs Post-Publish | ||
| description: Perform post-release operations for Python Libraries in MongoDB Labs | ||
| inputs: | ||
| following_version: | ||
| description: The following (dev) version | ||
| required: false | ||
| product_name: | ||
| description: The name of the product | ||
| required: true | ||
| version_bump_script: | ||
| description: The version bump script | ||
| default: hatch version | ||
| working_directory: | ||
| description: The working directory for the action | ||
| default: "." | ||
| tag_template: | ||
| description: The template for the git tag | ||
| default: "${VERSION}" | ||
| repository-url: | ||
| description: The PyPI repository URL to use | ||
| default: https://upload.pypi.org/legacy/ | ||
| token: | ||
| description: The GitHub access token | ||
| dry_run: | ||
| description: Whether this is a dry run | ||
| required: true | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.11' | ||
| - name: Install hatch | ||
| shell: bash | ||
| run: pipx install hatch | ||
| - name: Download all the dists | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| name: all-dist-${{ github.run_id }} | ||
| path: dist/ | ||
| - name: Get the package version | ||
| shell: bash | ||
| 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: Run GitHub Publish script | ||
| shell: bash | ||
| id: publish-script | ||
| run: ${{ github.action_path }}/post-publish.sh | ||
| env: | ||
| GH_TOKEN: ${{ inputs.token }} | ||
| VERSION: ${{ env.VERSION }} | ||
| TAG_TEMPLATE: ${{ inputs.tag_template }} | ||
| PRODUCT_NAME: ${{ inputs.product_name }} | ||
| DRY_RUN: ${{ inputs.dry_run }} | ||
| FOLLOWING_VERSION: ${{ inputs.following_version }} | ||
| - name: Ensure a clean repo | ||
| shell: bash | ||
| run: | | ||
| git clean -dffx | ||
| git pull origin ${GITHUB_REF} | ||
| - name: Set following version | ||
| uses: mongodb-labs/drivers-github-tools/bump-version@v2 | ||
| if: inputs.dry_run == 'false' | ||
| with: | ||
| version: ${{ steps.publish-script.outputs.following_version }} | ||
| version_bump_script: ${{ inputs.version_bump_script }} | ||
| working_directory: ${{ inputs.working_directory }} | ||
| - name: Skip Setting following version | ||
| shell: bash | ||
| if: inputs.dry_run == 'true' | ||
| run: | | ||
| echo "Dry run, not setting the following version: ${{ steps.publish-script.outputs.following_version }}" >> $GITHUB_STEP_SUMMARY | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import sys | ||
| from packaging.version import Version | ||
|
|
||
| version = Version(sys.argv[1]) | ||
| new_version = None | ||
|
|
||
| if version.is_devrelease: | ||
| # For dev releases, increment the dev release number. | ||
| new_version = f"{version.major}.{version.minor}.{version.micro}.dev{version.dev + 1}" | ||
| elif version.is_prerelease: | ||
| # For pre releases, go back to dev release. | ||
| rel_type, rel_num = version.pre | ||
| new_version = f"{version.major}.{version.minor}.{version.micro}.{rel_type}{rel_num + 1}" | ||
| elif version.micro == 0: | ||
| # For minor releases, go to next minor release. | ||
| new_version = f"{version.major}.{version.minor + 1}.0.dev0" | ||
| else: | ||
| # For patch releases, go to the next patch release. | ||
| new_version = f"{version.major}.{version.minor}.{version.micro + 1}.dev0" | ||
|
|
||
| print(str(new_version)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -eux | ||
|
|
||
| # Handle the following version. | ||
| if [ -z "${FOLLOWING_VERSION}" ]; then | ||
| pip install packaging | ||
| pushd $GITHUB_ACTION_PATH | ||
| FOLLOWING_VERSION=$(python handle_following_version.py $VERSION) | ||
| popd | ||
| fi | ||
| echo "following_version=$FOLLOWING_VERSION" >> $GITHUB_OUTPUT | ||
|
|
||
| if [ "$DRY_RUN" == "false" ]; then | ||
| PUSH_CHANGES=true | ||
| echo "Creating draft release with attached files" | ||
| TITLE="${PRODUCT_NAME} ${VERSION}" | ||
| TAG=$(echo "${TAG_TEMPLATE}" | envsubst) | ||
| gh release create ${TAG} --draft --verify-tag --title "${TITLE}" --generate-notes | ||
| gh release upload ${TAG} $RELEASE_ASSETS/*.* | ||
| JSON="url,tagName,assets,author,createdAt" | ||
| JQ='.url,.tagName,.author.login,.createdAt,.assets[].name' | ||
| echo "\## $TITLE" >> $GITHUB_STEP_SUMMARY | ||
| gh release view --json $JSON --jq $JQ ${TAG} >> $GITHUB_STEP_SUMMARY | ||
| else | ||
| echo "Dry run, not creating GitHub Release" >> $GITHUB_STEP_SUMMARY | ||
| ls -ltr $RELEASE_ASSETS | ||
| PUSH_CHANGES=false | ||
| fi | ||
|
|
||
| # Handle push_changes output. | ||
| echo "push_changes=$PUSH_CHANGES" >> $GITHUB_OUTPUT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| name: Python Labs Pre-Publish | ||
| description: Perform pre-release operations for Python Libraries in MongoDB Labs | ||
| inputs: | ||
| tag_template: | ||
| description: The template for the git tag | ||
| default: "${VERSION}" | ||
| tag_message_template: | ||
| description: The template for the git tag message | ||
| default: "Release ${VERSION}" | ||
| working_directory: | ||
| description: The working directory for the action | ||
| default: "." | ||
| dry_run: | ||
| description: Whether this is a dry run | ||
| required: true | ||
|
|
||
| outputs: | ||
| version: | ||
| description: The output version to use | ||
| value: ${{ steps.version.outputs.version }} | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.11' | ||
| - name: Install hatch | ||
| shell: bash | ||
| working-directory: ${{ inputs.working_directory }} | ||
| run: | | ||
| pipx install hatch | ||
| pip install build | ||
| - name: Handle inputs | ||
| shell: bash | ||
| working-directory: ${{ inputs.working_directory }} | ||
| env: | ||
| DRY_RUN: "${{ inputs.dry_run }}" | ||
| run: | | ||
| set -eux | ||
| # Handle DRY_RUN | ||
| if [ "$DRY_RUN" != "true" ]; then | ||
| export PUSH_CHANGES=true | ||
| else | ||
| export PUSH_CHANGES=false | ||
| fi | ||
| echo "PUSH_CHANGES=$PUSH_CHANGES" >> $GITHUB_ENV | ||
| # Handle version | ||
| # 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 | ||
|
||
| - name: Tag version | ||
| uses: mongodb-labs/drivers-github-tools/tag-version@v2 | ||
| with: | ||
| version: ${{ env.VERSION }} | ||
| tag_template: ${{ inputs.tag_template }} | ||
| tag_message_template: ${{ inputs.tag_message_template }} | ||
| push_tag: ${{ env.PUSH_CHANGES }} | ||
| - name: Handle version output | ||
| shell: bash | ||
| id: version | ||
| run: | | ||
| if [ "${{ inputs.dry_run}}" == 'true' ]; then | ||
| echo "version=${{ github.ref }}" >> $GITHUB_OUTPUT | ||
| else | ||
| export VERSION=${{ env.VERSION }} | ||
| export TAG=$(echo "${{ inputs.tag_template }}" | envsubst) | ||
| echo "version=$TAG" >> $GITHUB_OUTPUT | ||
| fi | ||
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this run into the same
dry_runissues we had in PyMongo?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those were addressed at the
envlevel, which will be the same here (see the mongo-arrow PR).