Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Publish to npm

on:
workflow_dispatch:
inputs:
dry_run:
description: "Run npm publish as a dry run"
required: false
default: "false"
type: choice
options:
- "false"
- "true"

permissions:
contents: read

concurrency:
group: publish-npm-${{ github.ref }}
cancel-in-progress: false

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout sumit-react
uses: actions/checkout@v4
with:
path: sumit-react

- name: Checkout sumit-api peer package
uses: actions/checkout@v4
with:
repository: Digitizers/sumit-api
path: sumit-api
Comment on lines +32 to +35
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Pin sumit-api checkout to a deterministic ref

This checkout omits ref, so actions/checkout will pull the secondary repo’s default branch instead of a revision tied to the sumit-react release being published. That makes publishes non-reproducible: running this workflow for an older branch/tag can build against a newer sumit-api state and fail (or produce a package validated against the wrong peer code). Set ref explicitly (for example to an input or known tag/sha) so release behavior is stable.

Useful? React with 👍 / 👎.


- uses: pnpm/action-setup@v4
with:
version: 10.26.0

- uses: actions/setup-node@v4
with:
node-version: 22
registry-url: https://registry.npmjs.org
cache: pnpm
cache-dependency-path: |
sumit-react/pnpm-lock.yaml
sumit-api/pnpm-lock.yaml

- name: Build sumit-api peer package
working-directory: sumit-api
run: |
pnpm install --frozen-lockfile
pnpm build

- name: Install sumit-react
working-directory: sumit-react
run: pnpm install --frozen-lockfile

- name: Typecheck
working-directory: sumit-react
run: pnpm typecheck

- name: Test
working-directory: sumit-react
run: pnpm test

- name: Build
working-directory: sumit-react
run: pnpm build

- name: Pack check
working-directory: sumit-react
run: npm pack --dry-run

- name: Verify npm token
working-directory: sumit-react
run: npm whoami
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish public package
working-directory: sumit-react
run: |
if [ "${{ inputs.dry_run }}" = "true" ]; then
npm publish --access public --dry-run
else
npm publish --access public
Comment on lines +82 to +88
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restrict publish step to protected release refs

The workflow publishes unconditionally once it reaches this step, and workflow_dispatch runs can be launched on arbitrary branches/tags from the UI/API. Without a ref guard (or environment protection), a maintainer can accidentally publish a feature branch build to npm. Add a branch/tag condition (for example only main or release tags) before executing npm publish.

Useful? React with 👍 / 👎.

fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Loading