Skip to content

Commit 031669a

Browse files
committed
feat: adding npm publish automation
1 parent 8b06653 commit 031669a

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

.github/workflows/npm.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Publish SDK to NPM
2+
on:
3+
push:
4+
branches: ["main"]
5+
paths:
6+
- "sdk/**"
7+
workflow_dispatch:
8+
9+
jobs:
10+
publish:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
16+
- name: Setup pnpm
17+
uses: pnpm/action-setup@v3
18+
with:
19+
version: latest
20+
21+
- name: Setup Node.js
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: 20
25+
cache: 'pnpm'
26+
cache-dependency-path: 'sdk/pnpm-lock.yaml'
27+
registry-url: 'https://registry.npmjs.org'
28+
29+
- name: Install dependencies
30+
working-directory: ./sdk
31+
run: pnpm install --frozen-lockfile
32+
33+
- name: Build package
34+
working-directory: ./sdk
35+
run: pnpm build
36+
37+
- name: Check if version changed
38+
id: version-check
39+
working-directory: ./sdk
40+
run: |
41+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
42+
NPM_VERSION=$(npm view so-teams-sdk version 2>/dev/null || echo "0.0.0")
43+
echo "package_version=$PACKAGE_VERSION" >> $GITHUB_OUTPUT
44+
echo "npm_version=$NPM_VERSION" >> $GITHUB_OUTPUT
45+
if [ "$PACKAGE_VERSION" != "$NPM_VERSION" ]; then
46+
echo "should_publish=true" >> $GITHUB_OUTPUT
47+
echo "Version changed from $NPM_VERSION to $PACKAGE_VERSION"
48+
else
49+
echo "should_publish=false" >> $GITHUB_OUTPUT
50+
echo "Version unchanged: $PACKAGE_VERSION"
51+
fi
52+
53+
- name: Publish to NPM
54+
if: steps.version-check.outputs.should_publish == 'true'
55+
working-directory: ./sdk
56+
run: pnpm publish --access public --no-git-checks
57+
env:
58+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
59+
60+
- name: Create Git tag
61+
if: steps.version-check.outputs.should_publish == 'true'
62+
run: |
63+
git config --local user.email "[email protected]"
64+
git config --local user.name "GitHub Action"
65+
git tag "sdk-v${{ steps.version-check.outputs.package_version }}"
66+
git push origin "sdk-v${{ steps.version-check.outputs.package_version }}"

0 commit comments

Comments
 (0)