Skip to content

updated

updated #5

Workflow file for this run

name: Publish to NPM
on:
push:
branches: [ main ]
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write # Required for provenance
steps:
- uses: actions/checkout@v4
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- name: Cache dependencies
uses: actions/cache@v4
with:
path: ~/.bun/install/cache
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lock') }}
restore-keys: |
${{ runner.os }}-bun-
- name: Verify NPM Token
run: |
if [ -z "${{ secrets.NPM_TOKEN }}" ]; then
echo "::error::NPM_TOKEN is missing. Please add it to your GitHub Repository Secrets."
exit 1
fi
- name: Publish MotionForge
working-directory: packages/motionforge
run: |
echo "Processing motionforge..."
bun install
# Using bun x ensures tsup is found/run correctly
echo "Building motionforge..."
bun x tsup
PACKAGE_NAME=$(node -p "require('./package.json').name")
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo "Checking if $PACKAGE_NAME@$CURRENT_VERSION is already published..."
NPM_VERSION=$(npm view $PACKAGE_NAME version 2>/dev/null || echo "")
if [ -z "$NPM_VERSION" ]; then
echo "Package $PACKAGE_NAME not found on NPM. Initial publication."
NPM_VERSION="0.0.0"
fi
if [ "$CURRENT_VERSION" != "$NPM_VERSION" ]; then
echo "New version detected: $CURRENT_VERSION (NPM has $NPM_VERSION). Publishing..."
npm publish --access public --provenance
echo "Successfully published $PACKAGE_NAME@$CURRENT_VERSION"
else
echo "$PACKAGE_NAME@$CURRENT_VERSION is already up to date on NPM."
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish Create-MotionForge
working-directory: packages/create-motionforge
run: |
echo "Processing create-motionforge..."
bun install
PACKAGE_NAME=$(node -p "require('./package.json').name")
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo "Checking if $PACKAGE_NAME@$CURRENT_VERSION is already published..."
NPM_VERSION=$(npm view $PACKAGE_NAME version 2>/dev/null || echo "")
if [ -z "$NPM_VERSION" ]; then
echo "Package $PACKAGE_NAME not found on NPM. Initial publication."
NPM_VERSION="0.0.0"
fi
if [ "$CURRENT_VERSION" != "$NPM_VERSION" ]; then
echo "New version detected: $CURRENT_VERSION (NPM has $NPM_VERSION). Publishing..."
npm publish --access public --provenance
echo "Successfully published $PACKAGE_NAME@$CURRENT_VERSION"
else
echo "$PACKAGE_NAME@$CURRENT_VERSION is already up to date on NPM."
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}