Skip to content

Commit 5b82303

Browse files
authored
INTPYTHON-406 Add automated release workflows for Django-MongoDB (#186)
INTPYTHON-406 Add automated release workflows for Django-MongoDB
1 parent ba4c521 commit 5b82303

File tree

6 files changed

+219
-9
lines changed

6 files changed

+219
-9
lines changed

.github/dependabot.yml

+5
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ updates:
99
actions:
1010
patterns:
1111
- "*"
12+
# Python
13+
- package-ecosystem: "pip"
14+
directory: "/"
15+
schedule:
16+
interval: "weekly"

.github/workflows/codeql.yml

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: [ "main", "*" ]
17+
pull_request:
18+
branches: [ "main", "*" ]
19+
schedule:
20+
- cron: '35 23 * * 5'
21+
workflow_call:
22+
inputs:
23+
ref:
24+
required: true
25+
type: string
26+
27+
jobs:
28+
analyze:
29+
name: Analyze
30+
runs-on: ubuntu-latest
31+
timeout-minutes: 360
32+
permissions:
33+
# required for all workflows
34+
security-events: write
35+
# required to fetch internal or private CodeQL packs
36+
packages: read
37+
actions: read
38+
contents: read
39+
40+
steps:
41+
- name: Checkout repository
42+
uses: actions/checkout@v4
43+
with:
44+
ref: ${{ inputs.ref }}
45+
- name: Set up Python
46+
uses: actions/setup-python@v4
47+
with:
48+
python-version: 3.x
49+
50+
# Initializes the CodeQL tools for scanning.
51+
- name: Initialize CodeQL
52+
uses: github/codeql-action/init@v3
53+
with:
54+
languages: python
55+
build-mode: none
56+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
57+
queries: security-extended
58+
config: |
59+
paths-ignore:
60+
- '.github/**'
61+
- 'tests/**'
62+
63+
- shell: bash
64+
run: |
65+
pip install -e .
66+
67+
- name: Perform CodeQL Analysis
68+
uses: github/codeql-action/analyze@v3
69+
with:
70+
category: "/language:python"

.github/workflows/dist.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Python Dist
2+
3+
on:
4+
workflow_dispatch:
5+
workflow_call:
6+
inputs:
7+
ref:
8+
required: true
9+
type: string
10+
push:
11+
tags:
12+
- "[0-9]+.[0-9]+.[0-9]+"
13+
- "[0-9]+.[0-9]+.[0-9]+.post[0-9]+"
14+
- "[0-9]+.[0-9]+.[0-9]+[a-b][0-9]+"
15+
- "[0-9]+.[0-9]+.[0-9]+rc[0-9]+"
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
environment: release
21+
steps:
22+
- uses: actions/checkout@v4
23+
with:
24+
ref: ${{ inputs.ref }}
25+
- name: Set up Python
26+
uses: actions/setup-python@v4
27+
with:
28+
python-version: 3.x
29+
- name: Install dependencies
30+
run: pip install build
31+
- name: Create packages
32+
run: python -m build .
33+
- name: Store package artifacts
34+
uses: actions/upload-artifact@v4
35+
with:
36+
name: all-dist-${{ github.run_id }}
37+
path: "dist/*"

.github/workflows/release-python.yml

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: "The new version to set"
8+
required: true
9+
following_version:
10+
description: "The post (dev) version to set"
11+
required: false
12+
dry_run:
13+
description: "Dry Run?"
14+
default: false
15+
type: boolean
16+
17+
env:
18+
# Changes per repo
19+
PRODUCT_NAME: django-mongodb
20+
# Changes per branch
21+
SILK_ASSET_GROUP: django-mongodb-main
22+
EVERGREEN_PROJECT: django-mongodb
23+
24+
defaults:
25+
run:
26+
shell: bash -eux {0}
27+
28+
jobs:
29+
pre-publish:
30+
environment: release
31+
runs-on: ubuntu-latest
32+
permissions:
33+
id-token: write
34+
contents: write
35+
outputs:
36+
version: ${{ steps.pre-publish.outputs.version }}
37+
steps:
38+
- uses: mongodb-labs/drivers-github-tools/secure-checkout@v2
39+
with:
40+
app_id: ${{ vars.APP_ID }}
41+
private_key: ${{ secrets.APP_PRIVATE_KEY }}
42+
- uses: mongodb-labs/drivers-github-tools/setup@v2
43+
with:
44+
aws_role_arn: ${{ secrets.AWS_ROLE_ARN }}
45+
aws_region_name: ${{ vars.AWS_REGION_NAME }}
46+
aws_secret_id: ${{ secrets.AWS_SECRET_ID }}
47+
artifactory_username: ${{ vars.ARTIFACTORY_USERNAME }}
48+
- uses: mongodb-labs/drivers-github-tools/python/pre-publish@v2
49+
id: pre-publish
50+
with:
51+
version: ${{ inputs.version }}
52+
dry_run: ${{ inputs.dry_run }}
53+
54+
build-dist:
55+
needs: [pre-publish]
56+
uses: ./.github/workflows/dist.yml
57+
with:
58+
ref: ${{ needs.pre-publish.outputs.version }}
59+
60+
static-scan:
61+
needs: [pre-publish]
62+
uses: ./.github/workflows/codeql.yml
63+
with:
64+
ref: ${{ needs.pre-publish.outputs.version }}
65+
66+
publish:
67+
needs: [build-dist, static-scan]
68+
runs-on: ubuntu-latest
69+
environment: release
70+
permissions:
71+
id-token: write
72+
contents: write
73+
attestations: write
74+
security-events: write
75+
steps:
76+
- uses: mongodb-labs/drivers-github-tools/secure-checkout@v2
77+
with:
78+
app_id: ${{ vars.APP_ID }}
79+
private_key: ${{ secrets.APP_PRIVATE_KEY }}
80+
- uses: mongodb-labs/drivers-github-tools/setup@v2
81+
with:
82+
aws_role_arn: ${{ secrets.AWS_ROLE_ARN }}
83+
aws_region_name: ${{ vars.AWS_REGION_NAME }}
84+
aws_secret_id: ${{ secrets.AWS_SECRET_ID }}
85+
artifactory_username: ${{ vars.ARTIFACTORY_USERNAME }}
86+
- uses: mongodb-labs/drivers-github-tools/python/publish@v2
87+
with:
88+
version: ${{ inputs.version }}
89+
following_version: ${{ inputs.following_version }}
90+
product_name: ${{ env.PRODUCT_NAME }}
91+
silk_asset_group: ${{ env.SILK_ASSET_GROUP }}
92+
evergreen_project: ${{ env.EVERGREEN_PROJECT }}
93+
token: ${{ github.token }}
94+
repository_url: https://test.pypi.org/legacy/
95+
dry_run: ${{ inputs.dry_run }}

pyproject.toml

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[build-system]
2-
requires = ["setuptools>=65.0"]
3-
build-backend = "setuptools.build_meta"
2+
requires = ["hatchling", "hatch-requirements-txt>=0.4.1"]
3+
build-backend = "hatchling.build"
44

55
[project]
66
name = "django-mongodb"
7-
dynamic = ["version"]
7+
dynamic = ["version", "dependencies"]
88
description = "MongoDB backend for Django"
99
readme = "README.md"
1010
license = {file="LICENSE"}
@@ -31,10 +31,6 @@ classifiers = [
3131
"Programming Language :: Python :: 3.11",
3232
"Programming Language :: Python :: 3.12",
3333
]
34-
dependencies = [
35-
"django>=5.0,<5.1",
36-
"pymongo>=4.6,<5.0",
37-
]
3834

3935
[project.optional-dependencies]
4036
docs = [ "sphinx>=7"]
@@ -45,8 +41,12 @@ Documentation = "https://django-mongodb.readthedocs.io"
4541
Source = "https://github.com/mongodb-labs/django-mongodb"
4642
Tracker = "https://github.com/mongodb-labs/django-mongodb/issues"
4743

48-
[tool.setuptools.dynamic]
49-
version = {attr = "django_mongodb.__version__"}
44+
[tool.hatch.version]
45+
path = "django_mongodb/__init__.py"
46+
validate-bump = false
47+
48+
[tool.hatch.metadata.hooks.requirements_txt]
49+
files = ["requirements.txt"]
5050

5151
[tool.mypy]
5252
strict = true

requirements.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# NOTE: this needs to change per branch to track the django version.
2+
django>=5.0,<5.1
3+
pymongo>=4.6,<5.0

0 commit comments

Comments
 (0)