Skip to content

Release libs/langchain-mongodb by @blink1073 #38

Release libs/langchain-mongodb by @blink1073

Release libs/langchain-mongodb by @blink1073 #38

Workflow file for this run

name: release
run-name: Release ${{ inputs.working-directory }} by @${{ github.actor }}
on:
workflow_call:
inputs:
working-directory:
required: true
type: string
description: "From which folder this pipeline executes"
workflow_dispatch:
inputs:
working-directory:
required: true
type: choice
options:
- libs/langchain-mongodb
- libs/langgraph-checkpoint-mongodb
- libs/langgraph-store-mongodb
default: libs/langchain-mongodb
description: "From which folder this pipeline executes"
env:
PYTHON_VERSION: "3.11"
jobs:
build:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ inputs.working-directory }}
outputs:
pkg-name: ${{ steps.check-version.outputs.pkg-name }}
version: ${{ steps.check-version.outputs.version }}
steps:
- uses: actions/checkout@v5
with:
persist-credentials: false
- name: Install uv
uses: astral-sh/setup-uv@d9e0f98d3fc6adb07d1e3d37f3043649ddad06a1 # v5
with:
enable-cache: true
python-version: ${{ env.PYTHON_VERSION }}
cache-dependency-glob: "${{ inputs.working-directory }}/uv.lock"
# We want to keep this build stage *separate* from the release stage,
# so that there's no sharing of permissions between them.
# The release stage has trusted publishing and GitHub repo contents write access,
# and we want to keep the scope of that access limited just to the release job.
# Otherwise, a malicious `build` step (e.g. via a compromised dependency)
# could get access to our GitHub or PyPI credentials.
#
# Per the trusted publishing GitHub Action:
# > It is strongly advised to separate jobs for building [...]
# > from the publish job.
# https://github.com/pypa/gh-action-pypi-publish#non-goals
- name: Build project for distribution
run: uv build
- name: Upload build
uses: actions/upload-artifact@v4
with:
name: dist
path: ${{ inputs.working-directory }}/dist/
- name: Check Version
id: check-version
shell: bash
run: |
set -eu
echo pkg-name="$(uvx hatch project metadata | jq -r .name)" >> $GITHUB_OUTPUT
echo version="$(uvx hatch version)" >> $GITHUB_OUTPUT
test-pypi-publish:
needs:
- build
uses:
./.github/workflows/_test_release.yml
permissions: write-all
with:
working-directory: ${{ inputs.working-directory }}
secrets: inherit
pre-release-checks:
needs:
- build
- test-pypi-publish
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ inputs.working-directory }}
steps:
- uses: actions/checkout@v5
with:
persist-credentials: false
# We explicitly *don't* set up caching here. This ensures our tests are
# maximally sensitive to catching breakage.
#
# For example, here's a way that caching can cause a falsely-passing test:
# - Make the langchain package manifest no longer list a dependency package
# as a requirement. This means it won't be installed by `pip install`,
# and attempting to use it would cause a crash.
# - That dependency used to be required, so it may have been cached.
# When restoring the venv packages from cache, that dependency gets included.
# - Tests pass, because the dependency is present even though it wasn't specified.
# - The package is published, and it breaks on the missing dependency when
# used in the real world.
- name: Install uv
uses: astral-sh/setup-uv@d9e0f98d3fc6adb07d1e3d37f3043649ddad06a1 # v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Import published package
shell: bash
env:
PKG_NAME: ${{ needs.build.outputs.pkg-name }}
VERSION: ${{ needs.build.outputs.version }}
# Here we use:
# - The default regular PyPI index as the *primary* index, meaning
# that it takes priority (https://pypi.org/simple)
# - The test PyPI index as an extra index, so that any dependencies that
# are not found on test PyPI can be resolved and installed anyway.
# (https://test.pypi.org/simple). This will include the PKG_NAME==VERSION
# package because VERSION will not have been uploaded to regular PyPI yet.
# - attempt install again after 5 seconds if it fails because there is
# sometimes a delay in availability on test pypi
run: |
uv run pip install \
--extra-index-url https://test.pypi.org/simple/ \
"$PKG_NAME==$VERSION" || \
( \
sleep 5 && \
uv run pip install \
--extra-index-url https://test.pypi.org/simple/ \
"$PKG_NAME==$VERSION" \
)
# For langchain-mongodb, replace dashes in the package name with underscores.
IMPORT_NAME="${PKG_NAME//-/_}"
# If langgraph*, it's a namespace package => /-/.
[[ "$PKG_NAME" == langgraph* ]] && IMPORT_NAME="${PKG_NAME//-/.}"
uv run python -c "import $IMPORT_NAME; print(dir($IMPORT_NAME))"
- uses: extractions/setup-just@e33e0265a09d6d736e2ee1e0eb685ef1de4669ff # v3
- name: Import test dependencies
run: just install
# Overwrite the local version of the package with the test PyPI version.
- name: Import published package (again)
shell: bash
env:
PKG_NAME: ${{ needs.build.outputs.pkg-name }}
VERSION: ${{ needs.build.outputs.version }}
run: |
uv run pip install \
--extra-index-url https://test.pypi.org/simple/ \
"$PKG_NAME==$VERSION"
- name: Start local Atlas
working-directory: .
run: bash scripts/start_local_atlas.sh
- name: Run unit tests
run: just unit_tests
- name: Install Ollama
run: curl -fsSL https://ollama.com/install.sh | sh
- name: Run Ollama
working-directory: .
run: |
ollama serve &
sleep 5 # wait for the Ollama server to be ready
bash scripts/setup_ollama.sh
- name: Run integration tests
run: just integration_tests
- name: Run unit tests with minimum dependency versions
run: |
uv sync --python=${PYTHON_VERSION} --resolution=lowest-direct
just unit_tests
publish:
needs:
- build
- test-pypi-publish
- pre-release-checks
runs-on: ubuntu-latest
permissions:
# This permission is used for trusted publishing:
# https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/
#
# Trusted publishing has to also be configured on PyPI for each package:
# https://docs.pypi.org/trusted-publishers/adding-a-publisher/
id-token: write
defaults:
run:
working-directory: ${{ inputs.working-directory }}
steps:
- uses: actions/checkout@v5
with:
persist-credentials: false
- name: Install uv
uses: astral-sh/setup-uv@d9e0f98d3fc6adb07d1e3d37f3043649ddad06a1 # v5
with:
enable-cache: true
python-version: ${{ env.PYTHON_VERSION }}
cache-dependency-glob: "${{ inputs.working-directory }}/uv.lock"
- uses: actions/download-artifact@v5
with:
name: dist
path: ${{ inputs.working-directory }}/dist/
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # release/v1
with:
packages-dir: ${{ inputs.working-directory }}/dist/
verbose: true
print-hash: true
# Temp workaround since attestations are on by default as of gh-action-pypi-publish v1\.11\.0
attestations: false
mark-release:
needs:
- build
- test-pypi-publish
- pre-release-checks
- publish
runs-on: ubuntu-latest
permissions:
# This permission is needed by `ncipollo/release-action` to
# create the GitHub release.
contents: write
defaults:
run:
working-directory: ${{ inputs.working-directory }}
steps:
- uses: actions/checkout@v5
with:
persist-credentials: false
- name: Install uv
uses: astral-sh/setup-uv@d9e0f98d3fc6adb07d1e3d37f3043649ddad06a1 # v5
with:
enable-cache: true
python-version: ${{ env.PYTHON_VERSION }}
cache-dependency-glob: "${{ inputs.working-directory }}/uv.lock"
- uses: actions/download-artifact@v5
with:
name: dist
path: ${{ inputs.working-directory }}/dist/
- name: Create Release
uses: ncipollo/release-action@bcfe5470707e8832e12347755757cec0eb3c22af # v1
id: create-release
with:
artifacts: "${{ inputs.working-directory }}/dist/*"
token: ${{ secrets.GITHUB_TOKEN }}
draft: false
generateReleaseNotes: true
tag: ${{ inputs.working-directory }}/v${{ needs.build.outputs.version }}
commit: main
- name: Add github release url to summary
env:
RELEASE_URL: ${{ steps.create-release.outputs.html_url }}
run: |
echo "GitHub Release: ${RELEASE_URL}" >> $GITHUB_STEP_SUMMARY