-
Notifications
You must be signed in to change notification settings - Fork 42
199 lines (178 loc) · 6.81 KB
/
Copy pathnpm-publish.yml
File metadata and controls
199 lines (178 loc) · 6.81 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
name: Release
on:
push:
tags:
- 'v*'
permissions:
contents: write # create GitHub Releases
id-token: write # npm provenance
packages: write # GitHub Packages
jobs:
# ── 1. Gate: all tests must pass ─────────────────────────────────────────
test:
name: Test (Node 20)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Run test suite
run: node test/run.js
# ── 2. Publish to npmjs.com ───────────────────────────────────────────────
publish-npm:
name: Publish → npmjs.com
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Verify package version matches tag
run: |
PKG_VERSION="v$(node -p "require('./package.json').version")"
TAG_VERSION="${GITHUB_REF_NAME}"
if [ "$PKG_VERSION" != "$TAG_VERSION" ]; then
echo "ERROR: package.json version ($PKG_VERSION) does not match tag ($TAG_VERSION)"
exit 1
fi
echo "✓ version check passed: $PKG_VERSION"
- name: Publish to npm
run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# ── 3. Publish to GitHub Packages (scoped) ───────────────────────────────
publish-github:
name: Publish → GitHub Packages
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://npm.pkg.github.com'
scope: '@manojmallick'
- name: Publish to GitHub Packages
run: |
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
pkg.name = '@manojmallick/sigmap';
pkg.publishConfig = { registry: 'https://npm.pkg.github.com' };
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
"
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ── 4. Publish VS Code extension ─────────────────────────────────────────
publish-vscode:
name: Publish → VS Code Marketplace
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install vsce
run: npm install -g @vscode/vsce
- name: Sync extension version with tag
run: |
TAG_VERSION="${GITHUB_REF_NAME#v}"
node -e "
const fs = require('fs');
const v = process.env.TAG_VERSION;
const pkg = JSON.parse(fs.readFileSync('vscode-extension/package.json', 'utf8'));
pkg.version = v;
fs.writeFileSync('vscode-extension/package.json', JSON.stringify(pkg, null, 2) + '\n');
console.log('✓ extension version set to', v);
"
env:
TAG_VERSION: ${{ github.ref_name }}
- name: Package and publish extension
working-directory: vscode-extension
run: |
vsce publish --no-dependencies 2>&1 | tee /tmp/vsce-out.txt
EXIT=${PIPESTATUS[0]}
if [ $EXIT -ne 0 ] && grep -q "already exists" /tmp/vsce-out.txt; then
echo "✓ Version already on Marketplace — skipping (not an error)"
exit 0
fi
exit $EXIT
env:
VSCE_PAT: ${{ secrets.VSCE_PAT }}
# ── 5. Publish to Open VSX Registry ──────────────────────────────────────
publish-openvsx:
name: Publish → Open VSX Registry
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install ovsx
run: npm install -g ovsx
- name: Sync extension version with tag
run: |
TAG_VERSION="${GITHUB_REF_NAME#v}"
node -e "
const fs = require('fs');
const v = process.env.TAG_VERSION;
const pkg = JSON.parse(fs.readFileSync('vscode-extension/package.json', 'utf8'));
pkg.version = v;
fs.writeFileSync('vscode-extension/package.json', JSON.stringify(pkg, null, 2) + '\n');
console.log('✓ extension version set to', v);
"
env:
TAG_VERSION: ${{ github.ref_name }}
- name: Package extension (.vsix)
working-directory: vscode-extension
run: |
npm install -g @vscode/vsce
vsce package --no-dependencies
- name: Publish to Open VSX
working-directory: vscode-extension
run: |
VSIX_FILE=$(ls *.vsix | head -1)
ovsx publish "$VSIX_FILE" --pat "$OVSX_PAT" 2>&1 | tee /tmp/ovsx-out.txt
EXIT=${PIPESTATUS[0]}
if [ $EXIT -ne 0 ] && grep -q "already exists" /tmp/ovsx-out.txt; then
echo "✓ Version already on Open VSX — skipping (not an error)"
exit 0
fi
exit $EXIT
env:
OVSX_PAT: ${{ secrets.OVSX_PAT }}
# ── 6. Create GitHub Release (after all publishes succeed) ────────────────
release:
name: Create GitHub Release
needs: [publish-npm, publish-github, publish-vscode, publish-openvsx]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Build .vsix for release attachment
run: |
npm install -g @vscode/vsce
TAG_VERSION="${GITHUB_REF_NAME#v}"
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('vscode-extension/package.json', 'utf8'));
pkg.version = process.env.TAG_VERSION;
fs.writeFileSync('vscode-extension/package.json', JSON.stringify(pkg, null, 2) + '\n');
"
cd vscode-extension && vsce package --no-dependencies
env:
TAG_VERSION: ${{ github.ref_name }}
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
make_latest: true
files: vscode-extension/*.vsix