Skip to content

INTPYTHON-615 Set up GitHub workflows for automated releases #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ "master", "*" ]
pull_request:
branches: [ "master", "*" ]
schedule:
- cron: '35 23 * * 5'
workflow_call:
inputs:
ref:
required: true
type: string

jobs:
analyze:
name: Analyze ${{ matrix.language }}
runs-on: ubuntu-latest
timeout-minutes: 360
permissions:
# required for all workflows
security-events: write
# required to fetch internal or private CodeQL packs
packages: read
actions: read
contents: read
strategy:
fail-fast: false
matrix:
include:
- language: python
- language: actions

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@28deaeda66b76a05916b6923827895f2b14ab387 # v3
with:
languages: ${{ matrix.language }}
build-mode: none
# 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
queries: security-extended
config: |
paths-ignore:
- 'test/**'

- shell: bash
if: matrix.language == 'python'
run: |
pip install -e .

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@28deaeda66b76a05916b6923827895f2b14ab387 # v3
with:
category: "/language:${{ matrix.language }}"
78 changes: 78 additions & 0 deletions .github/workflows/dist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Python Dist

on:
push:
tags:
- "[0-9]+.[0-9]+.[0-9]+"
- "[0-9]+.[0-9]+.[0-9]+.post[0-9]+"
- "[0-9]+.[0-9]+.[0-9]+[a-b][0-9]+"
- "[0-9]+.[0-9]+.[0-9]+rc[0-9]+"
workflow_dispatch:
pull_request:
workflow_call:
inputs:
ref:
required: true
type: string

permissions:
contents: read
actions: read

concurrency:
group: dist-${{ github.ref }}
cancel-in-progress: true

defaults:
run:
shell: bash -eux {0}

jobs:
make_dist:
name: Make Dist
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false

- uses: actions/setup-python@v5
with:
# Build sdist on lowest supported Python
python-version: '3.10'

- name: Install python requirements
run: |
python -m pip install uv rust-just build

- name: Build Dist
run: |
python -m build .

- name: Test SDist
run: |
python -m pip install dist/*.gz
cd ..
python -c "from pymongo_voyageai import PyMongoVoyageAI"

- uses: actions/upload-artifact@v4
with:
name: "dist"
path: ./dist/*.*

collect_dist:
runs-on: ubuntu-latest
needs: [make_dist]
name: Download Dist
steps:
- name: Download all workflow run artifacts
uses: actions/download-artifact@v4
- name: Flatten directory
working-directory: .
run: |
find . -mindepth 2 -type f -exec mv {} . \;
find . -type d -empty -delete
- uses: actions/upload-artifact@v4
with:
name: all-dist-${{ github.run_id }}
path: "./*"
158 changes: 91 additions & 67 deletions .github/workflows/release-python.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
name: Python Wheels
name: Release

on:
push:
branches: ["main"]
tags:
- "**"
pull_request:
workflow_dispatch:
inputs:
following_version:
description: "The post (dev) version to set"
dry_run:
description: "Dry Run?"
default: false
type: boolean
schedule:
- cron: '30 5 * * *'

env:
# Changes per repo
PRODUCT_NAME: python-bsonjs
# Constant
# inputs will be empty on a scheduled run. so, we only set dry_run
# to 'false' when the input is set to 'false'.
DRY_RUN: ${{ ! contains(inputs.dry_run, 'false') }}
FOLLOWING_VERSION: ${{ inputs.following_version || '' }}

concurrency:
group: wheels-${{ github.ref }}
Expand All @@ -17,83 +30,94 @@ defaults:
shell: bash -eux {0}

jobs:

build_dist:
name: Build Distribution Files
pre-publish:
environment: release
runs-on: ubuntu-latest
if: github.repository_owner == 'mongodb-labs' || github.event_name == 'workflow_dispatch'
permissions:
id-token: write
contents: write
outputs:
version: ${{ steps.pre-publish.outputs.version }}
steps:
- uses: actions/checkout@v4
- uses: mongodb-labs/drivers-github-tools/secure-checkout@v2
with:
fetch-depth: 0
persist-credentials: false

- uses: actions/setup-python@v5
app_id: ${{ vars.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: mongodb-labs/drivers-github-tools/setup@v2
with:
# Build sdist on lowest supported Python
python-version: '3.10'

- name: Install build
run: |
python -m pip install build

- name: build the dist files
run: |
python -m build .

- name: Upload the dist files
uses: actions/upload-artifact@v4
with:
name: dist-${{ github.run_id }}
path: ./dist/*.*

test_dist:
needs: [build_dist]
name: Test Distribution Files
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false

- uses: actions/setup-python@v5
aws_role_arn: ${{ secrets.AWS_ROLE_ARN }}
aws_region_name: ${{ vars.AWS_REGION_NAME }}
aws_secret_id: ${{ secrets.AWS_SECRET_ID }}
artifactory_username: ${{ vars.ARTIFACTORY_USERNAME }}
- uses: mongodb-labs/drivers-github-tools/python-labs/pre-publish@v2
id: pre-publish
with:
# Build sdist on lowest supported Python
python-version: '3.10'
dry_run: ${{ env.DRY_RUN }}

- name: Download the dists
uses: actions/download-artifact@v4
with:
name: dist-${{ github.run_id }}
path: dist/

- name: Test the sdist
run: |
cd dist
pip install *.tar.gz
python -c "import pymongo_voyageai"
pip uninstall -y pymongo_voyageai
build-dist:
needs: [pre-publish]
uses: ./.github/workflows/dist.yml
permissions:
contents: read
with:
ref: ${{ needs.pre-publish.outputs.version }}

- name: Test the wheel
run: |
cd dist
pip install *.whl
python -c "import pymongo_voyageai"
pip uninstall -y pymongo_voyageai
static-scan:
needs: [pre-publish]
uses: ./.github/workflows/codeql.yml
permissions:
contents: read
with:
ref: ${{ needs.pre-publish.outputs.version }}

publish:
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/#publishing-the-distribution-to-pypi
needs: [test_dist]
if: startsWith(github.ref, 'refs/tags/')
needs: [build-dist, static-scan]
if: (github.repository_owner == 'mongodb-labs' && github.event_name != 'pull_request') || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write
steps:
- name: Download the dists
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: dist-${{ github.run_id }}
name: all-dist-${{ github.run_id }}
path: dist/
- name: Publish package distributions to TestPyPI
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # release/v1
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true
attestations: ${{ env.DRY_RUN }}
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
if: startsWith(env.DRY_RUN, 'false')
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # release/v1

post-publish:
needs: [publish]
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write
contents: write
attestations: write
security-events: write
steps:
- uses: mongodb-labs/drivers-github-tools/secure-checkout@v2
with:
app_id: ${{ vars.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: mongodb-labs/drivers-github-tools/setup@v2
with:
aws_role_arn: ${{ secrets.AWS_ROLE_ARN }}
aws_region_name: ${{ vars.AWS_REGION_NAME }}
aws_secret_id: ${{ secrets.AWS_SECRET_ID }}
artifactory_username: ${{ vars.ARTIFACTORY_USERNAME }}
- uses: mongodb-labs/drivers-github-tools/python-labs/post-publish@v2
with:
following_version: ${{ env.FOLLOWING_VERSION }}
product_name: ${{ env.PRODUCT_NAME }}
token: ${{ github.token }}
dry_run: ${{ env.DRY_RUN }}
Loading