From bfd96d04b13dbcc1f0dd7b4fc5ebcc7bedcca7c4 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 21 Apr 2025 09:38:24 -0500 Subject: [PATCH 1/3] INTPYTHON-593 Add automated release workflow --- .../{release-python.yml => dist.yml} | 35 ++++++++----------- 1 file changed, 14 insertions(+), 21 deletions(-) rename .github/workflows/{release-python.yml => dist.yml} (83%) diff --git a/.github/workflows/release-python.yml b/.github/workflows/dist.yml similarity index 83% rename from .github/workflows/release-python.yml rename to .github/workflows/dist.yml index 4e5f15b..4ec4f36 100644 --- a/.github/workflows/release-python.yml +++ b/.github/workflows/dist.yml @@ -1,4 +1,4 @@ -name: Python Wheels +name: Python Dist on: push: @@ -7,20 +7,29 @@ on: - "[0-9]+.[0-9]+.[0-9]+.post[0-9]+" - "[0-9]+.[0-9]+.[0-9]+[a-b][0-9]+" - "[0-9]+.[0-9]+.[0-9]+rc[0-9]+" - pull_request: workflow_dispatch: + pull_request: + workflow_call: + inputs: + ref: + required: true + type: string concurrency: - group: wheels-${{ github.ref }} + group: dist-${{ github.ref }} cancel-in-progress: true +defaults: + run: + shell: bash -eux {0} + jobs: build_wheels: runs-on: ${{ matrix.os }} strategy: matrix: os: [macos-latest, windows-latest, ubuntu-latest] - name: Build CPython ${{ matrix.python-version }}-${{ matrix.os }} + name: Build CPython-${{ matrix.os }} steps: - uses: actions/checkout@v4 - uses: pypa/cibuildwheel@v2.23.2 @@ -108,20 +117,4 @@ jobs: - uses: actions/upload-artifact@v4 with: name: all-dist-${{ github.run_id }} - path: "./*" - publish: - # https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/#publishing-the-distribution-to-pypi - needs: [collect_dist] - if: startsWith(github.ref, 'refs/tags/') - runs-on: ubuntu-latest - environment: release - permissions: - id-token: write - steps: - - name: Download all the dists - uses: actions/download-artifact@v4 - with: - name: all-dist-${{ github.run_id }} - path: dist/ - - name: Publish distribution 📦 to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 \ No newline at end of file + path: "./*" \ No newline at end of file From 7e2573b56a02048987131e003dabf744d83b245c Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 21 Apr 2025 09:38:33 -0500 Subject: [PATCH 2/3] add release workflow --- .github/workflows/release-python.yml | 113 +++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 .github/workflows/release-python.yml diff --git a/.github/workflows/release-python.yml b/.github/workflows/release-python.yml new file mode 100644 index 0000000..2c5ea14 --- /dev/null +++ b/.github/workflows/release-python.yml @@ -0,0 +1,113 @@ +name: Release + +on: + workflow_dispatch: + inputs: + following_version: + description: "The post (dev) version to set" + dry_run: + description: "Dry Run?" + default: false + type: boolean + schedule: + - cron: '30 5 * * *' + +env: + # Changes per repo + PRODUCT_NAME: python-bsonjs + # Constant + # inputs will be empty on a scheduled run. so, we only set dry_run + # to 'false' when the input is set to 'false'. + DRY_RUN: ${{ ! contains(inputs.dry_run, 'false') }} + FOLLOWING_VERSION: ${{ inputs.following_version || '' }} + +concurrency: + group: wheels-${{ github.ref }} + cancel-in-progress: true + +defaults: + run: + shell: bash -eux {0} + +jobs: + pre-publish: + environment: release + runs-on: ubuntu-latest + if: github.repository_owner == 'mongodb-labs' || github.event_name == 'workflow_dispatch' + permissions: + id-token: write + contents: write + outputs: + version: ${{ steps.pre-publish.outputs.version }} + steps: + - uses: mongodb-labs/drivers-github-tools/secure-checkout@v2 + with: + app_id: ${{ vars.APP_ID }} + private_key: ${{ secrets.APP_PRIVATE_KEY }} + - uses: mongodb-labs/drivers-github-tools/setup@v2 + with: + aws_role_arn: ${{ secrets.AWS_ROLE_ARN }} + aws_region_name: ${{ vars.AWS_REGION_NAME }} + aws_secret_id: ${{ secrets.AWS_SECRET_ID }} + artifactory_username: ${{ vars.ARTIFACTORY_USERNAME }} + - uses: mongodb-labs/drivers-github-tools/python-labs/pre-publish@v2 + id: pre-publish + with: + dry_run: ${{ env.DRY_RUN }} + + build-dist: + needs: [pre-publish] + uses: ./.github/workflows/dist-python.yml + with: + ref: ${{ needs.pre-publish.outputs.version }} + + publish: + # https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/#publishing-the-distribution-to-pypi + needs: [build-dist] + if: (github.repository_owner == 'mongodb-labs' && github.event_name != 'pull_request') || github.event_name == 'workflow_dispatch' + runs-on: ubuntu-latest + environment: release + permissions: + id-token: write + steps: + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: all-dist-${{ github.run_id }} + path: dist/ + - name: Publish package distributions to TestPyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ + skip-existing: true + attestations: ${{ !startsWith(github.ref, 'refs/tags/') }} + - name: Publish distribution 📦 to PyPI + if: startsWith(github.ref, 'refs/tags/') + uses: pypa/gh-action-pypi-publish@release/v1 + + post-publish: + needs: [publish] + runs-on: ubuntu-latest + environment: release + permissions: + id-token: write + contents: write + attestations: write + security-events: write + steps: + - uses: mongodb-labs/drivers-github-tools/secure-checkout@v2 + with: + app_id: ${{ vars.APP_ID }} + private_key: ${{ secrets.APP_PRIVATE_KEY }} + - uses: mongodb-labs/drivers-github-tools/setup@v2 + with: + aws_role_arn: ${{ secrets.AWS_ROLE_ARN }} + aws_region_name: ${{ vars.AWS_REGION_NAME }} + aws_secret_id: ${{ secrets.AWS_SECRET_ID }} + artifactory_username: ${{ vars.ARTIFACTORY_USERNAME }} + - uses: mongodb-labs/drivers-github-tools/python-labs/post-publish@v2 + with: + following_version: ${{ env.FOLLOWING_VERSION }} + product_name: ${{ env.PRODUCT_NAME }} + token: ${{ github.token }} + dry_run: ${{ env.DRY_RUN }} From 7b24a7f7da756a398599b56d39b8a3bb6a35062f Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 21 Apr 2025 09:44:29 -0500 Subject: [PATCH 3/3] fix workflow call --- .github/workflows/release-python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-python.yml b/.github/workflows/release-python.yml index 2c5ea14..de6fd72 100644 --- a/.github/workflows/release-python.yml +++ b/.github/workflows/release-python.yml @@ -57,7 +57,7 @@ jobs: build-dist: needs: [pre-publish] - uses: ./.github/workflows/dist-python.yml + uses: ./.github/workflows/dist.yml with: ref: ${{ needs.pre-publish.outputs.version }}