1- name : Python Wheels
1+ name : Release
22
33on :
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
1324concurrency :
1425 group : wheels-${{ github.ref }}
1526 cancel-in-progress : true
1627
28+ defaults :
29+ run :
30+ shell : bash -eux {0}
31+
1732jobs :
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