forked from harsha-iiiv/openapi-mcp-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
52 lines (44 loc) · 1.45 KB
/
Copy pathnpm-publish.yml
File metadata and controls
52 lines (44 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
name: NPM Publish
on:
push:
branches:
- main
permissions:
contents: read
packages: write
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js with caching
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
cache: 'npm' # Enables npm dependency caching
cache-dependency-path: '**/package-lock.json' # Cache key based on lockfile
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Check version change
id: check_version
run: |
CURRENT_VERSION=$(node -p "require('./package.json').version")
PREV_VERSION=$(git show HEAD^:package.json | grep '"version":' | sed -E 's/.*"version": *"([^"]+)".*/\1/')
if [ "$CURRENT_VERSION" != "$PREV_VERSION" ]; then
echo "Version changed from $PREV_VERSION to $CURRENT_VERSION"
echo "version_changed=true" >> $GITHUB_OUTPUT
else
echo "Version unchanged: $CURRENT_VERSION"
echo "version_changed=false" >> $GITHUB_OUTPUT
fi
- name: Publish to npm
if: steps.check_version.outputs.version_changed == 'true'
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}