Skip to content

v0.6.0 — Phase 6: HTML Report, Badge & CI #11

v0.6.0 — Phase 6: HTML Report, Badge & CI

v0.6.0 — Phase 6: HTML Report, Badge & CI #11

Workflow file for this run

name: Publish to npm
on:
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: 'Tag version to publish (e.g., 0.2.0)'
required: true
type: string
permissions:
contents: read
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'workflow_dispatch' && format('refs/tags/v{0}', inputs.tag) || github.ref }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
cache: 'npm'
- name: Verify version matches tag
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TAG_VERSION="${{ inputs.tag }}"
else
TAG_VERSION="${GITHUB_REF#refs/tags/v}"
fi
PKG_VERSION=$(node -p "require('./package.json').version")
if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then
echo "Error: Tag version ($TAG_VERSION) does not match package.json version ($PKG_VERSION)"
exit 1
fi
echo "Version check passed: $PKG_VERSION"
- name: Check if version already published
run: |
PKG_VERSION=$(node -p "require('./package.json').version")
if npm view @eduardbar/drift@$PKG_VERSION version 2>/dev/null; then
echo "Version $PKG_VERSION already published on npm. Skipping."
echo "skip_publish=true" >> $GITHUB_ENV
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Install dependencies
if: env.skip_publish != 'true'
run: npm ci
- name: Build
if: env.skip_publish != 'true'
run: npm run build
- name: Publish to npm
if: env.skip_publish != 'true'
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}