Skip to content

Commit 64966e1

Browse files
author
vcart
committed
chore: setup automation workflow for release and publish to npm
1 parent 573f66e commit 64966e1

2 files changed

Lines changed: 128 additions & 4 deletions

File tree

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Release and Publish
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version_type:
7+
description: 'Version type (prerelease, prepatch, patch, preminor, minor, premajor, major)'
8+
required: true
9+
default: 'patch'
10+
type: choice
11+
options:
12+
- prerelease
13+
- prepatch
14+
- patch
15+
- preminor
16+
- minor
17+
- premajor
18+
- major
19+
custom_version:
20+
description: 'Custom version (leave empty to use version_type)'
21+
required: false
22+
type: string
23+
dist_tag:
24+
description: 'npm distribution tag (latest, next, beta, etc)'
25+
required: false
26+
default: 'latest'
27+
type: string
28+
29+
jobs:
30+
release-and-publish:
31+
runs-on: ubuntu-latest
32+
permissions:
33+
contents: write
34+
packages: write
35+
id-token: write
36+
steps:
37+
- name: Checkout code
38+
uses: actions/checkout@v4
39+
with:
40+
fetch-depth: 0
41+
token: ${{ secrets.PAT_GITHUB }}
42+
43+
- name: Setup Node.js
44+
uses: actions/setup-node@v4
45+
with:
46+
node-version: '18.x'
47+
registry-url: 'https://registry.npmjs.org'
48+
49+
- name: Setup Bun
50+
uses: oven-sh/setup-bun@v1
51+
with:
52+
bun-version: latest
53+
54+
- name: Install dependencies
55+
run: bun install
56+
57+
- name: Configure Git
58+
run: |
59+
git config --local user.email "action@github.com"
60+
git config --local user.name "GitHub Action"
61+
git config pull.rebase false
62+
63+
- name: Bump version
64+
id: bump_version
65+
run: |
66+
if [ -n "${{ github.event.inputs.custom_version }}" ]; then
67+
echo "Using custom version ${{ github.event.inputs.custom_version }}"
68+
npm version ${{ github.event.inputs.custom_version }} --no-git-tag-version
69+
echo "VERSION=${{ github.event.inputs.custom_version }}" >> $GITHUB_ENV
70+
else
71+
echo "Bumping ${{ github.event.inputs.version_type }} version"
72+
NEW_VERSION=$(npm version ${{ github.event.inputs.version_type }} --no-git-tag-version)
73+
echo "VERSION=${NEW_VERSION:1}" >> $GITHUB_ENV
74+
fi
75+
echo "New version: ${{ env.VERSION }}"
76+
77+
- name: Generate Changelog
78+
run: |
79+
# Generate the full changelog
80+
npm run changelog
81+
# Generate release notes for just this version
82+
npm run changelog:latest
83+
84+
- name: Build project
85+
run: bun run build && bun run build:http
86+
87+
- name: Commit and push changes
88+
run: |
89+
git pull origin main --no-edit
90+
git add package.json CHANGELOG.md
91+
git commit -m "Bump version to v${{ env.VERSION }}"
92+
git push --force-with-lease
93+
94+
- name: Create and push tag
95+
run: |
96+
# Delete the tag if it already exists locally
97+
git tag -d "v${{ env.VERSION }}" 2>/dev/null || true
98+
# Delete the tag if it exists on the remote
99+
git push origin --delete "v${{ env.VERSION }}" 2>/dev/null || true
100+
# Create and push the new tag
101+
git tag -a "v${{ env.VERSION }}" -m "Release v${{ env.VERSION }}"
102+
git push origin "v${{ env.VERSION }}"
103+
104+
- name: Create GitHub Release
105+
uses: softprops/action-gh-release@v1
106+
with:
107+
tag_name: v${{ env.VERSION }}
108+
name: Release v${{ env.VERSION }}
109+
body_path: RELEASE_NOTES.md
110+
generate_release_notes: false
111+
env:
112+
GITHUB_TOKEN: ${{ secrets.PAT_GITHUB }}
113+
114+
- name: Publish to npm
115+
run: npm publish --access public --provenance --tag ${{ github.event.inputs.dist_tag || 'latest' }}
116+
env:
117+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

package.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@mcpdotdirect/template-mcp-server",
2+
"name": "@mcpdotdirect/create-mcp-server",
33
"module": "src/index.ts",
44
"type": "module",
55
"version": "1.0.0",
@@ -21,11 +21,17 @@
2121
"scripts": {
2222
"start": "bun run src/index.ts",
2323
"build": "bun build src/index.ts --outdir build --target node",
24-
"build:http": "bun build src/server/http-server.ts --outdir build --target node",
24+
"build:http": "bun build src/server/http-server.ts --outdir build --target node --outfile http-server.js",
2525
"dev": "bun --watch src/index.ts",
2626
"start:http": "bun run src/server/http-server.ts",
2727
"dev:http": "bun --watch src/server/http-server.ts",
28-
"prepublishOnly": "bun run build"
28+
"prepublishOnly": "bun run build && bun run build:http",
29+
"version:patch": "npm version patch",
30+
"version:minor": "npm version minor",
31+
"version:major": "npm version major",
32+
"release": "npm publish",
33+
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
34+
"changelog:latest": "conventional-changelog -p angular -r 1 > RELEASE_NOTES.md"
2935
},
3036
"repository": {
3137
"type": "git",
@@ -56,7 +62,8 @@
5662
"@types/bun": "latest",
5763
"@types/cors": "^2.8.17",
5864
"@types/express": "^5.0.0",
59-
"@types/node": "^20.17.24"
65+
"@types/node": "^20.17.24",
66+
"conventional-changelog-cli": "^5.0.0"
6067
},
6168
"peerDependencies": {
6269
"typescript": "^5.8.2"

0 commit comments

Comments
 (0)