-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
979 additions
and
392 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# An action for setting up poetry install with caching. | ||
# Using a custom action since the default action does not | ||
# take poetry install groups into account. | ||
# Action code from: | ||
# https://github.com/actions/setup-python/issues/505#issuecomment-1273013236 | ||
name: poetry-install-with-caching | ||
description: Poetry install with support for caching of dependency groups. | ||
|
||
inputs: | ||
python-version: | ||
description: Python version, supporting MAJOR.MINOR only | ||
required: true | ||
|
||
poetry-version: | ||
description: Poetry version | ||
required: true | ||
|
||
cache-key: | ||
description: Cache key to use for manual handling of caching | ||
required: true | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- uses: actions/setup-python@v5 | ||
name: Setup python ${{ inputs.python-version }} | ||
id: setup-python | ||
with: | ||
python-version: ${{ inputs.python-version }} | ||
|
||
- uses: actions/cache@v3 | ||
id: cache-bin-poetry | ||
name: Cache Poetry binary - Python ${{ inputs.python-version }} | ||
env: | ||
SEGMENT_DOWNLOAD_TIMEOUT_MIN: "1" | ||
with: | ||
path: | | ||
/opt/pipx/venvs/poetry | ||
# This step caches the poetry installation, so make sure it's keyed on the poetry version as well. | ||
key: bin-poetry-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}-${{ inputs.poetry-version }} | ||
|
||
- name: Refresh shell hashtable and fixup softlinks | ||
if: steps.cache-bin-poetry.outputs.cache-hit == 'true' | ||
shell: bash | ||
env: | ||
POETRY_VERSION: ${{ inputs.poetry-version }} | ||
PYTHON_VERSION: ${{ inputs.python-version }} | ||
run: | | ||
set -eux | ||
# Refresh the shell hashtable, to ensure correct `which` output. | ||
hash -r | ||
# `actions/cache@v3` doesn't always seem able to correctly unpack softlinks. | ||
# Delete and recreate the softlinks pipx expects to have. | ||
rm /opt/pipx/venvs/poetry/bin/python | ||
cd /opt/pipx/venvs/poetry/bin | ||
ln -s "$(which "python$PYTHON_VERSION")" python | ||
chmod +x python | ||
cd /opt/pipx_bin/ | ||
ln -s /opt/pipx/venvs/poetry/bin/poetry poetry | ||
chmod +x poetry | ||
# Ensure everything got set up correctly. | ||
/opt/pipx/venvs/poetry/bin/python --version | ||
/opt/pipx_bin/poetry --version | ||
- name: Install poetry | ||
if: steps.cache-bin-poetry.outputs.cache-hit != 'true' | ||
shell: bash | ||
env: | ||
POETRY_VERSION: ${{ inputs.poetry-version }} | ||
PYTHON_VERSION: ${{ inputs.python-version }} | ||
# Install poetry using the python version installed by setup-python step. | ||
run: pipx install "poetry==$POETRY_VERSION" --python '${{ steps.setup-python.outputs.python-path }}' --verbose | ||
|
||
- name: Restore pip and poetry cached dependencies | ||
uses: actions/cache@v3 | ||
env: | ||
SEGMENT_DOWNLOAD_TIMEOUT_MIN: "4" | ||
with: | ||
path: | | ||
~/.cache/pip | ||
~/.cache/pypoetry/virtualenvs | ||
~/.cache/pypoetry/cache | ||
~/.cache/pypoetry/artifacts | ||
./.venv | ||
key: py-deps-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}-poetry-${{ inputs.poetry-version }}-${{ inputs.cache-key }}-${{ hashFiles('./poetry.lock') }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
name: lint | ||
|
||
on: | ||
workflow_call | ||
|
||
env: | ||
POETRY_VERSION: "1.7.1" | ||
|
||
# This env var allows us to get inline annotations when ruff has complaints. | ||
RUFF_OUTPUT_FORMAT: github | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
# Only lint on the min and max supported Python versions. | ||
# It's extremely unlikely that there's a lint issue on any version in between | ||
# that doesn't show up on the min or max versions. | ||
# | ||
# GitHub rate-limits how many jobs can be running at any one time. | ||
# Starting new jobs is also relatively slow, | ||
# so linting on fewer versions makes CI faster. | ||
python-version: | ||
- "3.12" | ||
name: "lint #${{ matrix.python-version }}" | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Get changed files | ||
id: changed-files | ||
uses: Ana06/[email protected] | ||
- name: Set up Python ${{ matrix.python-version }} + Poetry ${{ env.POETRY_VERSION }} | ||
if: steps.changed-files.outputs.all | ||
uses: "./.github/actions/poetry_setup" | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
poetry-version: ${{ env.POETRY_VERSION }} | ||
cache-key: lint | ||
|
||
- name: Check Poetry File | ||
if: steps.changed-files.outputs.all | ||
shell: bash | ||
run: poetry check | ||
|
||
- name: Check lock file | ||
if: steps.changed-files.outputs.all | ||
shell: bash | ||
run: poetry lock --check | ||
|
||
- name: Install dependencies | ||
if: steps.changed-files.outputs.all | ||
# Also installs dev/lint/test/typing dependencies, to ensure we have | ||
# type hints for as many of our libraries as possible. | ||
# This helps catch errors that require dependencies to be spotted, for example: | ||
# https://github.com/langchain-ai/langchain/pull/10249/files#diff-935185cd488d015f026dcd9e19616ff62863e8cde8c0bee70318d3ccbca98341 | ||
# | ||
# If you change this configuration, make sure to change the `cache-key` | ||
# in the `poetry_setup` action above to stop using the old cache. | ||
# It doesn't matter how you change it, any change will cause a cache-bust. | ||
run: poetry install --with dev | ||
|
||
- name: Get .mypy_cache to speed up mypy | ||
if: steps.changed-files.outputs.all | ||
uses: actions/cache@v3 | ||
env: | ||
SEGMENT_DOWNLOAD_TIMEOUT_MIN: "2" | ||
with: | ||
path: | | ||
.mypy_cache | ||
key: mypy-lint-${{ runner.os }}-${{ runner.arch }}-py${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }} | ||
|
||
- name: Analysing package code with our lint | ||
if: steps.changed-files.outputs.all | ||
run: | | ||
if make lint_package > /dev/null 2>&1; then | ||
make lint_package | ||
else | ||
echo "lint_package command not found, using lint instead" | ||
make lint | ||
fi | ||
- name: Install test dependencies | ||
if: steps.changed-files.outputs.all | ||
# Also installs dev/lint/test/typing dependencies, to ensure we have | ||
# type hints for as many of our libraries as possible. | ||
# This helps catch errors that require dependencies to be spotted, for example: | ||
# https://github.com/langchain-ai/langchain/pull/10249/files#diff-935185cd488d015f026dcd9e19616ff62863e8cde8c0bee70318d3ccbca98341 | ||
# | ||
# If you change this configuration, make sure to change the `cache-key` | ||
# in the `poetry_setup` action above to stop using the old cache. | ||
# It doesn't matter how you change it, any change will cause a cache-bust. | ||
run: | | ||
poetry install --with dev | ||
- name: Get .mypy_cache_test to speed up mypy | ||
if: steps.changed-files.outputs.all | ||
uses: actions/cache@v3 | ||
env: | ||
SEGMENT_DOWNLOAD_TIMEOUT_MIN: "2" | ||
with: | ||
path: | | ||
.mypy_cache_test | ||
key: mypy-test-${{ runner.os }}-${{ runner.arch }}-py${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }} | ||
|
||
- name: Analysing tests with our lint | ||
if: steps.changed-files.outputs.all | ||
run: | | ||
if make lint_tests > /dev/null 2>&1; then | ||
make lint_tests | ||
else | ||
echo "lint_tests command not found, skipping step" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: test | ||
|
||
on: | ||
workflow_call | ||
|
||
env: | ||
POETRY_VERSION: "1.7.1" | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: | ||
- "3.9" | ||
- "3.10" | ||
- "3.11" | ||
- "3.12" | ||
|
||
name: "test #${{ matrix.python-version }}" | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python ${{ matrix.python-version }} + Poetry ${{ env.POETRY_VERSION }} | ||
uses: "./.github/actions/poetry_setup" | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
poetry-version: ${{ env.POETRY_VERSION }} | ||
cache-key: test | ||
|
||
- name: Install dependencies | ||
shell: bash | ||
run: | | ||
poetry install --with dev | ||
- name: Run tests | ||
shell: bash | ||
run: | | ||
make test | ||
- name: Ensure the tests did not create any additional files | ||
shell: bash | ||
run: | | ||
set -eu | ||
STATUS="$(git status)" | ||
echo "$STATUS" | ||
# grep will exit non-zero if the target message isn't found, | ||
# and `set -e` above will cause the step to fail. | ||
echo "$STATUS" | grep 'nothing to commit, working tree clean' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
name: test-release | ||
|
||
on: | ||
workflow_call | ||
|
||
env: | ||
POETRY_VERSION: "1.7.1" | ||
PYTHON_VERSION: "3.10" | ||
|
||
jobs: | ||
build: | ||
if: github.ref == 'refs/heads/main' | ||
runs-on: ubuntu-latest | ||
|
||
outputs: | ||
pkg-name: ${{ steps.check-version.outputs.pkg-name }} | ||
version: ${{ steps.check-version.outputs.version }} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Python + Poetry ${{ env.POETRY_VERSION }} | ||
uses: "./.github/actions/poetry_setup" | ||
with: | ||
python-version: ${{ env.PYTHON_VERSION }} | ||
poetry-version: ${{ env.POETRY_VERSION }} | ||
cache-key: release | ||
|
||
# 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: poetry build | ||
|
||
- name: Upload build | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: test-dist | ||
path: dist/ | ||
|
||
- name: Check Version | ||
id: check-version | ||
shell: bash | ||
run: | | ||
echo pkg-name="$(poetry version | cut -d ' ' -f 1)" >> $GITHUB_OUTPUT | ||
echo version="$(poetry version --short)" >> $GITHUB_OUTPUT | ||
publish: | ||
needs: | ||
- build | ||
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 | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: actions/download-artifact@v4 | ||
with: | ||
name: test-dist | ||
path: dist/ | ||
|
||
- name: Publish to test PyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
packages-dir: dist/ | ||
verbose: true | ||
print-hash: true | ||
repository-url: https://test.pypi.org/legacy/ | ||
|
||
# We overwrite any existing distributions with the same name and version. | ||
# This is *only for CI use* and is *extremely dangerous* otherwise! | ||
# https://github.com/pypa/gh-action-pypi-publish#tolerating-release-package-file-duplicates | ||
skip-existing: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
|
||
# If another push to the same PR or branch happens while this workflow is still running, | ||
# cancel the earlier run in favor of the next run. | ||
# | ||
# There's no point in testing an outdated version of the code. GitHub only allows | ||
# a limited number of job runners to be active at the same time, so it's better to cancel | ||
# pointless jobs early so that more useful jobs can run sooner. | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
env: | ||
POETRY_VERSION: "1.7.1" | ||
|
||
jobs: | ||
lint: | ||
uses: ./.github/workflows/_lint.yml | ||
secrets: inherit | ||
|
||
test: | ||
uses: ./.github/workflows/_test.yml | ||
secrets: inherit | ||
|
||
ci_success: | ||
name: "CI Success" | ||
needs: [lint, test] | ||
if: | | ||
always() | ||
runs-on: ubuntu-latest | ||
env: | ||
JOBS_JSON: ${{ toJSON(needs) }} | ||
RESULTS_JSON: ${{ toJSON(needs.*.result) }} | ||
EXIT_CODE: ${{!contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') && '0' || '1'}} | ||
steps: | ||
- name: "CI Success" | ||
run: | | ||
echo $JOBS_JSON | ||
echo $RESULTS_JSON | ||
echo "Exiting with $EXIT_CODE" | ||
exit $EXIT_CODE |
Oops, something went wrong.