Skip to content

Commit

Permalink
Improvements to GH actions, unbreak the build (#1445)
Browse files Browse the repository at this point in the history
* Verbosity in config: _which_ config file is outdated?
* Allow config init without package install.
* UI build is run as part of package build.
* Update publish to harness Python build script.
* Use cypress action for cypress/pnpm installs on e2e tests.
* UI linting as separate workflow.
* Use defaults to specify versions.
* Bump checkout step to v4; avoid warning about deprecated Node.js.
* Use frozen lockfiles for all installs.
* Build UI in lint and do not lint during e2e.
  • Loading branch information
dokterbob authored Oct 21, 2024
1 parent a42c154 commit 22d198d
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 36 deletions.
9 changes: 9 additions & 0 deletions .github/actions/pnpm-node-install/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ inputs:
node-version:
description: Node.js version
required: true
default: '22.7.0'
pnpm-version:
description: pnpm version
required: true
default: '9.7.0'
pnpm-skip-install:
description: Skip install.
required: false
default: 'false'
pnpm-install-args:
description: Extra arguments for pnpm install, e.g. --no-frozen-lockfile.
default: '--frozen-lockfile'

runs:
using: composite
Expand All @@ -25,3 +32,5 @@ runs:
- name: Install JS dependencies
run: pnpm install ${{ inputs.pnpm-install-args }}
shell: bash
# Skip install if pnpm-skip-install is true
if: ${{ inputs.pnpm-skip-install != 'true' }}
2 changes: 2 additions & 0 deletions .github/actions/poetry-python-install/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ inputs:
python-version:
description: Python version
required: true
default: '3.9'
poetry-version:
description: Poetry version
required: true
default: '1.8.3'
poetry-working-directory:
description: Working directory for poetry command.
required: false
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ jobs:
e2e-tests:
uses: ./.github/workflows/e2e-tests.yaml
secrets: inherit
lint-ui:
uses: ./.github/workflows/lint-ui.yaml
secrets: inherit
ci:
runs-on: ubuntu-latest
name: Run CI
needs: [mypy, pytest, e2e-tests]
needs: [mypy, pytest, lint-ui, e2e-tests]
steps:
- name: Done
run: echo "Done"
14 changes: 6 additions & 8 deletions .github/workflows/e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,20 @@ jobs:
env:
BACKEND_DIR: ./backend
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ./.github/actions/pnpm-node-install
name: Install Node, pnpm and dependencies.
with:
node-version: 22.7.0
pnpm-version: 9.7.0
pnpm-install-args: --no-frozen-lockfile
pnpm-skip-install: true
- name: Install depdendencies and Cypress
uses: cypress-io/github-action@v6
with:
runTests: false
- uses: ./.github/actions/poetry-python-install
name: Install Python, poetry and Python dependencies
with:
python-version: 3.9
poetry-version: 1.8.3
poetry-working-directory: ${{ env.BACKEND_DIR }}
poetry-install-args: --with tests
- name: Lint UI
run: pnpm run lintUi
- name: Run tests
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/lint-ui.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: LintUI

on: [workflow_call]

permissions: read-all

jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/pnpm-node-install
name: Install Node, pnpm and dependencies.
- name: Build UI
run: pnpm run buildUi
- name: Lint UI
run: pnpm run lintUi
4 changes: 1 addition & 3 deletions .github/workflows/mypy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ jobs:
env:
BACKEND_DIR: ./backend
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ./.github/actions/poetry-python-install
name: Install Python, poetry and Python dependencies
with:
python-version: 3.9
poetry-version: 1.8.3
poetry-install-args: --with tests --with mypy --with custom-data --no-root
poetry-working-directory: ${{ env.BACKEND_DIR }}
- name: Run Mypy
Expand Down
10 changes: 1 addition & 9 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,17 @@ jobs:
contents: read
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: main
- uses: ./.github/actions/pnpm-node-install
name: Install Node, pnpm and dependencies.
with:
node-version: 22.7.0
pnpm-version: 9.7.0
pnpm-install-args: --no-frozen-lockfile
- uses: ./.github/actions/poetry-python-install
name: Install Python, poetry and Python dependencies
with:
python-version: 3.9
poetry-version: 1.8.3
poetry-working-directory: ${{ env.BACKEND_DIR }}
- name: Copy readme to backend
run: cp README.md backend/
- name: Build chainlit
run: pnpm run build
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
Expand Down
15 changes: 4 additions & 11 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,18 @@ jobs:
env:
BACKEND_DIR: ./backend
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ./.github/actions/pnpm-node-install
name: Install Node, pnpm and dependencies.
- uses: ./.github/actions/poetry-python-install
name: Install Python, poetry and Python dependencies
with:
python-version: ${{ matrix.python-version }}
poetry-version: 1.8.3
poetry-install-args: --with tests --with mypy --with custom-data --no-root
poetry-install-args: --with tests --with mypy --with custom-data
poetry-working-directory: ${{ env.BACKEND_DIR }}
- name: Install fastapi ${{ matrix.fastapi-version }}
run: poetry add fastapi@^${{ matrix.fastapi-version}}
working-directory: ${{ env.BACKEND_DIR }}
- uses: ./.github/actions/pnpm-node-install
name: Install Node, pnpm and dependencies.
with:
node-version: 22.7.0
pnpm-version: 9.7.0
pnpm-install-args: --no-frozen-lockfile
- name: Build UI
run: pnpm run buildUi
- name: Run Pytest
run: poetry run pytest --cov=chainlit/
working-directory: ${{ env.BACKEND_DIR }}
4 changes: 3 additions & 1 deletion backend/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@


def pnpm_install(project_root, pnpm_path):
subprocess.run([pnpm_path, "install"], cwd=project_root, check=True)
subprocess.run(
[pnpm_path, "install", "--frozen-lockfile"], cwd=project_root, check=True
)


def pnpm_buildui(project_root, pnpm_path):
Expand Down
2 changes: 1 addition & 1 deletion backend/chainlit/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ def load_settings():

if not meta or meta.get("generated_by") <= "0.3.0":
raise ValueError(
"Your config file is outdated. Please delete it and restart the app to regenerate it."
f"Your config file '{config_file}' is outdated. Please delete it and restart the app to regenerate it."
)

lc_cache_path = os.path.join(config_dir, ".langchain.db")
Expand Down
5 changes: 3 additions & 2 deletions backend/chainlit/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
try:
__version__ = metadata.version(__package__)
except metadata.PackageNotFoundError:
# Case where package metadata is not available.
__version__ = ""
# Case where package metadata is not available, default to a 'non-outdated' version.
# Ref: config.py::load_settings()
__version__ = "0.3.1"

0 comments on commit 22d198d

Please sign in to comment.