Skip to content

publish npm packages #2658

publish npm packages

publish npm packages #2658

name: publish npm packages
env:
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
on:
workflow_dispatch:
# trigger this workflow when the CI workflow is completed
workflow_run:
workflows: ["Continuous Integration"]
branches: [main]
types:
- completed
jobs:
publish:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Setup Pnpm
uses: pnpm/action-setup@v4
with:
version: 9
- name: Setup Node.js 22
uses: actions/setup-node@v3
with:
node-version: 22
cache: "pnpm"
# Check if any package needs to be published
- name: Check if publish is needed
id: check_publish
run: |
echo "Running pnpm publish --dry-run"
pnpm publish --dry-run > publish_output.txt 2>&1 || true
if grep -q "published" publish_output.txt; then
echo "needs_publish=true" >> $GITHUB_ENV
else
echo "No packages need to be published"
echo "needs_publish=false" >> $GITHUB_ENV
fi
# Conditional steps based on the check
- name: Install Dependencies
if: env.needs_publish == 'true'
run: pnpm install
- name: Install Doppler CLI for env variables
if: env.needs_publish == 'true'
uses: dopplerhq/cli-action@v2
- name: Build
if: env.needs_publish == 'true'
run: doppler run -- pnpm build
env:
DOPPLER_TOKEN: ${{ secrets.DOPPLER_PRODUCTION_ENV_TOKEN }}
- name: Publish packages
if: env.needs_publish == 'true'
run: pnpm ci:publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}