Skip to content

NPM Auto Publish

NPM Auto Publish #15

Workflow file for this run

name: NPM Auto Publish
on:
release:
types:
- released
branches:
- master
jobs:
check-packages:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Login to npm registry
run: npm config set //registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN
env:
NPM_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}
- name: Publish if version changed
run: |
npm install -g pnpm
pnpm install
for dir in packages/*/ packages/networks/*/; do
if [ -d "$dir" ] && [ "$(basename "$dir")" != "boilerplate" ]; then
cd "$dir" || exit
if [ -f "package.json" ]; then
PACKAGE_INFO=$(node -p "JSON.stringify(require('./package.json'))")
PACKAGE_NAME=$(echo "$PACKAGE_INFO" | jq -r '.name')
CURRENT_VERSION=$(echo "$PACKAGE_INFO" | jq -r '.version')
PREVIOUS_VERSION=$(npm show "$PACKAGE_NAME" version)
if [ "$PREVIOUS_VERSION" != "$CURRENT_VERSION" ]; then
echo "Version changed for $PACKAGE_NAME from $PREVIOUS_VERSION to $CURRENT_VERSION"
pnpm install && npm publish
fi
else
echo "package.json not found in $dir"
fi
cd - || exit
fi
done