|
| 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 |
0 commit comments