2025-01-27 13:22:46 -03:00

40 lines
1.1 KiB
YAML

name: NPM Package Publish
on:
push:
branches: [main]
release:
types: [created]
workflow_dispatch:
jobs:
publish-npm:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
with:
registry-url: "https://registry.npmjs.org"
- run: bun install
- run: bun run build
- run: |
PACKAGE_NAME=$(jq -r '.name' package.json)
PACKAGE_VERSION=$(jq -r '.version' package.json)
# Get the version from npm registry
REGISTRY_VERSION=$(npm show "$PACKAGE_NAME" version)
# Compare versions
if [ "$PACKAGE_VERSION" == "$REGISTRY_VERSION" ]; then
echo "Version $PACKAGE_VERSION already exists in the npm registry."
exit 0
else
echo "Version $PACKAGE_VERSION does not exist in the npm registry. Proceeding..."
npm publish --provenance --access public
fi
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}