Skip to content

Commit 76db892

Browse files
committed
INTPYTHON-615 Set up GitHub workflows for automated releases
1 parent 92954cc commit 76db892

File tree

3 files changed

+97
-77
lines changed

3 files changed

+97
-77
lines changed
Lines changed: 87 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1-
name: Python Wheels
1+
name: Release
22

33
on:
4-
push:
5-
branches: ["main"]
6-
tags:
7-
- "**"
8-
pull_request:
94
workflow_dispatch:
5+
inputs:
6+
following_version:
7+
description: "The post (dev) version to set"
8+
dry_run:
9+
description: "Dry Run?"
10+
default: false
11+
type: boolean
12+
schedule:
13+
- cron: '30 5 * * *'
14+
15+
env:
16+
# Changes per repo
17+
PRODUCT_NAME: python-bsonjs
18+
# Constant
19+
# inputs will be empty on a scheduled run. so, we only set dry_run
20+
# to 'false' when the input is set to 'false'.
21+
DRY_RUN: ${{ ! contains(inputs.dry_run, 'false') }}
22+
FOLLOWING_VERSION: ${{ inputs.following_version || '' }}
1023

1124
concurrency:
1225
group: wheels-${{ github.ref }}
@@ -17,83 +30,90 @@ defaults:
1730
shell: bash -eux {0}
1831

1932
jobs:
20-
21-
build_dist:
22-
name: Build Distribution Files
23-
runs-on: ubuntu-latest
24-
steps:
25-
- uses: actions/checkout@v4
26-
with:
27-
fetch-depth: 0
28-
persist-credentials: false
29-
30-
- uses: actions/setup-python@v5
31-
with:
32-
# Build sdist on lowest supported Python
33-
python-version: '3.10'
34-
35-
- name: Install build
36-
run: |
37-
python -m pip install build
38-
39-
- name: build the dist files
40-
run: |
41-
python -m build .
42-
43-
- name: Upload the dist files
44-
uses: actions/upload-artifact@v4
45-
with:
46-
name: dist-${{ github.run_id }}
47-
path: ./dist/*.*
48-
49-
test_dist:
50-
needs: [build_dist]
51-
name: Test Distribution Files
33+
pre-publish:
34+
environment: release
5235
runs-on: ubuntu-latest
36+
if: github.repository_owner == 'mongodb-labs' || github.event_name == 'workflow_dispatch'
37+
permissions:
38+
id-token: write
39+
contents: write
40+
outputs:
41+
version: ${{ steps.pre-publish.outputs.version }}
5342
steps:
54-
- uses: actions/checkout@v4
43+
- uses: mongodb-labs/drivers-github-tools/secure-checkout@v2
5544
with:
56-
fetch-depth: 0
57-
persist-credentials: false
58-
59-
- uses: actions/setup-python@v5
45+
app_id: ${{ vars.APP_ID }}
46+
private_key: ${{ secrets.APP_PRIVATE_KEY }}
47+
- uses: mongodb-labs/drivers-github-tools/setup@v2
6048
with:
61-
# Build sdist on lowest supported Python
62-
python-version: '3.10'
63-
64-
- name: Download the dists
65-
uses: actions/download-artifact@v4
49+
aws_role_arn: ${{ secrets.AWS_ROLE_ARN }}
50+
aws_region_name: ${{ vars.AWS_REGION_NAME }}
51+
aws_secret_id: ${{ secrets.AWS_SECRET_ID }}
52+
artifactory_username: ${{ vars.ARTIFACTORY_USERNAME }}
53+
- uses: mongodb-labs/drivers-github-tools/python-labs/pre-publish@v2
54+
id: pre-publish
6655
with:
67-
name: dist-${{ github.run_id }}
68-
path: dist/
56+
dry_run: ${{ env.DRY_RUN }}
6957

70-
- name: Test the sdist
71-
run: |
72-
cd dist
73-
pip install *.tar.gz
74-
python -c "import pymongo_voyageai"
75-
pip uninstall -y pymongo_voyageai
58+
build-dist:
59+
needs: [pre-publish]
60+
uses: ./.github/workflows/dist.yml
61+
with:
62+
ref: ${{ needs.pre-publish.outputs.version }}
7663

77-
- name: Test the wheel
78-
run: |
79-
cd dist
80-
pip install *.whl
81-
python -c "import pymongo_voyageai"
82-
pip uninstall -y pymongo_voyageai
64+
static-scan:
65+
needs: [pre-publish]
66+
uses: ./.github/workflows/codeql.yml
67+
with:
68+
ref: ${{ needs.pre-publish.outputs.version }}
8369

8470
publish:
8571
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/#publishing-the-distribution-to-pypi
86-
needs: [test_dist]
87-
if: startsWith(github.ref, 'refs/tags/')
72+
needs: [build-dist, static-scan]
73+
if: (github.repository_owner == 'mongodb-labs' && github.event_name != 'pull_request') || github.event_name == 'workflow_dispatch'
8874
runs-on: ubuntu-latest
8975
environment: release
9076
permissions:
9177
id-token: write
9278
steps:
93-
- name: Download the dists
79+
- name: Download all the dists
9480
uses: actions/download-artifact@v4
9581
with:
96-
name: dist-${{ github.run_id }}
82+
name: all-dist-${{ github.run_id }}
9783
path: dist/
84+
- name: Publish package distributions to TestPyPI
85+
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # release/v1
86+
with:
87+
repository-url: https://test.pypi.org/legacy/
88+
skip-existing: true
89+
attestations: ${{ env.DRY_RUN }}
9890
- name: Publish distribution 📦 to PyPI
99-
uses: pypa/gh-action-pypi-publish@release/v1
91+
if: startsWith(env.DRY_RUN, 'false')
92+
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # release/v1
93+
94+
post-publish:
95+
needs: [publish]
96+
runs-on: ubuntu-latest
97+
environment: release
98+
permissions:
99+
id-token: write
100+
contents: write
101+
attestations: write
102+
security-events: write
103+
steps:
104+
- uses: mongodb-labs/drivers-github-tools/secure-checkout@v2
105+
with:
106+
app_id: ${{ vars.APP_ID }}
107+
private_key: ${{ secrets.APP_PRIVATE_KEY }}
108+
- uses: mongodb-labs/drivers-github-tools/setup@v2
109+
with:
110+
aws_role_arn: ${{ secrets.AWS_ROLE_ARN }}
111+
aws_region_name: ${{ vars.AWS_REGION_NAME }}
112+
aws_secret_id: ${{ secrets.AWS_SECRET_ID }}
113+
artifactory_username: ${{ vars.ARTIFACTORY_USERNAME }}
114+
- uses: mongodb-labs/drivers-github-tools/python-labs/post-publish@v2
115+
with:
116+
following_version: ${{ env.FOLLOWING_VERSION }}
117+
product_name: ${{ env.PRODUCT_NAME }}
118+
token: ${{ github.token }}
119+
dry_run: ${{ env.DRY_RUN }}

.github/workflows/test-python.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ jobs:
2525
persist-credentials: false
2626
fetch-depth: 0
2727
- name: Install uv
28-
uses: astral-sh/setup-uv@v5
28+
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5
2929
with:
3030
enable-cache: true
3131
python-version: ${{ matrix.python-version }}
32-
- uses: extractions/setup-just@v3
32+
- uses: extractions/setup-just@e33e0265a09d6d736e2ee1e0eb685ef1de4669ff # v3
3333
- run: just install
3434
- run: just lint
3535
- run: just docs
@@ -47,11 +47,11 @@ jobs:
4747
persist-credentials: false
4848
fetch-depth: 0
4949
- name: Install uv
50-
uses: astral-sh/setup-uv@v5
50+
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5
5151
with:
5252
enable-cache: true
5353
python-version: ${{ matrix.python-version }}
54-
- uses: extractions/setup-just@v3
54+
- uses: extractions/setup-just@e33e0265a09d6d736e2ee1e0eb685ef1de4669ff # v3
5555
- uses: mongodb-labs/drivers-evergreen-tools@master
5656
with:
5757
local-atlas: '1'
@@ -66,17 +66,17 @@ jobs:
6666
persist-credentials: false
6767
fetch-depth: 0
6868
- name: Install uv
69-
uses: astral-sh/setup-uv@v5
69+
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5
7070
with:
7171
enable-cache: true
7272
python-version: ${{ env.MIN_PYTHON }}
73-
- uses: extractions/setup-just@v3
73+
- uses: extractions/setup-just@e33e0265a09d6d736e2ee1e0eb685ef1de4669ff # v3
7474
- name: Install uv
75-
uses: astral-sh/setup-uv@v5
75+
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5
7676
with:
7777
enable-cache: true
7878
python-version: ${{ env.MIN_PYTHON }}
79-
- uses: extractions/setup-just@v3
79+
- uses: extractions/setup-just@e33e0265a09d6d736e2ee1e0eb685ef1de4669ff # v3
8080
- uses: mongodb-labs/drivers-evergreen-tools@master
8181
with:
8282
local-atlas: '1'

.github/workflows/zizmor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ jobs:
1818
with:
1919
persist-credentials: false
2020
- name: Setup Rust
21-
uses: actions-rust-lang/setup-rust-toolchain@v1
21+
uses: actions-rust-lang/setup-rust-toolchain@9d7e65c320fdb52dcd45ffaa68deb6c02c8754d9 # v1
2222
- name: Get zizmor
2323
run: cargo install zizmor
2424
- name: Run zizmor
2525
run: zizmor --format sarif . > results.sarif
2626
env:
2727
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2828
- name: Upload SARIF file
29-
uses: github/codeql-action/upload-sarif@v3
29+
uses: github/codeql-action/upload-sarif@28deaeda66b76a05916b6923827895f2b14ab387 # v3
3030
with:
3131
sarif_file: results.sarif
3232
category: zizmor

0 commit comments

Comments
 (0)