Skip to content

Commit 5719b1d

Browse files
authored
INTPYTHON-593 Add automated release workflow (#69)
* INTPYTHON-593 Add automated release workflow * add release workflow * fix workflow call
1 parent 0ea2bb9 commit 5719b1d

File tree

2 files changed

+206
-100
lines changed

2 files changed

+206
-100
lines changed

.github/workflows/dist.yml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: Python Dist
2+
3+
on:
4+
push:
5+
tags:
6+
- "[0-9]+.[0-9]+.[0-9]+"
7+
- "[0-9]+.[0-9]+.[0-9]+.post[0-9]+"
8+
- "[0-9]+.[0-9]+.[0-9]+[a-b][0-9]+"
9+
- "[0-9]+.[0-9]+.[0-9]+rc[0-9]+"
10+
workflow_dispatch:
11+
pull_request:
12+
workflow_call:
13+
inputs:
14+
ref:
15+
required: true
16+
type: string
17+
18+
concurrency:
19+
group: dist-${{ github.ref }}
20+
cancel-in-progress: true
21+
22+
defaults:
23+
run:
24+
shell: bash -eux {0}
25+
26+
jobs:
27+
build_wheels:
28+
runs-on: ${{ matrix.os }}
29+
strategy:
30+
matrix:
31+
os: [macos-latest, windows-latest, ubuntu-latest]
32+
name: Build CPython-${{ matrix.os }}
33+
steps:
34+
- uses: actions/checkout@v4
35+
- uses: pypa/cibuildwheel@v2.23.2
36+
env:
37+
CIBW_ARCHS_MACOS: x86_64 universal2
38+
CIBW_TEST_SKIP: '*universal2:arm64'
39+
CIBW_BUILD: "cp39-macosx_universal2 cp39-win* cp39-manylinux_{x86_64,i686}"
40+
- uses: actions/upload-artifact@v4
41+
with:
42+
name: ${{ matrix.os }}-wheel
43+
path: ./wheelhouse/*.whl
44+
if-no-files-found: error
45+
test_non_linux_wheels:
46+
needs: build_wheels
47+
runs-on: ${{ matrix.os }}
48+
strategy:
49+
matrix:
50+
os: [macos-latest, windows-latest]
51+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
52+
name: Test CPython ${{ matrix.python-version }}-${{ matrix.os }}
53+
steps:
54+
- name: Setup Python
55+
uses: actions/setup-python@v5
56+
with:
57+
python-version: ${{ matrix.python-version }}
58+
allow-prereleases: true
59+
- name: Download a previously created wheel
60+
uses: actions/download-artifact@v4
61+
with:
62+
name: ${{ matrix.os }}-wheel
63+
- name: Test wheel
64+
shell: bash
65+
run: |
66+
python -m pip install -U pip
67+
python -m pip install --no-index --find-links=./ python_bsonjs
68+
python -m pip list | grep python-bsonjs
69+
python -c "from bsonjs import dumps"
70+
# Linux
71+
test_manylinux_wheels:
72+
runs-on: ${{ matrix.os }}
73+
needs: build_wheels
74+
strategy:
75+
matrix:
76+
os: [ubuntu-latest]
77+
container: ['manylinux2014_i686', 'manylinux2014_x86_64']
78+
python-version: ['cp39-cp39', 'cp310-cp310', 'cp311-cp311', 'cp312-cp312', 'cp313-cp313']
79+
name: Test CPython ${{ matrix.python-version }}-${{ matrix.container }}
80+
steps:
81+
- name: Download a previously created wheel
82+
uses: actions/download-artifact@v4
83+
with:
84+
name: ${{ matrix.os }}-wheel
85+
- name: Test wheel
86+
run: |
87+
docker run --rm --volume `pwd`:/python quay.io/pypa/${{ matrix.container }} /bin/bash -c "/opt/python/${{ matrix.python-version }}/bin/python -m pip install -U pip && /opt/python/${{ matrix.python-version }}/bin/python -m pip install --find-links=/python/ --no-index python_bsonjs && /opt/python/${{ matrix.python-version }}/bin/python -m pip list | grep python-bsonjs && /opt/python/${{ matrix.python-version }}/bin/python -c 'from bsonjs import dumps'"
88+
make_sdist:
89+
name: Make SDist
90+
runs-on: ubuntu-latest
91+
steps:
92+
- uses: actions/checkout@v4
93+
- name: Setup Python
94+
uses: actions/setup-python@v5
95+
with:
96+
python-version: 3.9
97+
- name: Build SDist
98+
run: |
99+
python -m pip install build
100+
python -m build --sdist
101+
- uses: actions/upload-artifact@v4
102+
with:
103+
name: "sdist"
104+
path: dist/*.tar.gz
105+
collect_dist:
106+
runs-on: ubuntu-latest
107+
needs: [build_wheels, make_sdist]
108+
name: Download Wheels
109+
steps:
110+
- name: Download all workflow run artifacts
111+
uses: actions/download-artifact@v4
112+
- name: Flatten directory
113+
working-directory: .
114+
run: |
115+
find . -mindepth 2 -type f -exec mv {} . \;
116+
find . -type d -empty -delete
117+
- uses: actions/upload-artifact@v4
118+
with:
119+
name: all-dist-${{ github.run_id }}
120+
path: "./*"
Lines changed: 86 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,70 @@
1-
name: Python Wheels
1+
name: Release
22

33
on:
4-
push:
5-
tags:
6-
- "[0-9]+.[0-9]+.[0-9]+"
7-
- "[0-9]+.[0-9]+.[0-9]+.post[0-9]+"
8-
- "[0-9]+.[0-9]+.[0-9]+[a-b][0-9]+"
9-
- "[0-9]+.[0-9]+.[0-9]+rc[0-9]+"
10-
pull_request:
114
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 || '' }}
1223

1324
concurrency:
1425
group: wheels-${{ github.ref }}
1526
cancel-in-progress: true
1627

28+
defaults:
29+
run:
30+
shell: bash -eux {0}
31+
1732
jobs:
18-
build_wheels:
19-
runs-on: ${{ matrix.os }}
20-
strategy:
21-
matrix:
22-
os: [macos-latest, windows-latest, ubuntu-latest]
23-
name: Build CPython ${{ matrix.python-version }}-${{ matrix.os }}
24-
steps:
25-
- uses: actions/checkout@v4
26-
- uses: pypa/cibuildwheel@v2.23.2
27-
env:
28-
CIBW_ARCHS_MACOS: x86_64 universal2
29-
CIBW_TEST_SKIP: '*universal2:arm64'
30-
CIBW_BUILD: "cp39-macosx_universal2 cp39-win* cp39-manylinux_{x86_64,i686}"
31-
- uses: actions/upload-artifact@v4
32-
with:
33-
name: ${{ matrix.os }}-wheel
34-
path: ./wheelhouse/*.whl
35-
if-no-files-found: error
36-
test_non_linux_wheels:
37-
needs: build_wheels
38-
runs-on: ${{ matrix.os }}
39-
strategy:
40-
matrix:
41-
os: [macos-latest, windows-latest]
42-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
43-
name: Test CPython ${{ matrix.python-version }}-${{ matrix.os }}
44-
steps:
45-
- name: Setup Python
46-
uses: actions/setup-python@v5
47-
with:
48-
python-version: ${{ matrix.python-version }}
49-
allow-prereleases: true
50-
- name: Download a previously created wheel
51-
uses: actions/download-artifact@v4
52-
with:
53-
name: ${{ matrix.os }}-wheel
54-
- name: Test wheel
55-
shell: bash
56-
run: |
57-
python -m pip install -U pip
58-
python -m pip install --no-index --find-links=./ python_bsonjs
59-
python -m pip list | grep python-bsonjs
60-
python -c "from bsonjs import dumps"
61-
# Linux
62-
test_manylinux_wheels:
63-
runs-on: ${{ matrix.os }}
64-
needs: build_wheels
65-
strategy:
66-
matrix:
67-
os: [ubuntu-latest]
68-
container: ['manylinux2014_i686', 'manylinux2014_x86_64']
69-
python-version: ['cp39-cp39', 'cp310-cp310', 'cp311-cp311', 'cp312-cp312', 'cp313-cp313']
70-
name: Test CPython ${{ matrix.python-version }}-${{ matrix.container }}
71-
steps:
72-
- name: Download a previously created wheel
73-
uses: actions/download-artifact@v4
74-
with:
75-
name: ${{ matrix.os }}-wheel
76-
- name: Test wheel
77-
run: |
78-
docker run --rm --volume `pwd`:/python quay.io/pypa/${{ matrix.container }} /bin/bash -c "/opt/python/${{ matrix.python-version }}/bin/python -m pip install -U pip && /opt/python/${{ matrix.python-version }}/bin/python -m pip install --find-links=/python/ --no-index python_bsonjs && /opt/python/${{ matrix.python-version }}/bin/python -m pip list | grep python-bsonjs && /opt/python/${{ matrix.python-version }}/bin/python -c 'from bsonjs import dumps'"
79-
make_sdist:
80-
name: Make SDist
33+
pre-publish:
34+
environment: release
8135
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 }}
8242
steps:
83-
- uses: actions/checkout@v4
84-
- name: Setup Python
85-
uses: actions/setup-python@v5
43+
- uses: mongodb-labs/drivers-github-tools/secure-checkout@v2
8644
with:
87-
python-version: 3.9
88-
- name: Build SDist
89-
run: |
90-
python -m pip install build
91-
python -m build --sdist
92-
- uses: actions/upload-artifact@v4
45+
app_id: ${{ vars.APP_ID }}
46+
private_key: ${{ secrets.APP_PRIVATE_KEY }}
47+
- uses: mongodb-labs/drivers-github-tools/setup@v2
9348
with:
94-
name: "sdist"
95-
path: dist/*.tar.gz
96-
collect_dist:
97-
runs-on: ubuntu-latest
98-
needs: [build_wheels, make_sdist]
99-
name: Download Wheels
100-
steps:
101-
- name: Download all workflow run artifacts
102-
uses: actions/download-artifact@v4
103-
- name: Flatten directory
104-
working-directory: .
105-
run: |
106-
find . -mindepth 2 -type f -exec mv {} . \;
107-
find . -type d -empty -delete
108-
- uses: actions/upload-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
10955
with:
110-
name: all-dist-${{ github.run_id }}
111-
path: "./*"
56+
dry_run: ${{ env.DRY_RUN }}
57+
58+
build-dist:
59+
needs: [pre-publish]
60+
uses: ./.github/workflows/dist.yml
61+
with:
62+
ref: ${{ needs.pre-publish.outputs.version }}
63+
11264
publish:
11365
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/#publishing-the-distribution-to-pypi
114-
needs: [collect_dist]
115-
if: startsWith(github.ref, 'refs/tags/')
66+
needs: [build-dist]
67+
if: (github.repository_owner == 'mongodb-labs' && github.event_name != 'pull_request') || github.event_name == 'workflow_dispatch'
11668
runs-on: ubuntu-latest
11769
environment: release
11870
permissions:
@@ -123,5 +75,39 @@ jobs:
12375
with:
12476
name: all-dist-${{ github.run_id }}
12577
path: dist/
78+
- name: Publish package distributions to TestPyPI
79+
uses: pypa/gh-action-pypi-publish@release/v1
80+
with:
81+
repository-url: https://test.pypi.org/legacy/
82+
skip-existing: true
83+
attestations: ${{ !startsWith(github.ref, 'refs/tags/') }}
12684
- name: Publish distribution 📦 to PyPI
127-
uses: pypa/gh-action-pypi-publish@release/v1
85+
if: startsWith(github.ref, 'refs/tags/')
86+
uses: pypa/gh-action-pypi-publish@release/v1
87+
88+
post-publish:
89+
needs: [publish]
90+
runs-on: ubuntu-latest
91+
environment: release
92+
permissions:
93+
id-token: write
94+
contents: write
95+
attestations: write
96+
security-events: write
97+
steps:
98+
- uses: mongodb-labs/drivers-github-tools/secure-checkout@v2
99+
with:
100+
app_id: ${{ vars.APP_ID }}
101+
private_key: ${{ secrets.APP_PRIVATE_KEY }}
102+
- uses: mongodb-labs/drivers-github-tools/setup@v2
103+
with:
104+
aws_role_arn: ${{ secrets.AWS_ROLE_ARN }}
105+
aws_region_name: ${{ vars.AWS_REGION_NAME }}
106+
aws_secret_id: ${{ secrets.AWS_SECRET_ID }}
107+
artifactory_username: ${{ vars.ARTIFACTORY_USERNAME }}
108+
- uses: mongodb-labs/drivers-github-tools/python-labs/post-publish@v2
109+
with:
110+
following_version: ${{ env.FOLLOWING_VERSION }}
111+
product_name: ${{ env.PRODUCT_NAME }}
112+
token: ${{ github.token }}
113+
dry_run: ${{ env.DRY_RUN }}

0 commit comments

Comments
 (0)