1+ name : Release NPM Package
2+
3+ on :
4+ release :
5+ types : [published]
6+ workflow_dispatch :
7+ inputs :
8+ version :
9+ description : ' Version to release'
10+ required : true
11+ default : ' v0.1.0'
12+
13+ permissions :
14+ contents : write
15+ packages : write
16+
17+ env :
18+ CARGO_TERM_COLOR : always
19+
20+ jobs :
21+ build-binaries :
22+ name : Build ${{ matrix.target }}
23+ runs-on : ${{ matrix.os }}
24+ strategy :
25+ fail-fast : false
26+ matrix :
27+ include :
28+ - target : x86_64-unknown-linux-gnu
29+ os : ubuntu-latest
30+ archive : tar.gz
31+ - target : x86_64-apple-darwin
32+ os : macos-latest
33+ archive : tar.gz
34+ - target : aarch64-apple-darwin
35+ os : macos-14
36+ archive : tar.gz
37+ - target : x86_64-pc-windows-msvc
38+ os : windows-latest
39+ archive : zip
40+
41+ steps :
42+ - name : Checkout repository
43+ uses : actions/checkout@v4
44+
45+ - name : Install Rust
46+ uses : dtolnay/rust-toolchain@stable
47+ with :
48+ targets : ${{ matrix.target }}
49+
50+ - name : Build binary
51+ run : cargo build --release --target ${{ matrix.target }} --package template-mcp-server
52+
53+ - name : Prepare binary (Unix)
54+ if : matrix.archive == 'tar.gz'
55+ run : |
56+ mkdir -p dist
57+ cp target/${{ matrix.target }}/release/template-mcp-server dist/
58+ cd dist
59+ tar -czf template-mcp-server-${{ github.event.release.tag_name || github.event.inputs.version }}-${{ matrix.target }}.tar.gz template-mcp-server
60+
61+ - name : Prepare binary (Windows)
62+ if : matrix.archive == 'zip'
63+ run : |
64+ mkdir dist
65+ cp target/${{ matrix.target }}/release/template-mcp-server.exe dist/
66+ cd dist
67+ Compress-Archive -Path template-mcp-server.exe -DestinationPath template-mcp-server-${{ github.event.release.tag_name || github.event.inputs.version }}-${{ matrix.target }}.zip
68+
69+ - name : Upload binary to release
70+ shell : bash
71+ env :
72+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
73+ run : |
74+ VERSION=${{ github.event.release.tag_name || github.event.inputs.version }}
75+ FILE="dist/template-mcp-server-${VERSION}-${{ matrix.target }}.${{ matrix.archive }}"
76+
77+ # Check if release exists, create if not
78+ if ! gh release view "${VERSION}" >/dev/null 2>&1; then
79+ gh release create "${VERSION}" --title "Release ${VERSION}" --notes "Auto-generated release for ${VERSION}"
80+ fi
81+
82+ # Upload or update asset
83+ if gh release view "${VERSION}" --json assets --jq '.assets[].name' | grep -q "template-mcp-server-${VERSION}-${{ matrix.target }}.${{ matrix.archive }}"; then
84+ gh release delete-asset "${VERSION}" "template-mcp-server-${VERSION}-${{ matrix.target }}.${{ matrix.archive }}" --yes
85+ fi
86+
87+ gh release upload "${VERSION}" "${FILE}"
88+
89+ publish-npm :
90+ name : Publish to NPM
91+ needs : build-binaries
92+ runs-on : ubuntu-latest
93+ steps :
94+ - name : Checkout repository
95+ uses : actions/checkout@v4
96+
97+ - name : Setup Node.js
98+ uses : actions/setup-node@v4
99+ with :
100+ node-version : ' 18'
101+ registry-url : ' https://registry.npmjs.org'
102+
103+ - name : Update package version and dependencies
104+ working-directory : npm
105+ run : |
106+ VERSION=${{ github.event.release.tag_name || github.event.inputs.version }}
107+ # Remove 'v' prefix if present
108+ VERSION=${VERSION#v}
109+
110+ # Update main package version and optionalDependencies
111+ jq --arg version "$VERSION" '
112+ .version = $version |
113+ .optionalDependencies = {
114+ "@yourusername/template-mcp-server-darwin-arm64": $version,
115+ "@yourusername/template-mcp-server-darwin-x64": $version,
116+ "@yourusername/template-mcp-server-linux-x64": $version,
117+ "@yourusername/template-mcp-server-win32-x64": $version
118+ }
119+ ' package.json > package.json.tmp && mv package.json.tmp package.json
120+
121+ - name : Install dependencies
122+ working-directory : npm
123+ run : npm install
124+
125+ - name : Publish to NPM
126+ working-directory : npm
127+ run : npm publish --access public
128+ env :
129+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
130+
131+ - name : Create NPM release summary
132+ run : |
133+ echo "## 📦 NPM Package Published" >> $GITHUB_STEP_SUMMARY
134+ echo "" >> $GITHUB_STEP_SUMMARY
135+ echo "Package: \`@yourusername/template-mcp-server\`" >> $GITHUB_STEP_SUMMARY
136+ echo "Version: \`${{ github.event.release.tag_name || github.event.inputs.version }}\`" >> $GITHUB_STEP_SUMMARY
137+ echo "" >> $GITHUB_STEP_SUMMARY
138+ echo "### 🚀 Usage:" >> $GITHUB_STEP_SUMMARY
139+ echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
140+ echo "# Run with npx (no installation)" >> $GITHUB_STEP_SUMMARY
141+ echo "npx @yourusername/template-mcp-server --help" >> $GITHUB_STEP_SUMMARY
142+ echo "" >> $GITHUB_STEP_SUMMARY
143+ echo "# Or install globally" >> $GITHUB_STEP_SUMMARY
144+ echo "npm install -g @yourusername/template-mcp-server" >> $GITHUB_STEP_SUMMARY
145+ echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
146+
147+ build-platform-packages :
148+ name : Build Platform Packages
149+ needs : build-binaries
150+ runs-on : ubuntu-latest
151+ strategy :
152+ matrix :
153+ include :
154+ - target : aarch64-apple-darwin
155+ platform : darwin-arm64
156+ binary : template-mcp-server
157+ - target : x86_64-apple-darwin
158+ platform : darwin-x64
159+ binary : template-mcp-server
160+ - target : x86_64-unknown-linux-gnu
161+ platform : linux-x64
162+ binary : template-mcp-server
163+ - target : x86_64-pc-windows-msvc
164+ platform : win32-x64
165+ binary : template-mcp-server.exe
166+
167+ steps :
168+ - name : Checkout repository
169+ uses : actions/checkout@v4
170+
171+ - name : Setup Node.js
172+ uses : actions/setup-node@v4
173+ with :
174+ node-version : ' 18'
175+ registry-url : ' https://registry.npmjs.org'
176+
177+ - name : Download release asset
178+ env :
179+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
180+ run : |
181+ VERSION=${{ github.event.release.tag_name || github.event.inputs.version }}
182+ ARCHIVE_EXT=${{ matrix.target == 'x86_64-pc-windows-msvc' && 'zip' || 'tar.gz' }}
183+ ASSET_NAME="template-mcp-server-${VERSION}-${{ matrix.target }}.${ARCHIVE_EXT}"
184+
185+ # Download the release asset
186+ gh release download "${VERSION}" --pattern "${ASSET_NAME}" --dir ./temp
187+
188+ # Extract the binary
189+ cd temp
190+ if [[ "${ARCHIVE_EXT}" == "zip" ]]; then
191+ unzip "${ASSET_NAME}"
192+ else
193+ tar -xzf "${ASSET_NAME}"
194+ fi
195+
196+ # Move binary to platform package directory
197+ mv "${{ matrix.binary }}" "../platform-packages/${{ matrix.platform }}/"
198+
199+ - name : Update platform package version
200+ working-directory : platform-packages/${{ matrix.platform }}
201+ run : |
202+ VERSION=${{ github.event.release.tag_name || github.event.inputs.version }}
203+ # Remove 'v' prefix if present
204+ VERSION=${VERSION#v}
205+
206+ # Update platform package version
207+ jq --arg version "$VERSION" '.version = $version' package.json > package.json.tmp && mv package.json.tmp package.json
208+
209+ - name : Publish platform package
210+ working-directory : platform-packages/${{ matrix.platform }}
211+ run : npm publish --access public
212+ env :
213+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
214+
215+ - name : Clean up
216+ run : rm -rf temp
0 commit comments