Skip to content

Update publish.yml

Update publish.yml #27

Workflow file for this run

name: Publish Package
on:
push:
branches:
- main
permissions:
actions: read
security-events: write
contents: read
jobs:
scan-pr:
uses: google/osv-scanner-action/.github/workflows/[email protected]
with:
scan-args: |-
--recursive
--skip-git=true
--lockfile pnpm-lock.yaml
./
publish:
needs: scan-pr
if: success()
runs-on: ubuntu-24.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Cache Node.js modules
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-node-
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: npm install
- name: Run Build
run: npm run build
- name: Configure .npmrc
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_AUTH_TOKEN }}" > ~/.npmrc
- name: Unpublish if exists
if: github.ref == 'refs/heads/main'
run: |
PACKAGE_NAME=$(node -p "require('./package.json').name")
PACKAGE_VERSION=$(node -p "require('./package.json').version")
echo "Checking if $PACKAGE_NAME@$PACKAGE_VERSION exists..."
# npm info "$PACKAGE_NAME@$PACKAGE_VERSION"
if npm view "$PACKAGE_NAME@$PACKAGE_VERSION" > /dev/null 2>&1; then
echo "Package version exists. Unpublishing..."
npm unpublish "$PACKAGE_NAME@$PACKAGE_VERSION" --force
else
echo "Package version does not exist. Publishing."
fi
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
- name: Publish Package
if: github.ref == 'refs/heads/main'
run: npm publish
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}