Skip to content

Issue #224544 feat: Enable GitHub Actions to publish NPM package #40

Issue #224544 feat: Enable GitHub Actions to publish NPM package

Issue #224544 feat: Enable GitHub Actions to publish NPM package #40

Workflow file for this run

name: πŸš€ Publish NPM Package
on:
pull_request:
branches:
- '**'
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: πŸ“₯ Checkout Code Repository
uses: actions/checkout@v4
- name: πŸ”§ Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org/'
- name: Authenticate to npm
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
- name: Debug NPM Token
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}"
cat ~/.npmrc # Verify the contents of .npmrc to ensure the token is written correctly
env:
NPM_AUTOMATION_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: πŸ“¦ Install Dependencies
run: npm install
- name: πŸ› οΈ Build Library
run: npm run build-lib
- name: πŸ” Ensure jq is installed
run: sudo apt-get install -y jq
- name: πŸ” Check if Version Exists
id: check-version
run: |
cd dist/quml-library
PACKAGE_NAME=$(jq -r .name package.json)
PACKAGE_VERSION=$(jq -r .version package.json)
NPM_REGISTRY="https://registry.npmjs.org"
STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$NPM_REGISTRY/$PACKAGE_NAME/$PACKAGE_VERSION")
echo "status=$STATUS" >> $GITHUB_ENV
- name: 🚒 Publish to NPM
if: env.status != '200'
run: |
cd dist/quml-library
if [[ "$(jq -r .version package.json)" == *"beta"* ]]; then
npm publish --tag=beta --access public
else
npm publish --access public
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: πŸ“œ Log Version Exists
if: env.status == '200'
run: echo "Version already exists, skipping publish."