Skip to content

Commit 590cef1

Browse files
committed
ci: add vscode publish job + release.sh script
1 parent d215cfa commit 590cef1

2 files changed

Lines changed: 140 additions & 22 deletions

File tree

.github/workflows/npm-publish.yml

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,36 @@
1-
name: Publish to npm + GitHub Packages
1+
name: Release
22

33
on:
44
push:
55
tags:
66
- 'v*'
77

88
permissions:
9-
contents: write # needed for creating GitHub Releases
10-
id-token: write # needed for npm provenance
11-
packages: write # needed for GitHub Packages
9+
contents: write # create GitHub Releases
10+
id-token: write # npm provenance
11+
packages: write # GitHub Packages
1212

1313
jobs:
14+
# ── 1. Gate: all tests must pass ─────────────────────────────────────────
1415
test:
15-
name: Run tests
16+
name: Test (Node 20)
1617
runs-on: ubuntu-latest
1718
steps:
1819
- uses: actions/checkout@v4
19-
20-
- name: Setup Node.js
21-
uses: actions/setup-node@v4
20+
- uses: actions/setup-node@v4
2221
with:
2322
node-version: '20'
24-
2523
- name: Run test suite
2624
run: node test/run.js
2725

26+
# ── 2. Publish to npmjs.com ───────────────────────────────────────────────
2827
publish-npm:
29-
name: Publish to npm
28+
name: Publish → npmjs.com
3029
needs: test
3130
runs-on: ubuntu-latest
3231
steps:
3332
- uses: actions/checkout@v4
34-
35-
- name: Setup Node.js
36-
uses: actions/setup-node@v4
33+
- uses: actions/setup-node@v4
3734
with:
3835
node-version: '20'
3936
registry-url: 'https://registry.npmjs.org'
@@ -46,31 +43,28 @@ jobs:
4643
echo "ERROR: package.json version ($PKG_VERSION) does not match tag ($TAG_VERSION)"
4744
exit 1
4845
fi
49-
echo "Version check passed: $PKG_VERSION"
46+
echo "✓ version check passed: $PKG_VERSION"
5047
5148
- name: Publish to npm
5249
run: npm publish --provenance --access public
5350
env:
5451
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
5552

53+
# ── 3. Publish to GitHub Packages (scoped) ───────────────────────────────
5654
publish-github:
57-
name: Publish to GitHub Packages
55+
name: Publish GitHub Packages
5856
needs: test
5957
runs-on: ubuntu-latest
6058
steps:
6159
- uses: actions/checkout@v4
62-
63-
- name: Setup Node.js
64-
uses: actions/setup-node@v4
60+
- uses: actions/setup-node@v4
6561
with:
6662
node-version: '20'
6763
registry-url: 'https://npm.pkg.github.com'
6864
scope: '@manojmallick'
6965

7066
- name: Publish to GitHub Packages
7167
run: |
72-
# GitHub Packages requires a scoped name — publish as @manojmallick/sigmap
73-
# without altering the canonical package.json (which stays as "sigmap" for npmjs.com)
7468
node -e "
7569
const fs = require('fs');
7670
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
@@ -82,13 +76,47 @@ jobs:
8276
env:
8377
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8478

79+
# ── 4. Publish VS Code extension ─────────────────────────────────────────
80+
publish-vscode:
81+
name: Publish → VS Code Marketplace
82+
needs: test
83+
runs-on: ubuntu-latest
84+
steps:
85+
- uses: actions/checkout@v4
86+
- uses: actions/setup-node@v4
87+
with:
88+
node-version: '20'
89+
90+
- name: Install vsce
91+
run: npm install -g @vscode/vsce
92+
93+
- name: Sync extension version with tag
94+
run: |
95+
TAG_VERSION="${GITHUB_REF_NAME#v}"
96+
node -e "
97+
const fs = require('fs');
98+
const v = process.env.TAG_VERSION;
99+
const pkg = JSON.parse(fs.readFileSync('vscode-extension/package.json', 'utf8'));
100+
pkg.version = v;
101+
fs.writeFileSync('vscode-extension/package.json', JSON.stringify(pkg, null, 2) + '\n');
102+
console.log('✓ extension version set to', v);
103+
"
104+
env:
105+
TAG_VERSION: ${{ github.ref_name }}
106+
107+
- name: Package and publish extension
108+
working-directory: vscode-extension
109+
run: vsce publish --no-dependencies
110+
env:
111+
VSCE_PAT: ${{ secrets.VSCE_PAT }}
112+
113+
# ── 5. Create GitHub Release (after all publishes succeed) ────────────────
85114
release:
86115
name: Create GitHub Release
87-
needs: [publish-npm, publish-github]
116+
needs: [publish-npm, publish-github, publish-vscode]
88117
runs-on: ubuntu-latest
89118
steps:
90119
- uses: actions/checkout@v4
91-
92120
- name: Create GitHub Release
93121
uses: softprops/action-gh-release@v2
94122
with:

scripts/release.sh

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env bash
2+
# Usage: ./scripts/release.sh 1.6.0
3+
#
4+
# Bumps version in all 3 places, commits, tags, and pushes.
5+
# The GitHub Actions pipeline handles the rest:
6+
# → npm publish (NPM_TOKEN secret)
7+
# → GitHub Packages publish (GITHUB_TOKEN — automatic)
8+
# → VS Code Marketplace publish (VSCE_PAT secret)
9+
# → GitHub Release (auto-generated notes)
10+
11+
set -euo pipefail
12+
13+
VERSION="${1:-}"
14+
15+
if [ -z "$VERSION" ]; then
16+
echo "Usage: ./scripts/release.sh <version> e.g. ./scripts/release.sh 1.6.0"
17+
exit 1
18+
fi
19+
20+
# Validate semver format
21+
if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
22+
echo "ERROR: version must be semver without a leading 'v', e.g. 1.6.0"
23+
exit 1
24+
fi
25+
26+
# Make sure the working tree is clean
27+
if ! git diff --quiet || ! git diff --cached --quiet; then
28+
echo "ERROR: working tree has uncommitted changes — commit or stash first"
29+
git status --short
30+
exit 1
31+
fi
32+
33+
echo "→ Releasing v$VERSION"
34+
35+
# 1. Bump package.json
36+
node -e "
37+
const fs = require('fs');
38+
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
39+
pkg.version = '$VERSION';
40+
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
41+
"
42+
echo " ✓ package.json"
43+
44+
# 2. Bump VERSION constant in gen-context.js
45+
sed -i.bak "s/const VERSION = '[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*'/const VERSION = '$VERSION'/" gen-context.js
46+
rm -f gen-context.js.bak
47+
echo " ✓ gen-context.js"
48+
49+
# 3. Bump MCP server version in src/mcp/server.js
50+
sed -i.bak "s/version: '[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*'/version: '$VERSION'/" src/mcp/server.js
51+
rm -f src/mcp/server.js.bak
52+
echo " ✓ src/mcp/server.js"
53+
54+
# 4. Rebuild bundle so gen-context.standalone.js stays in sync
55+
if [ -f scripts/bundle.js ]; then
56+
node scripts/bundle.js > /dev/null 2>&1 || true
57+
echo " ✓ bundle rebuilt"
58+
fi
59+
60+
# 5. Bump VS Code extension version
61+
node -e "
62+
const fs = require('fs');
63+
const pkg = JSON.parse(fs.readFileSync('vscode-extension/package.json', 'utf8'));
64+
pkg.version = '$VERSION';
65+
fs.writeFileSync('vscode-extension/package.json', JSON.stringify(pkg, null, 2) + '\n');
66+
"
67+
echo " ✓ vscode-extension/package.json"
68+
69+
# 6. Stage and commit
70+
git add package.json gen-context.js src/mcp/server.js vscode-extension/package.json
71+
# Include standalone bundle only if it is tracked (not in .gitignore)
72+
if git ls-files --error-unmatch gen-context.standalone.js > /dev/null 2>&1; then
73+
git add gen-context.standalone.js
74+
fi
75+
76+
git commit -m "chore: release v$VERSION"
77+
78+
# 7. Tag and push
79+
git tag "v$VERSION"
80+
git push
81+
git push origin "v$VERSION"
82+
83+
echo ""
84+
echo "✓ Tag v$VERSION pushed — pipeline is running:"
85+
echo " https://github.com/manojmallick/sigmap/actions"
86+
echo ""
87+
echo "Required GitHub Secrets (must be set before pipeline publishes):"
88+
echo " NPM_TOKEN — Automation token from npmjs.com/settings/tokens"
89+
echo " VSCE_PAT — PAT from dev.azure.com with Marketplace (Publish) scope"
90+
echo " GITHUB_TOKEN is automatic — no action needed"

0 commit comments

Comments
 (0)