Skip to content

Commit

Permalink
add release workflows (#705)
Browse files Browse the repository at this point in the history
  • Loading branch information
vbarda authored Jun 19, 2024
1 parent 755495a commit c1cf269
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 21 deletions.
18 changes: 13 additions & 5 deletions .github/workflows/_test_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ name: test-release

on:
workflow_call:
inputs:
working-directory:
required: true
type: string
description: "From which folder this pipeline executes"

env:
POETRY_VERSION: "1.7.1"
Expand All @@ -24,6 +29,7 @@ jobs:
with:
python-version: ${{ env.PYTHON_VERSION }}
poetry-version: ${{ env.POETRY_VERSION }}
working-directory: ${{ inputs.working-directory }}
cache-key: release

# We want to keep this build stage *separate* from the release stage,
Expand All @@ -39,16 +45,18 @@ jobs:
# https://github.com/pypa/gh-action-pypi-publish#non-goals
- name: Build project for distribution
run: poetry build
working-directory: ${{ inputs.working-directory }}

- name: Upload build
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: test-dist
path: ./langgraph/dist/
path: ${{ inputs.working-directory }}/dist/

- name: Check Version
id: check-version
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |
echo pkg-name="$(poetry version | cut -d ' ' -f 1)" >> $GITHUB_OUTPUT
echo version="$(poetry version --short)" >> $GITHUB_OUTPUT
Expand All @@ -68,15 +76,15 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: test-dist
path: ./langgraph/dist/
path: ${{ inputs.working-directory }}/dist/

- name: Publish to test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: ./langgraph/dist/
packages-dir: ${{ inputs.working-directory }}/dist/
verbose: true
print-hash: true
repository-url: https://test.pypi.org/legacy/
Expand Down
115 changes: 99 additions & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
name: release
run-name: Release by @${{ github.actor }}
run-name: Release ${{ inputs.working-directory }} by @${{ github.actor }}
on:
workflow_dispatch
workflow_dispatch:
inputs:
working-directory:
required: true
type: string
default: 'libs/langgraph'

env:
PYTHON_VERSION: "3.10"
PYTHON_VERSION: "3.11"
POETRY_VERSION: "1.7.1"

jobs:
Expand All @@ -24,6 +29,7 @@ jobs:
with:
python-version: ${{ env.PYTHON_VERSION }}
poetry-version: ${{ env.POETRY_VERSION }}
working-directory: ${{ inputs.working-directory }}
cache-key: release

# We want to keep this build stage *separate* from the release stage,
Expand All @@ -39,30 +45,90 @@ jobs:
# https://github.com/pypa/gh-action-pypi-publish#non-goals
- name: Build project for distribution
run: poetry build
working-directory: ${{ inputs.working-directory }}

- name: Upload build
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: dist
path: ./dist/
path: ${{ inputs.working-directory }}/dist/

- name: Check Version
id: check-version
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |
echo pkg-name="$(poetry version | cut -d ' ' -f 1)" >> $GITHUB_OUTPUT
echo version="$(poetry version --short)" >> $GITHUB_OUTPUT
release-notes:
needs:
- build
runs-on: ubuntu-latest
outputs:
release-body: ${{ steps.generate-release-body.outputs.release-body }}
steps:
- uses: actions/checkout@v4
with:
repository: langchain-ai/langchain
path: langchain
sparse-checkout: | # this only grabs files for relevant dir
${{ inputs.working-directory }}
ref: master # this scopes to just master branch
fetch-depth: 0 # this fetches entire commit history
- name: Check Tags
id: check-tags
shell: bash
working-directory: langchain/${{ inputs.working-directory }}
env:
PKG_NAME: ${{ needs.build.outputs.pkg-name }}
VERSION: ${{ needs.build.outputs.version }}
run: |
REGEX="^$PKG_NAME==\\d+\\.\\d+\\.\\d+\$"
echo $REGEX
PREV_TAG=$(git tag --sort=-creatordate | grep -P $REGEX || true | head -1)
TAG="${PKG_NAME}==${VERSION}"
if [ "$TAG" == "$PREV_TAG" ]; then
echo "No new version to release"
exit 1
fi
echo tag="$TAG" >> $GITHUB_OUTPUT
echo prev-tag="$PREV_TAG" >> $GITHUB_OUTPUT
- name: Generate release body
id: generate-release-body
working-directory: langchain
env:
WORKING_DIR: ${{ inputs.working-directory }}
PKG_NAME: ${{ needs.build.outputs.pkg-name }}
TAG: ${{ steps.check-tags.outputs.tag }}
PREV_TAG: ${{ steps.check-tags.outputs.prev-tag }}
run: |
{
echo 'release-body<<EOF'
echo "# Release $TAG"
if [ -z "$PREV_TAG" ]; then
echo "Initial release"
else
echo "Changes since $PREV_TAG"
echo
git log --format="%s" "$PREV_TAG"..HEAD -- $WORKING_DIR
fi
echo EOF
} >> "$GITHUB_OUTPUT"
test-pypi-publish:
needs:
- build
- release-notes
uses:
./.github/workflows/_test_release.yml
with:
working-directory: ${{ inputs.working-directory }}
secrets: inherit

pre-release-checks:
needs:
- build
- release-notes
- test-pypi-publish
runs-on: ubuntu-latest
steps:
Expand All @@ -86,14 +152,16 @@ jobs:
with:
python-version: ${{ env.PYTHON_VERSION }}
poetry-version: ${{ env.POETRY_VERSION }}
working-directory: ${{ inputs.working-directory }}

- name: Import published package
shell: bash
working-directory: ${{ inputs.working-directory }}
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
# - 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.
Expand All @@ -120,9 +188,11 @@ jobs:
- name: Import test dependencies
run: poetry install --with dev
working-directory: ${{ inputs.working-directory }}

# Overwrite the local version of the package with the test PyPI version.
- name: Import published package (again)
working-directory: ${{ inputs.working-directory }}
shell: bash
env:
PKG_NAME: ${{ needs.build.outputs.pkg-name }}
Expand All @@ -134,10 +204,12 @@ jobs:
- name: Run unit tests
run: make test
working-directory: ${{ inputs.working-directory }}

publish:
needs:
- build
- release-notes
- test-pypi-publish
- pre-release-checks
runs-on: ubuntu-latest
Expand All @@ -149,6 +221,10 @@ jobs:
# https://docs.pypi.org/trusted-publishers/adding-a-publisher/
id-token: write

defaults:
run:
working-directory: ${{ inputs.working-directory }}

steps:
- uses: actions/checkout@v4

Expand All @@ -157,23 +233,25 @@ jobs:
with:
python-version: ${{ env.PYTHON_VERSION }}
poetry-version: ${{ env.POETRY_VERSION }}
working-directory: ${{ inputs.working-directory }}
cache-key: release

- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: dist
path: ./dist/
path: ${{ inputs.working-directory }}/dist/

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: ./dist/
packages-dir: ${{ inputs.working-directory }}/dist/
verbose: true
print-hash: true

mark-release:
needs:
- build
- release-notes
- test-pypi-publish
- pre-release-checks
- publish
Expand All @@ -183,6 +261,10 @@ jobs:
# create the GitHub release.
contents: write

defaults:
run:
working-directory: ${{ inputs.working-directory }}

steps:
- uses: actions/checkout@v4

Expand All @@ -191,19 +273,20 @@ jobs:
with:
python-version: ${{ env.PYTHON_VERSION }}
poetry-version: ${{ env.POETRY_VERSION }}
working-directory: ${{ inputs.working-directory }}
cache-key: release

- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: dist
path: ./dist/
path: ${{ inputs.working-directory }}/dist/

- name: Create Release
- name: Create Tag
uses: ncipollo/release-action@v1
with:
artifacts: "dist/*"
token: ${{ secrets.GITHUB_TOKEN }}
draft: false
generateReleaseNotes: true
tag: v${{ needs.build.outputs.version }}
commit: master
generateReleaseNotes: false
tag: ${{needs.build.outputs.pkg-name}}==${{ needs.build.outputs.version }}
body: ${{ needs.release-notes.outputs.release-body }}
commit: ${{ github.sha }}

0 comments on commit c1cf269

Please sign in to comment.