-
Notifications
You must be signed in to change notification settings - Fork 0
299 lines (289 loc) · 9.88 KB
/
Copy pathrelease.yml
File metadata and controls
299 lines (289 loc) · 9.88 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
name: Release
on:
workflow_call:
inputs:
release_tag:
description: Tag to build and publish
required: true
type: string
publish_github_release:
description: Publish the GitHub release and its assets
required: false
default: true
type: boolean
workflow_dispatch:
inputs:
release_tag:
description: Existing tag to build and publish
required: true
type: string
publish_github_release:
description: Publish the GitHub release and its assets
required: false
default: true
type: boolean
permissions:
contents: read
concurrency:
group: release-${{ inputs.release_tag || github.ref_name }}
cancel-in-progress: false
jobs:
validate:
name: Validate release commit
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v6
with:
ref: ${{ inputs.release_tag || github.ref_name }}
- uses: actions/setup-go@v7
with:
go-version-file: go.mod
cache: true
cache-dependency-path: go.sum
- uses: actions/setup-node@v7
with:
node-version: 22
- run: go test ./...
- run: go vet ./...
- run: test -z "$(gofmt -l .)"
- name: Verify release version
shell: bash
env:
VERSION: ${{ inputs.release_tag || github.ref_name }}
run: node scripts/verify-release-version.mjs "${VERSION#v}"
- run: npm run test:npm
build-npm-binaries:
name: Build npm binary ${{ matrix.target }}
needs: [validate, platform_matrix]
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.platform_matrix.outputs.matrix) }}
steps:
- uses: actions/checkout@v6
with:
ref: ${{ inputs.release_tag || github.ref_name }}
- uses: actions/setup-go@v7
with:
go-version-file: go.mod
cache: true
cache-dependency-path: go.sum
- name: Build native binary
shell: bash
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: "0"
TARGET: ${{ matrix.target }}
BINARY: ${{ matrix.binary }}
VERSION: ${{ inputs.release_tag || github.ref_name }}
run: |
mkdir -p "dist/$TARGET"
go build -trimpath -ldflags "-s -w -X main.version=${VERSION#v}" -o "dist/$TARGET/$BINARY" ./cmd/gitcontribute
- uses: actions/upload-artifact@v7
with:
name: native-${{ matrix.target }}
path: dist/${{ matrix.target }}/${{ matrix.binary }}
if-no-files-found: error
platform_matrix:
name: Derive npm release targets
needs: validate
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
matrix: ${{ steps.platforms.outputs.matrix }}
steps:
- uses: actions/checkout@v6
with:
ref: ${{ inputs.release_tag || github.ref_name }}
- uses: actions/setup-node@v7
with:
node-version: 22
- id: platforms
shell: bash
run: echo "matrix=$(node scripts/release-platform-matrix.mjs)" >> "$GITHUB_OUTPUT"
goreleaser:
name: Build and release
needs: validate
if: inputs.publish_github_release
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: write
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ inputs.release_tag || github.ref_name }}
- uses: actions/setup-go@v7
with:
go-version-file: go.mod
cache: true
cache-dependency-path: go.sum
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v7
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-npm:
name: Publish npm package
needs: [validate, build-npm-binaries, goreleaser]
if: >-
always() &&
needs.validate.result == 'success' &&
needs.build-npm-binaries.result == 'success' &&
(needs.goreleaser.result == 'success' || needs.goreleaser.result == 'skipped')
runs-on: ubuntu-latest
timeout-minutes: 20
environment: npm
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v6
with:
ref: ${{ inputs.release_tag || github.ref_name }}
- uses: actions/setup-node@v7
with:
node-version: 22
registry-url: https://registry.npmjs.org
- run: npm install --global npm@11.15.0
- uses: actions/download-artifact@v8
with:
pattern: native-*
path: dist
- name: Normalize downloaded artifact layout
shell: bash
run: |
for directory in dist/native-*; do
target=${directory##*/native-}
mkdir -p "dist/$target"
cp "$directory"/* "dist/$target/"
if [[ $target != win32-* ]]; then chmod +x "dist/$target/gitcontribute"; fi
done
- name: Verify release version
shell: bash
env:
VERSION: ${{ inputs.release_tag || github.ref_name }}
run: node scripts/verify-release-version.mjs "${VERSION#v}"
- run: npm run test:npm
- run: npm run build:npm
- name: Build and inspect npm tarball
shell: bash
env:
VERSION: ${{ inputs.release_tag || github.ref_name }}
run: |
npm pack --pack-destination dist
tarball=$(find dist -maxdepth 1 -name 'gitcontribute-*.tgz' -print -quit)
test -n "$tarball"
test "$(stat -c %s "$tarball")" -le 100000000
sha256sum "$tarball" | sed 's# dist/# #' > dist/npm-SHA256SUMS
npm install --prefix "$RUNNER_TEMP/npm-smoke" --ignore-scripts --no-audit --no-fund "$(realpath "$tarball")"
metadata=$("$RUNNER_TEMP/npm-smoke/node_modules/.bin/gitcontribute" metadata --json)
EXPECTED_VERSION="${VERSION#v}" node -e '
const expected = process.env.EXPECTED_VERSION;
let input = "";
process.stdin.setEncoding("utf8");
process.stdin.on("data", chunk => { input += chunk; });
process.stdin.on("end", () => {
const actual = JSON.parse(input).version;
if (actual !== expected) {
throw new Error(`packed binary version ${actual} does not match release ${expected}`);
}
});
' <<<"$metadata"
- name: Publish npm package
run: npm publish --provenance --access public
- name: Verify npm publication is publicly discoverable
shell: bash
env:
VERSION: ${{ inputs.release_tag || github.ref_name }}
run: node scripts/verify-npm-publication.mjs "${VERSION#v}"
- name: Attach npm package to GitHub release
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ inputs.release_tag || github.ref_name }}
shell: bash
run: |
tarball=$(find dist -maxdepth 1 -name 'gitcontribute-*.tgz' -print -quit)
gh release upload "$RELEASE_TAG" "$tarball" dist/npm-SHA256SUMS --clobber
publish-mcp-registry:
name: Publish MCP Registry metadata
needs: [validate, publish-npm]
if: >-
always() &&
needs.validate.result == 'success' &&
needs.publish-npm.result == 'success'
runs-on: ubuntu-latest
timeout-minutes: 10
environment: mcp-registry-publish
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v6
with:
ref: ${{ inputs.release_tag || github.ref_name }}
- name: Verify release version
shell: bash
env:
VERSION: ${{ inputs.release_tag || github.ref_name }}
run: node scripts/verify-release-version.mjs "${VERSION#v}"
- name: Set released version in server metadata
shell: bash
env:
VERSION: ${{ inputs.release_tag || github.ref_name }}
run: |
version="${VERSION#v}"
jq --arg version "$version" '.version = $version | .packages |= map(.version = $version)' server.json > server.json.tmp
mv server.json.tmp server.json
node scripts/verify-mcp-registry.mjs "$version"
- name: Install mcp-publisher
shell: bash
run: |
curl --fail --location --silent --show-error \
--output mcp-publisher.tar.gz \
https://github.com/modelcontextprotocol/registry/releases/download/v1.8.0/mcp-publisher_linux_amd64.tar.gz
echo "1370446bbe74d562608e8005a6ccce02d146a661fbd78674e11cc70b9618d6cf mcp-publisher.tar.gz" | sha256sum --check
tar --extract --gzip --file mcp-publisher.tar.gz mcp-publisher
chmod +x mcp-publisher
- name: Validate metadata with mcp-publisher
run: ./mcp-publisher validate server.json
- name: Authenticate to MCP Registry
run: ./mcp-publisher login github-oidc
- name: Publish server to MCP Registry
run: ./mcp-publisher publish
release-notes:
name: Generate release notes
runs-on: ubuntu-latest
timeout-minutes: 5
needs: [goreleaser, publish-npm]
if: >-
always() &&
needs.goreleaser.result == 'success' &&
needs.publish-npm.result == 'success'
permissions:
contents: write
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ inputs.release_tag || github.ref_name }}
- name: Generate changelog
uses: orhun/git-cliff-action@v4
with:
config: cliff.toml
args: --latest --strip all
env:
OUTPUT: CHANGELOG.md
- name: Upload release notes
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ inputs.release_tag }}
body_path: CHANGELOG.md
generate_release_notes: true