Skip to content

Commit 5f4b430

Browse files
authored
ci: libs publishing workflow (#2570)
Closes #2550 This PR enables automatic publishing of the `@chainlit/react-client` (and any other non-private package in `libs/*` if we will add them) to the **npm** registry. To test the publishing process, use the **Dry run (test publishing)** option, similar to the **Publish to TestPyPI instead of PyPI** feature introduced in #2483. ### Other changes: - Removed `pnpm install` arguments, since CI **must always use a frozen lockfile**. * **Updating the lockfile during CI runs is bad practice**, as changes are not committed back to the repository and resolved dependency versions may differ from those declared in the source code. * If you encounter an error where `pnpm` indicates that the lockfile needs to be updated, run `pnpm install` or `pnpm install --lockfile-only` locally and commit the resulting changes to the PR where the CI failure occurred. - Removed `pnpm-skip-install` from `pnpm-node-install` action since no longer used anywhere - CI will be skipped if the PR or commit includes only markdown files located at the repository root or the `LICENSE` file.
1 parent a909ea3 commit 5f4b430

File tree

9 files changed

+63
-21
lines changed

9 files changed

+63
-21
lines changed

.github/actions/pnpm-node-install/action.yaml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@ inputs:
66
description: Node.js version
77
required: true
88
default: '24.3.0' # Switch to 'lts' as soon as Node 24 reaches LTS status.
9-
pnpm-skip-install:
10-
description: Skip install.
11-
required: false
12-
default: 'false'
13-
pnpm-install-args:
14-
description: Extra arguments for pnpm install, e.g. --no-frozen-lockfile.
15-
default: '--frozen-lockfile'
169

1710
runs:
1811
using: composite
@@ -28,7 +21,5 @@ runs:
2821
cache: 'pnpm'
2922
cache-dependency-path: '**/pnpm-lock.yaml'
3023
- name: Install JS dependencies
31-
run: pnpm install ${{ inputs.pnpm-install-args }}
32-
shell: bash
33-
# Skip install if pnpm-skip-install is true
34-
if: ${{ inputs.pnpm-skip-install != 'true' }}
24+
run: pnpm install
25+
shell: bash

.github/workflows/ci.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ on:
66
merge_group:
77
pull_request:
88
branches: [main, dev, 'release/**']
9+
paths-ignore:
10+
- '*.md'
11+
- LICENSE
912
push:
1013
branches: [main, dev, 'release/**']
14+
paths-ignore:
15+
- '*.md'
16+
- LICENSE
1117

1218
permissions: read-all
1319

.github/workflows/copilot-setup-steps.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ jobs:
3232

3333
- name: Install Node.js, pnpm and dependencies
3434
uses: ./.github/actions/pnpm-node-install
35-
with:
36-
node-version: "24.3.0"
37-
pnpm-install-args: "--frozen-lockfile"
3835

3936
- name: Install Python, uv and dependencies
4037
uses: ./.github/actions/uv-python-install

.github/workflows/e2e-tests.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ jobs:
1616
- uses: actions/checkout@v4
1717
- uses: ./.github/actions/pnpm-node-install
1818
name: Install Node, pnpm and dependencies.
19-
with:
20-
pnpm-install-args: "--frozen-lockfile"
2119
- name: Install Cypress
2220
uses: cypress-io/github-action@v6
2321
with:
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Publish libs
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
dry_run:
7+
description: 'Dry run (test publishing)'
8+
required: false
9+
default: false
10+
type: boolean
11+
release:
12+
types: [published]
13+
14+
permissions: read-all
15+
16+
jobs:
17+
validate:
18+
name: Validate inputs
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Validate publishing branch and destination package index
22+
run: |
23+
if [[ "${{ github.ref_name }}" != "main" && "${{ github.event_name }}" != "release" ]]; then
24+
if [[ "${{ inputs.dry_run }}" != "true" ]]; then
25+
echo "❌ Error: Only build from main branch or release tag can be published to npm registry."
26+
echo "Please check 'Dry run (test publishing)' when running from branch: ${{ github.ref_name }}"
27+
exit 1
28+
fi
29+
fi
30+
echo "✅ Validation passed"
31+
ci:
32+
needs: [validate]
33+
uses: ./.github/workflows/ci.yaml
34+
secrets: inherit
35+
build-n-publish:
36+
name: Upload libs release to npm registry
37+
runs-on: ubuntu-latest
38+
needs: [ci]
39+
permissions:
40+
contents: read
41+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
42+
steps:
43+
- uses: actions/checkout@v4
44+
- uses: ./.github/actions/pnpm-node-install
45+
name: Install Node, pnpm and dependencies.
46+
47+
- name: Build libs
48+
run: pnpm build:libs
49+
50+
- name: Publish packages to npm
51+
run: pnpm publish --recursive ${{ inputs.dry_run && '--dry-run --no-git-checks' || '' }} # --no-git-checks allows testing from non-main branches

.github/workflows/publish.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ jobs:
4747
- uses: actions/checkout@v4
4848
- uses: ./.github/actions/pnpm-node-install
4949
name: Install Node, pnpm and dependencies.
50-
with:
51-
pnpm-install-args: --no-frozen-lockfile
5250
- uses: ./.github/actions/uv-python-install
5351
name: Install Python, uv and Python dependencies
5452
with:

RELENG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This document outlines the steps for maintainers to create a new release of the
1717
2. **Bump the package version**:
1818

1919
- Update `version` in `backend/chainlit/version.py`.
20+
- Update `version` in `libs/*/package.json` if there were any changes in the corresponding directories.
2021

2122
3. **Update the changelog**:
2223

libs/react-client/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
"dev": "tsup src/index.ts --clean --format esm,cjs --dts --external react --external recoil --minify --sourcemap --treeshake",
88
"lint": "eslint ./src --ext ts,tsx --report-unused-disable-directives --max-warnings 0 && tsc --noemit",
99
"format": "prettier '**/*.{ts,tsx}' --write",
10-
"test": "echo no tests yet",
11-
"prepublishOnly": "pnpm run build"
10+
"test": "echo no tests yet"
1211
},
1312
"repository": {
1413
"type": "git",

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"formatUi": "pnpm run --parallel format",
2929
"lintPython": "cd backend && uv run dmypy run -- chainlit/ tests/",
3030
"formatPython": "black `git ls-files | grep '.py$'` && isort --profile=black .",
31-
"buildUi": "cd libs/react-client && pnpm run build && cd ../copilot && pnpm run build && cd ../../frontend && pnpm run build"
31+
"build:libs": "cd libs/react-client && pnpm run build && cd ../copilot && pnpm run build",
32+
"buildUi": "pnpm build:libs && cd frontend && pnpm run build"
3233
},
3334
"pnpm": {
3435
"overrides": {

0 commit comments

Comments
 (0)