Skip to content

.

. #146

Workflow file for this run

name: Publish to npm
on:
push:
branches: [master]
permissions:
contents: write
id-token: write
jobs:
publish-packages:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 2
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: "https://registry.npmjs.org"
- uses: oven-sh/setup-bun@v2
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Publish changed non-private packages
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
set -euo pipefail
failed_packages=""
for dir in packages/*/; do
pkg="${dir}package.json"
if [ ! -f "$pkg" ]; then
echo "⏭ Skipping $dir (no package.json)"
continue
fi
is_private=$(node -e "const p=require('./$pkg'); console.log(!!p.private)")
name=$(node -e "const p=require('./$pkg'); console.log(p.name)")
version=$(node -e "const p=require('./$pkg'); console.log(p.version)")
if [ "$is_private" = "true" ]; then
echo "⏭ Skipping $name (private)"
continue
fi
if git diff --quiet HEAD^ HEAD -- "$dir"; then
echo "⏭ Skipping $name (no changes)"
continue
fi
echo "📦 Releasing $name from $dir"
(
cd "$dir"
remote_version=$(npm view "$name" version 2>/dev/null || echo "")
if [ "$remote_version" = "$version" ]; then
echo "🔼 Bumping $name because $version already exists on npm"
npm version patch --no-git-tag-version
version=$(node -e "const p=require('./package.json'); console.log(p.version)")
fi
npm install --ignore-scripts --legacy-peer-deps
has_build=$(node -e "const p=require('./package.json'); console.log(!!(p.scripts && p.scripts.build))")
if [ "$has_build" = "true" ]; then
npm run build
fi
echo "Publishing $(node -e "const p=require('./package.json'); console.log(p.name+'@'+p.version)")"
npm publish --provenance --access public
) || {
echo "❌ Failed to publish $name"
failed_packages="$failed_packages $name"
}
done
if [ -n "$failed_packages" ]; then
echo "⚠ Failed packages:$failed_packages"
exit 1
fi
- name: Commit version bumps
if: success()
run: |
git add packages/*/package.json packages/*/package-lock.json
git diff --staged --quiet && echo "No version changes to commit" && exit 0
git commit -m "chore: bump published package versions [skip ci]"
git push