Skip to content

Publish npm package

Publish npm package #1

Workflow file for this run

name: Publish npm package
on:
workflow_call:
inputs:
package:
required: true
type: string
publish:
required: true
type: boolean
workflow_dispatch:
inputs:
package:
description: 'Publish the package in this folder'
required: true
type: choice
options:
- canvas-html
- canvas-react
publish:
description: 'Publish and commit the package changes'
required: true
type: boolean
jobs:
publish:
runs-on: ubuntu-latest
name: Will ${{inputs.publish != true && 'not '}}publish ${{ inputs.package }}
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '20.x'
- name: Install dependencies
run: npm install
- name: Increment package version and build
id: version
run: |
cd packages/${{ inputs.package }}
npm version prerelease --preid=beta --no-git-tag-version
npm run build
package_version=$(node --eval="process.stdout.write(require('./package.json').version)")
echo "version=$package_version" > $GITHUB_OUTPUT
- name: Publish prerelease package
if: ${{ inputs.publish == true }}
run: |
cd packages/${{ inputs.package }}
npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
npm publish --tag prerelease --ignore-scripts
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Push version increment to GIT
if: ${{ inputs.publish == true }}
run: |
git config user.email "[email protected]"
git config user.name "$GITHUB_ACTOR"
git add packages/${{ inputs.package }}/.
git commit -m "ci: published version ${{ steps.version.outputs.version }} [skip ci]"
git push
env:
github-token: ${{ secrets.GITHUB_TOKEN }}