Skip to content

Commit dcdaa4d

Browse files
authored
PYTHON-5591 Add automated release workflows (#324)
1 parent 408ed6b commit dcdaa4d

File tree

5 files changed

+200
-35
lines changed

5 files changed

+200
-35
lines changed

.github/dependabot.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: 2
2+
updates:
3+
# GitHub Actions
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
interval: "weekly"
8+
cooldown:
9+
default-days: 7
10+
groups:
11+
actions:
12+
patterns:
13+
- "*"
14+
# Python
15+
- package-ecosystem: "pip"
16+
directory: "/"
17+
schedule:
18+
interval: "weekly"
19+
cooldown:
20+
default-days: 7

.github/workflows/dist-python.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
make_dist:
28+
name: Make Dist
29+
runs-on: macos-latest
30+
permissions:
31+
contents: write
32+
steps:
33+
- uses: actions/checkout@v4
34+
with:
35+
persist-credentials: false
36+
37+
- uses: actions/setup-python@v5
38+
with:
39+
# Build sdist on lowest supported Python
40+
python-version: '3.9'
41+
42+
- name: Install python requirements
43+
run: |
44+
python -m pip install uv rust-just build twine
45+
46+
- name: Build Dist
47+
run: |
48+
python -m build .
49+
50+
- name: Test SDist
51+
run: |
52+
python -m twine check --strict dist/*.*
53+
python -m pip install dist/*.gz
54+
cd ..
55+
python -c "from mongo_orchestration import ReplicaSets"
56+
57+
- uses: actions/upload-artifact@v4
58+
with:
59+
name: "dist"
60+
path: ./dist/*.*
61+
62+
collect_dist:
63+
runs-on: ubuntu-latest
64+
needs: [make_dist]
65+
name: Download Dist
66+
permissions:
67+
contents: read
68+
steps:
69+
- name: Download all workflow run artifacts
70+
uses: actions/download-artifact@v4
71+
- name: Flatten directory
72+
working-directory: .
73+
run: |
74+
find . -mindepth 2 -type f -exec mv {} . \;
75+
find . -type d -empty -delete
76+
- uses: actions/upload-artifact@v4
77+
with:
78+
name: all-dist-${{ github.run_id }}
79+
path: "./*"
Lines changed: 80 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,109 @@
1-
name: Python Wheels
1+
name: Release
22

33
on:
4-
push:
5-
branches: ["master"]
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: Mongo-Orchestration
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:
12-
group: wheels-${{ github.ref }}
25+
group: release-${{ github.ref }}
1326
cancel-in-progress: true
1427

1528
defaults:
1629
run:
1730
shell: bash -eux {0}
1831

1932
jobs:
20-
21-
build_dist:
22-
name: Build Distribution Files
33+
pre-publish:
34+
environment: release
2335
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 }}
2442
steps:
25-
- uses: actions/checkout@v4
43+
- uses: mongodb-labs/drivers-github-tools/secure-checkout@v2
2644
with:
27-
fetch-depth: 0
28-
persist-credentials: false
29-
30-
- 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
3148
with:
32-
# Build sdist on lowest supported Python
33-
python-version: '3.9'
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
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
4555
with:
46-
name: dist-${{ github.run_id }}
47-
path: ./dist/*.*
56+
dry_run: ${{ env.DRY_RUN }}
57+
58+
build-dist:
59+
needs: [pre-publish]
60+
uses: ./.github/workflows/dist-python.yml
61+
permissions:
62+
contents: write
63+
with:
64+
ref: ${{ needs.pre-publish.outputs.version }}
4865

4966
publish:
5067
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/#publishing-the-distribution-to-pypi
51-
needs: [build_dist]
52-
if: startsWith(github.ref, 'refs/tags/')
68+
needs: [build-dist]
69+
if: (github.repository_owner == 'mongodb-labs' && github.event_name != 'pull_request') || github.event_name == 'workflow_dispatch'
5370
runs-on: ubuntu-latest
5471
environment: release
5572
permissions:
5673
id-token: write
5774
steps:
58-
- name: Download the dists
75+
- name: Download all the dists
5976
uses: actions/download-artifact@v4
6077
with:
61-
name: dist-${{ github.run_id }}
78+
name: all-dist-${{ github.run_id }}
6279
path: dist/
6380
- name: Publish distribution 📦 to PyPI
64-
uses: pypa/gh-action-pypi-publish@release/v1
81+
if: startsWith(env.DRY_RUN, 'false')
82+
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # release/v1
83+
84+
post-publish:
85+
needs: [publish]
86+
runs-on: ubuntu-latest
87+
environment: release
88+
permissions:
89+
id-token: write
90+
contents: write
91+
attestations: write
92+
security-events: write
93+
steps:
94+
- uses: mongodb-labs/drivers-github-tools/secure-checkout@v2
95+
with:
96+
app_id: ${{ vars.APP_ID }}
97+
private_key: ${{ secrets.APP_PRIVATE_KEY }}
98+
- uses: mongodb-labs/drivers-github-tools/setup@v2
99+
with:
100+
aws_role_arn: ${{ secrets.AWS_ROLE_ARN }}
101+
aws_region_name: ${{ vars.AWS_REGION_NAME }}
102+
aws_secret_id: ${{ secrets.AWS_SECRET_ID }}
103+
artifactory_username: ${{ vars.ARTIFACTORY_USERNAME }}
104+
- uses: mongodb-labs/drivers-github-tools/python-labs/post-publish@v2
105+
with:
106+
following_version: ${{ env.FOLLOWING_VERSION }}
107+
product_name: ${{ env.PRODUCT_NAME }}
108+
token: ${{ github.token }}
109+
dry_run: ${{ env.DRY_RUN }}
File renamed without changes.

.github/workflows/zizmor.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: GitHub Actions Security Analysis with zizmor 🌈
2+
3+
on:
4+
push:
5+
branches: ["master"]
6+
pull_request:
7+
branches: ["**"]
8+
9+
jobs:
10+
zizmor:
11+
name: zizmor latest via Cargo
12+
runs-on: ubuntu-latest
13+
permissions:
14+
security-events: write
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
with:
19+
persist-credentials: false
20+
- name: Run zizmor 🌈
21+
uses: zizmorcore/zizmor-action@87e33752ad17c7c7fc16fe27c858900c59b18d77

0 commit comments

Comments
 (0)