Skip to content

Publish NPM Package #10

Publish NPM Package

Publish NPM Package #10

Workflow file for this run

---
name: Publish NPM Package
on:
workflow_dispatch:
workflow_run:
workflows: [goreleaser]
types:
- completed
jobs:
publish_npm:
name: Publish NPM
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3
with:
fetch-tags: true
- name: Install node.js
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
working-directory: ./bdist/js
run: npm install --ignore-scripts
- name: Set package version
working-directory: ./bdist/js
run: npm run version
- name: Pack NPM Package
working-directory: ./bdist/js
run: npm pack
- name: Issue warning if NPM_TOKEN is not set
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
echo "::warning title=Missing authentication token::In order to publish an NPM package, you must set the NPM_TOKEN secret"
if: ${{ env.NODE_AUTH_TOKEN == '' }}
- name: Issue warning if NPM_EMAIL is not set
env:
NPM_EMAIL: ${{ secrets.NPM_EMAIL }}
run: |
echo "::warning title=Missing authentication information::In order to publish an NPM package, you must set the NPM_EMAIL secret"
if: ${{ env.NPM_EMAIL == '' }}
- name: Create .npmrc file
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_EMAIL: ${{ secrets.NPM_EMAIL }}
run: |
# Use project specific npmrc file (cf. https://docs.npmjs.com/cli/v6/using-npm/config)
# Use scoped AUTH TOKEN (cf. https://docs.npmjs.com/cli/v9/configuring-npm/npmrc#auth-related-configuration)
echo "//registry.npmjs.org/:_authToken = $NPM_AUTH_TOKEN" >> .npmrc
echo "email = $NPM_EMAIL" >> .npmrc
working-directory: ./bdist/js
if: ${{ env.NPM_AUTH_TOKEN != '' }}
- name: Publish NPM package
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish
working-directory: ./bdist/js
if: ${{ env.NODE_AUTH_TOKEN != '' }}