Skip to content

Publish API to NPM

Publish API to NPM #17

name: Publish API to NPM
on:
workflow_run:
workflows: [Test]
types: [completed]
branches: [main]
jobs:
publish:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Setup .npmrc file to publish to npm
- name: Setup .npmrc (NPM)
uses: actions/setup-node@v3
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
scope: '@arunabot'
- name: Update npm
run: npm install -g npm@latest
- name: Get Current version
id: current_version
working-directory: ./api
run: echo ::set-output name=version::$(node -p "require('./package.json').version")
- name: Get current npm version
id: npm_version
run: echo ::set-output name=version::$(npm view arunacore-api version)
- name: Compare versions and skip if same
id: compare_versions
if: ${{ steps.current_version.outputs.version == steps.npm_version.outputs.version }}
run: echo ::set-output name=skip::true && echo "Skipping publish as versions are same" && exit 0
- name: Install dependencies
working-directory: ./api
run: npm ci
- name: Build
working-directory: ./api
run: npm run build
- name: Prepare to publish
working-directory: ./api
run: npm run pdeploy
- name: Publish to npm
working-directory: ./api/out
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}