From 0f461612fdc4ba54db10f1197ccf731e21100813 Mon Sep 17 00:00:00 2001 From: Travis Donia Date: Wed, 24 Apr 2024 10:41:12 -0400 Subject: [PATCH] add pypi test release workflow --- .github/workflows/publish-to-pypi-test.yaml | 136 ++++++++++++++++++++ .github/workflows/release-test.yaml | 46 +++++++ Makefile | 4 + 3 files changed, 186 insertions(+) create mode 100644 .github/workflows/publish-to-pypi-test.yaml create mode 100644 .github/workflows/release-test.yaml diff --git a/.github/workflows/publish-to-pypi-test.yaml b/.github/workflows/publish-to-pypi-test.yaml new file mode 100644 index 00000000..8270305c --- /dev/null +++ b/.github/workflows/publish-to-pypi-test.yaml @@ -0,0 +1,136 @@ +name: Publish to PyPI Test + +on: + workflow_call: + secrets: + PYPI_USERNAME: + required: true + PYPI_PASSWORD: + required: true + inputs: + ref: + description: 'Git ref to build (branch name or SHA)' + required: true + type: string + default: 'main' + releaseLevel: + description: 'Release level' + required: true + type: string + default: 'patch' + isPrerelease: + description: 'Whether this is a prerelease' + required: true + type: boolean + default: true + prereleaseSuffix: + description: 'Suffix to add onto the new version number in order to mark it as a prerelease. Value ignored when shipping a release that is not a prerelease.' + required: false + type: string + default: 'rc1' + TWINE_REPOSITORY: + description: 'PyPI repository' + required: true + type: string + default: 'pypi' # options are: pypi, testpypi + +jobs: + pypi: + timeout-minutes: 30 + name: pypi + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Need full history and tags to compute list of commits in release + ref: ${{ inputs.ref }} + + - name: Verify prereleaseSuffix not empty if isPrerelease is true + if: ${{ inputs.isPrerelease == true }} + run: | + if [ -z "${{ inputs.prereleaseSuffix }}" ]; then + echo "prereleaseSuffix cannot be empty if isPrerelease is true" + exit 1 + fi + + - name: Bump version + id: bump + uses: './.github/actions/bump-version' + with: + versionFile: pinecone/__version__ + bumpType: ${{ inputs.releaseLevel }} + prereleaseSuffix: ${{ inputs.prereleaseSuffix }} + + - name: Verify unique release number + run: | + TAG_NAME=${{ steps.bump.outputs.VERSION_TAG }} + if git rev-parse -q --verify "refs/tags/$TAG_NAME" >/dev/null; then + echo "Tag $TAG_NAME already exists." + exit 1 + fi + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: 3.x + + - name: Setup Poetry + uses: ./.github/actions/setup-poetry + + - name: Set up Git + run: | + git config --global user.name "Pinecone CI" + git config --global user.email "clients@pinecone.io" + + - name: Poetry bump pyproject toml version + run: | + poetry version ${{ steps.bump.outputs.version }} + + - name: Build Python client + run: make package + + - name: Upload Python client to PyPI + id: pypi_upload + env: + PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }} + PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + TWINE_REPOSITORY: ${{ inputs.TWINE_REPOSITORY }} + run: make upload-test + + - name: Discard changes, if prerelease + if: ${{ inputs.isPrerelease == true }} + run: | + git checkout pinecone/__version__ + + - name: Commit changes, if not prerelease + if: ${{ inputs.isPrerelease == false }} + run: | + # Add the original pinecone client version file to git + # Even though Poetry is now the preferred means of working + # with this project, since this __version__ file has been the + # one source of truth for our release process. We need to maintain + # both files for the time being, and they should always contain the + # identical package version + git add pinecone/__version__ + # Add also the pyproject.toml, which is Poetry's source of truth, so + # that we maintain the exact same version across the two files + git add pyproject.toml + git commit -m "[skip ci] Bump version to ${{ steps.bump.outputs.VERSION_TAG }}" + + - name: Tag version + run: | + newVersionTag="${{ steps.bump.outputs.VERSION_TAG }}" + git tag -a $newVersionTag -m "Release $newVersionTag" + + - name: Push tags (prerelease) + if: ${{ inputs.isPrerelease == true }} + # In the case of the prerelease, we discarded the version changes + # instead of committing them. So we need a slightly different + # command to push the git tag we created. + run: git push --tags + + - name: Push tags (production release) + if: ${{ inputs.isPrerelease == false }} + run: git push --follow-tags diff --git a/.github/workflows/release-test.yaml b/.github/workflows/release-test.yaml new file mode 100644 index 00000000..8bb10777 --- /dev/null +++ b/.github/workflows/release-test.yaml @@ -0,0 +1,46 @@ +name: 'PyPI Test Release: Production (pinecone)' + +on: + workflow_dispatch: + inputs: + ref: + description: 'Git ref to build (branch name or SHA)' + required: true + type: string + default: 'main' + releaseLevel: + description: 'Release level' + required: true + type: choice + default: 'patch' + options: + - 'patch' # bug fixes + - 'minor' # new features, backwards compatible + - 'major' # breaking changes + +jobs: + unit-tests: + uses: './.github/workflows/testing-unit.yaml' + secrets: inherit + integration-tests: + uses: './.github/workflows/testing-integration.yaml' + secrets: inherit + dependency-tests: + uses: './.github/workflows/testing-dependency.yaml' + secrets: inherit + + pypi: + uses: './.github/workflows/publish-to-pypi.yaml' + needs: + - unit-tests + - integration-tests + - dependency-tests + with: + isPrerelease: false + ref: ${{ inputs.ref }} + releaseLevel: ${{ inputs.releaseLevel }} + TWINE_REPOSITORY: 'pypi' + prereleaseSuffix: '' + secrets: + PYPI_USERNAME: __token__ + PYPI_PASSWORD: ${{ secrets.PROD_PYPI_PUBLISH_TOKEN }} diff --git a/Makefile b/Makefile index 45e13cef..f688a58b 100644 --- a/Makefile +++ b/Makefile @@ -29,6 +29,10 @@ package: upload: poetry publish --verbose --username ${PYPI_USERNAME} --password ${PYPI_PASSWORD} +upload-test: + poetry config repositories.test-pypi https://test.pypi.org/legacy/ + poetry publish --verbose -r test-pypi --username ${TEST_PYPI_USERNAME} --password ${TEST_PYPI_PASSWORD} + upload-spruce: # Configure Poetry for publishing to testpypi poetry config repositories.test-pypi https://test.pypi.org/legacy/