Skip to content

Commit 187e5da

Browse files
authored
Merge pull request #2328 from ManishMadan2882/main
Chore(React widget): automate publish via actions
2 parents 175ed58 + c4968a6 commit 187e5da

File tree

16 files changed

+5329
-1574
lines changed

16 files changed

+5329
-1574
lines changed

.github/workflows/npm-publish.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Publish npm libraries
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: >
8+
Version bump type (patch | minor | major) or explicit semver (e.g. 1.2.3).
9+
Applies to both docsgpt and docsgpt-react.
10+
required: true
11+
default: patch
12+
13+
jobs:
14+
publish:
15+
runs-on: ubuntu-latest
16+
environment: npm-release
17+
defaults:
18+
run:
19+
working-directory: extensions/react-widget
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- uses: actions/setup-node@v4
25+
with:
26+
node-version: 20
27+
registry-url: https://registry.npmjs.org
28+
29+
- name: Install dependencies
30+
run: npm ci
31+
32+
# ── docsgpt (HTML embedding bundle) ──────────────────────────────────
33+
# Uses the `build` script (parcel build src/browser.tsx) and keeps
34+
# the `targets` field so Parcel produces browser-optimised bundles.
35+
36+
- name: Set package name → docsgpt
37+
run: jq --arg n "docsgpt" '.name=$n' package.json > _tmp.json && mv _tmp.json package.json
38+
39+
- name: Bump version (docsgpt)
40+
id: version_docsgpt
41+
run: |
42+
VERSION="${{ github.event.inputs.version }}"
43+
NEW_VER=$(npm version "${VERSION:-patch}" --no-git-tag-version)
44+
echo "version=${NEW_VER#v}" >> "$GITHUB_OUTPUT"
45+
46+
- name: Build docsgpt
47+
run: npm run build
48+
49+
- name: Publish docsgpt
50+
run: npm publish --verbose
51+
env:
52+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
53+
54+
# ── docsgpt-react (React library bundle) ─────────────────────────────
55+
# Uses `build:react` script (parcel build src/index.ts) and strips
56+
# the `targets` field so Parcel treats the output as a plain library
57+
# without browser-specific target resolution, producing a smaller bundle.
58+
59+
- name: Reset package.json from source control
60+
run: git checkout -- package.json
61+
62+
- name: Set package name → docsgpt-react
63+
run: jq --arg n "docsgpt-react" '.name=$n' package.json > _tmp.json && mv _tmp.json package.json
64+
65+
- name: Remove targets field (react library build)
66+
run: jq 'del(.targets)' package.json > _tmp.json && mv _tmp.json package.json
67+
68+
- name: Bump version (docsgpt-react) to match docsgpt
69+
run: npm version "${{ steps.version_docsgpt.outputs.version }}" --no-git-tag-version
70+
71+
- name: Clean dist before react build
72+
run: rm -rf dist
73+
74+
- name: Build docsgpt-react
75+
run: npm run build:react
76+
77+
- name: Publish docsgpt-react
78+
run: npm publish --verbose
79+
env:
80+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
81+
82+
# ── Commit the bumped version back to the repository ─────────────────
83+
84+
- name: Reset package.json and write final version
85+
run: |
86+
git checkout -- package.json
87+
jq --arg v "${{ steps.version_docsgpt.outputs.version }}" '.version=$v' \
88+
package.json > _tmp.json && mv _tmp.json package.json
89+
npm install --package-lock-only
90+
91+
- name: Commit version bump
92+
run: |
93+
git config user.name "github-actions[bot]"
94+
git config user.email "github-actions[bot]@users.noreply.github.com"
95+
git add package.json package-lock.json
96+
git commit -m "chore: bump npm libraries to v${{ steps.version_docsgpt.outputs.version }}"
97+
git push
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: React Widget Build
2+
3+
on:
4+
push:
5+
paths:
6+
- 'extensions/react-widget/**'
7+
pull_request:
8+
paths:
9+
- 'extensions/react-widget/**'
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
defaults:
18+
run:
19+
working-directory: extensions/react-widget
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- uses: actions/setup-node@v4
25+
with:
26+
node-version: 20
27+
cache: npm
28+
cache-dependency-path: extensions/react-widget/package-lock.json
29+
30+
- name: Install dependencies
31+
run: npm ci
32+
33+
- name: Build
34+
run: npm run build
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import js from '@eslint/js'
2+
import tsParser from '@typescript-eslint/parser'
3+
import tsPlugin from '@typescript-eslint/eslint-plugin'
4+
import react from 'eslint-plugin-react'
5+
import unusedImports from 'eslint-plugin-unused-imports'
6+
import prettier from 'eslint-plugin-prettier'
7+
import globals from 'globals'
8+
9+
export default [
10+
{
11+
ignores: [
12+
'node_modules/',
13+
'dist/',
14+
'prettier.config.cjs',
15+
'custom.d.ts',
16+
'package-lock.json',
17+
'package.json',
18+
],
19+
},
20+
{
21+
files: ['**/*.{js,jsx,ts,tsx}'],
22+
languageOptions: {
23+
ecmaVersion: 'latest',
24+
sourceType: 'module',
25+
parser: tsParser,
26+
parserOptions: {
27+
ecmaFeatures: {
28+
jsx: true,
29+
},
30+
},
31+
globals: {
32+
...globals.browser,
33+
...globals.es2021,
34+
...globals.node,
35+
},
36+
},
37+
plugins: {
38+
'@typescript-eslint': tsPlugin,
39+
react,
40+
'unused-imports': unusedImports,
41+
prettier,
42+
},
43+
rules: {
44+
...js.configs.recommended.rules,
45+
...tsPlugin.configs.recommended.rules,
46+
...react.configs.recommended.rules,
47+
...prettier.configs.recommended.rules,
48+
'react/prop-types': 'off',
49+
'unused-imports/no-unused-imports': 'error',
50+
'react/react-in-jsx-scope': 'off',
51+
'no-undef': 'off',
52+
'@typescript-eslint/no-explicit-any': 'warn',
53+
'@typescript-eslint/no-unused-vars': [
54+
'warn',
55+
{ varsIgnorePattern: '^_', argsIgnorePattern: '^_' },
56+
],
57+
'@typescript-eslint/no-unused-expressions': 'warn',
58+
'prettier/prettier': [
59+
'error',
60+
{
61+
endOfLine: 'auto',
62+
},
63+
],
64+
},
65+
settings: {
66+
react: {
67+
version: 'detect',
68+
},
69+
},
70+
},
71+
]
72+

0 commit comments

Comments
 (0)