-
Notifications
You must be signed in to change notification settings - Fork 6
314 lines (269 loc) · 9.94 KB
/
release.yml
File metadata and controls
314 lines (269 loc) · 9.94 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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
name: Release
on:
push:
tags:
- "v*.*.*" # triggers on v1.0.0, v0.2.1-beta, etc.
permissions:
contents: write # needed to create GitHub Releases, upload assets, and push formula updates
packages: write # needed to push to GHCR
pull-requests: write # needed to open the Homebrew formula PR
jobs:
source:
name: Prepare Source Tree
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Package source tree
run: tar --exclude='.git' -czf /tmp/source-tree.tar.gz .
- name: Upload source tree
uses: actions/upload-artifact@v4
with:
name: source-tree
path: /tmp/source-tree.tar.gz
retention-days: 1
# ── 1. Run tests before releasing ─────────────────────────────────────────
test:
name: Pre-release Tests
runs-on: ubuntu-latest
needs: [source]
steps:
- name: Download source tree
uses: actions/download-artifact@v4
with:
name: source-tree
path: /tmp/source
- name: Extract source tree
run: tar -xzf /tmp/source/source-tree.tar.gz -C "$GITHUB_WORKSPACE"
- uses: actions/setup-go@v5
with:
go-version: "1.26"
cache: true
- run: go test -race -count=1 ./...
# ── 2. Cross-compile binaries for all target platforms ────────────────────
build:
name: Build ${{ matrix.goos }}/${{ matrix.goarch }}
runs-on: ubuntu-latest
needs: [source, test]
strategy:
matrix:
include:
- goos: linux
goarch: amd64
- goos: linux
goarch: arm64
- goos: darwin
goarch: amd64
- goos: darwin
goarch: arm64
- goos: windows
goarch: amd64
steps:
- name: Download source tree
uses: actions/download-artifact@v4
with:
name: source-tree
path: /tmp/source
- name: Extract source tree
run: tar -xzf /tmp/source/source-tree.tar.gz -C "$GITHUB_WORKSPACE"
- uses: actions/setup-go@v5
with:
go-version: "1.26"
cache: true
- name: Set version from tag
run: echo "VERSION=${GITHUB_REF_NAME}" >> $GITHUB_ENV
- name: Build binaries
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: "0"
run: |
SUFFIX=""
if [ "${{ matrix.goos }}" = "windows" ]; then SUFFIX=".exe"; fi
mkdir -p dist
go build \
-ldflags "-X main.version=${VERSION} -s -w" \
-o "dist/tooltrust-scanner_${{ matrix.goos }}_${{ matrix.goarch }}${SUFFIX}" \
./cmd/tooltrust-scanner/
go build \
-ldflags "-X main.version=${VERSION} -s -w" \
-o "dist/tooltrust-mcp_${{ matrix.goos }}_${{ matrix.goarch }}${SUFFIX}" \
./cmd/tooltrust-mcp/
- name: Generate checksums
run: |
cd dist
sha256sum tooltrust-scanner_* tooltrust-mcp_* > checksums_${{ matrix.goos }}_${{ matrix.goarch }}.txt
- name: Upload binary artifacts
uses: actions/upload-artifact@v4
with:
name: binaries-${{ matrix.goos }}-${{ matrix.goarch }}
path: dist/
retention-days: 1
# ── 3. Create GitHub Release ───────────────────────────────────────────────
release:
name: GitHub Release
runs-on: ubuntu-latest
needs: [build]
steps:
- name: Download all binary artifacts
uses: actions/download-artifact@v4
with:
pattern: binaries-*
path: dist/
merge-multiple: true
- name: List release assets
run: ls -lh dist/
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
files: |
dist/tooltrust-scanner_*
dist/tooltrust-mcp_*
dist/checksums_*
# ── 4. Build and push Docker image to GHCR ────────────────────────────────
docker:
name: Docker Image
runs-on: ubuntu-latest
needs: [source, test]
steps:
- name: Download source tree
uses: actions/download-artifact@v4
with:
name: source-tree
path: /tmp/source
- name: Extract source tree
run: tar -xzf /tmp/source/source-tree.tar.gz -C "$GITHUB_WORKSPACE"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=latest
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
VERSION=${{ github.ref_name }}
# ── 5. Smoke Test Released Binaries ────────────────────────────────────────
smoke-test:
name: Smoke Test (${{ matrix.os }})
runs-on: ${{ matrix.os }}
needs: [release]
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
goos: linux
goarch: amd64
ext: ""
- os: macos-latest
goos: darwin
goarch: arm64
ext: ""
- os: windows-latest
goos: windows
goarch: amd64
ext: ".exe"
steps:
- name: Download binary artifacts
uses: actions/download-artifact@v4
with:
name: binaries-${{ matrix.goos }}-${{ matrix.goarch }}
path: dist/
- name: Make executable (Unix)
if: runner.os != 'Windows'
run: |
chmod +x dist/tooltrust-scanner_${{ matrix.goos }}_${{ matrix.goarch }}${{ matrix.ext }}
chmod +x dist/tooltrust-mcp_${{ matrix.goos }}_${{ matrix.goarch }}${{ matrix.ext }}
- name: Create Test JSON
shell: bash
run: |
mkdir -p testdata
cat << 'EOF' > testdata/tools.json
{
"tools": [
{
"name": "test_tool",
"description": "A simple test tool",
"inputSchema": { "type": "object", "properties": {} }
}
]
}
EOF
- name: Test Scanner CLI
shell: bash
run: |
BIN_PATH="dist/tooltrust-scanner_${{ matrix.goos }}_${{ matrix.goarch }}${{ matrix.ext }}"
# Try running a basic scan to ensure it doesn't crash
$BIN_PATH scan --input testdata/tools.json
- name: Test MCP Server
shell: bash
run: |
BIN_PATH="dist/tooltrust-mcp_${{ matrix.goos }}_${{ matrix.goarch }}${{ matrix.ext }}"
# Send a basic initialize request and check if it replies without crashing
echo '{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": {"name": "test", "version": "1.0.0"}}}' | $BIN_PATH
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Test NPM Wrapper
shell: bash
run: |
# Use npx to download and run the wrapper. We must use tooltrust-mcp
# Note: Since the release was just created, the binary is already available on GitHub.
npx -y tooltrust-mcp@latest --help
# ── 6. Update Homebrew Formula ─────────────────────────────────────────────
update-formula:
name: Update Homebrew Formula
runs-on: ubuntu-latest
needs: [release]
steps:
- uses: actions/checkout@v4
with:
ref: main
token: ${{ secrets.GITHUB_TOKEN }}
- name: Compute tarball SHA256
run: |
VERSION="${GITHUB_REF_NAME#v}"
URL="https://github.com/${{ github.repository }}/archive/refs/tags/${GITHUB_REF_NAME}.tar.gz"
SHA256=$(curl -sL "$URL" | shasum -a 256 | awk '{print $1}')
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "SHA256=$SHA256" >> $GITHUB_ENV
- name: Update Formula/tooltrust-scanner.rb
run: |
sed -i "s/version \".*\"/version \"${VERSION}\"/" Formula/tooltrust-scanner.rb
sed -i "s/sha256 \".*\"/sha256 \"${SHA256}\"/" Formula/tooltrust-scanner.rb
- name: Create PR for updated formula
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.TOOLTRUST_BOT_TOKEN || secrets.GITHUB_TOKEN }}
commit-message: "chore: update Homebrew formula to ${{ github.ref_name }}"
branch: "ci/update-homebrew-formula-${{ github.ref_name }}"
delete-branch: true
title: "Update Homebrew formula for ${{ github.ref_name }}"
body: |
Updates `Formula/tooltrust-scanner.rb` for release `${{ github.ref_name }}`.
- bumps the formula version
- refreshes the source tarball SHA256
add-paths: |
Formula/tooltrust-scanner.rb