Skip to content

Publish API to NPM

Publish API to NPM #22

name: Publish API to NPM
on:
workflow_run:
workflows: [Test]
types: [completed]
branches: [main]
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Setup .npmrc file to publish to npm
- name: Setup .npmrc (NPM)
uses: actions/setup-node@v4
with:
node-version: 22
registry-url: 'https://registry.npmjs.org'
scope: '@arunabot'
- name: Get Current version
id: current_version
working-directory: ./api
run: echo version=$(node -p "require('./package.json').version") >> $GITHUB_OUTPUT
- name: Get current npm version
id: npm_version
run: echo version=$(npm view arunacore-api version) >> $GITHUB_OUTPUT
- name: Compare versions and skip if same
id: compare_versions
if: ${{ steps.current_version.outputs.version == steps.npm_version.outputs.version }}
run: echo "skip=true" >> $GITHUB_OUTPUT && echo "Skipping publish because versions are the same" && exit 0
- name: Install dependencies
if: ${{ steps.compare_versions.outputs.skip != 'true' }}
working-directory: ./api
run: npm ci
- name: Copy readme
if: ${{ steps.compare_versions.outputs.skip != 'true' }}
run: cp README.md ./api/README.md
- name: Publish to npm
working-directory: ./api
run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}