-
Notifications
You must be signed in to change notification settings - Fork 18
403 lines (342 loc) · 13.6 KB
/
release.yml
File metadata and controls
403 lines (342 loc) · 13.6 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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
# Using [trusted publishing](https://docs.npmjs.com/trusted-publishers)
name: Release
on:
push:
branches:
- main
workflow_dispatch:
inputs:
version_bump:
description: "Version bump type"
required: true
type: choice
options:
- patch
- minor
- major
- dry-run
permissions:
contents: write
id-token: write
jobs:
check-pr-label:
name: Check PR Label
runs-on: ubuntu-latest
outputs:
has_label: ${{ steps.check.outputs.has_label }}
bump_type: ${{ steps.check.outputs.bump_type }}
is_dry_run: ${{ steps.check.outputs.is_dry_run }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for version label
id: check
run: |
# If manually triggered, use the input
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "bump_type=${{ inputs.version_bump }}" >> $GITHUB_OUTPUT
echo "has_label=true" >> $GITHUB_OUTPUT
echo "Manual trigger: using bump type ${{ inputs.version_bump }}"
# Set dry_run flag
if [ "${{ inputs.version_bump }}" = "dry-run" ]; then
echo "is_dry_run=true" >> $GITHUB_OUTPUT
else
echo "is_dry_run=false" >> $GITHUB_OUTPUT
fi
exit 0
fi
# For PR merges, not a dry run
echo "is_dry_run=false" >> $GITHUB_OUTPUT
# Get the PR number from the merge commit
PR_NUMBER=$(gh pr list --state merged --json number,mergeCommit --jq ".[] | select(.mergeCommit.oid == \"${{ github.sha }}\") | .number" | head -n 1)
if [ -z "$PR_NUMBER" ]; then
echo "Error: Could not find PR for commit ${{ github.sha }}"
echo "Direct pushes to main are not allowed. All changes must go through a PR with a version label (major, minor, or patch)."
exit 1
fi
# Get PR labels
LABELS=$(gh pr view "$PR_NUMBER" --json labels --jq '.labels[].name' | tr '\n' ' ')
echo "PR #$PR_NUMBER labels: $LABELS"
# Check if PR has a version label and set bump_type
if echo "$LABELS" | grep -qw "major"; then
echo "bump_type=major" >> $GITHUB_OUTPUT
echo "has_label=true" >> $GITHUB_OUTPUT
elif echo "$LABELS" | grep -qw "minor"; then
echo "bump_type=minor" >> $GITHUB_OUTPUT
echo "has_label=true" >> $GITHUB_OUTPUT
elif echo "$LABELS" | grep -qw "patch"; then
echo "bump_type=patch" >> $GITHUB_OUTPUT
echo "has_label=true" >> $GITHUB_OUTPUT
else
echo "Error: PR #$PR_NUMBER must have one of these labels: major, minor, patch"
echo "Current labels: $LABELS"
exit 1
fi
env:
GH_TOKEN: ${{ github.token }}
version:
name: Determine Version
needs: check-pr-label
if: needs.check-pr-label.outputs.is_dry_run != 'true'
runs-on: ubuntu-latest
outputs:
version: ${{ steps.bump.outputs.version }}
build_date: ${{ steps.info.outputs.build_date }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get last version from GitHub releases
id: last_version
run: |
# Try to get the latest release tag from GitHub
LAST_TAG=$(gh release list --limit 1 --json tagName --jq '.[0].tagName' 2>/dev/null || echo "")
if [ -z "$LAST_TAG" ]; then
# No releases yet, start at 0.0.0
LAST_VERSION="0.0.0"
else
# Remove 'v' prefix from tag
LAST_VERSION="${LAST_TAG#v}"
fi
echo "last_version=$LAST_VERSION" >> $GITHUB_OUTPUT
echo "Last published version: $LAST_VERSION"
env:
GH_TOKEN: ${{ github.token }}
- name: Bump version
id: bump
run: |
LAST_VERSION="${{ steps.last_version.outputs.last_version }}"
BUMP_TYPE="${{ needs.check-pr-label.outputs.bump_type }}"
# Parse version
IFS='.' read -r MAJOR MINOR PATCH <<< "$LAST_VERSION"
# Bump based on type
case "$BUMP_TYPE" in
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
;;
patch)
PATCH=$((PATCH + 1))
;;
esac
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version: $NEW_VERSION (bumped $BUMP_TYPE from $LAST_VERSION)"
- name: Get build info
id: info
run: |
echo "build_date=$(date -u +%Y-%m-%d)" >> $GITHUB_OUTPUT
build:
name: Build Binaries
needs: [check-pr-label, version]
if: always() && needs.check-pr-label.result == 'success'
# Use matrix to build on native runners for each platform because SQLite requires CGO,
# which needs platform-specific C compilers. Native builds are simpler than cross-compiling.
strategy:
matrix:
include:
- os: ubuntu-latest
targets: linux-amd64,linux-arm64
- os: macos-latest
targets: darwin-amd64,darwin-arm64
- os: windows-latest
targets: windows-amd64
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.24"
- name: Install cross-compilation tools
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
- name: Build Linux binaries
if: runner.os == 'Linux'
env:
VERSION: ${{ needs.check-pr-label.outputs.is_dry_run == 'true' && 'dry-run' || needs.version.outputs.version }}
BUILD_DATE: ${{ needs.check-pr-label.outputs.is_dry_run == 'true' && '2000-01-01' || needs.version.outputs.build_date }}
run: |
mkdir -p dist/linux-amd64 dist/linux-arm64
# Linux amd64 (static build for compatibility with any libc)
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 \
CGO_CFLAGS="-DSQLITE_ENABLE_FTS5" \
CGO_LDFLAGS="-lm" \
go build -ldflags "-X main.Version=${VERSION} -X main.BuildDate=${BUILD_DATE} -linkmode external -extldflags '-static'" \
-o dist/linux-amd64/github-brain
# Linux arm64 (static build for compatibility with any libc)
GOOS=linux GOARCH=arm64 CGO_ENABLED=1 CC=aarch64-linux-gnu-gcc \
CGO_CFLAGS="-DSQLITE_ENABLE_FTS5" \
CGO_LDFLAGS="-lm" \
go build -ldflags "-X main.Version=${VERSION} -X main.BuildDate=${BUILD_DATE} -linkmode external -extldflags '-static'" \
-o dist/linux-arm64/github-brain
- name: Build macOS binaries
if: runner.os == 'macOS'
env:
VERSION: ${{ needs.check-pr-label.outputs.is_dry_run == 'true' && 'dry-run' || needs.version.outputs.version }}
BUILD_DATE: ${{ needs.check-pr-label.outputs.is_dry_run == 'true' && '2000-01-01' || needs.version.outputs.build_date }}
run: |
mkdir -p dist/darwin-amd64 dist/darwin-arm64
# macOS amd64
GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 \
CGO_CFLAGS="-DSQLITE_ENABLE_FTS5" \
go build -ldflags "-X main.Version=${VERSION} -X main.BuildDate=${BUILD_DATE}" \
-o dist/darwin-amd64/github-brain
# macOS arm64
GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 \
CGO_CFLAGS="-DSQLITE_ENABLE_FTS5" \
go build -ldflags "-X main.Version=${VERSION} -X main.BuildDate=${BUILD_DATE}" \
-o dist/darwin-arm64/github-brain
- name: Build Windows binaries
if: runner.os == 'Windows'
env:
VERSION: ${{ needs.check-pr-label.outputs.is_dry_run == 'true' && 'dry-run' || needs.version.outputs.version }}
BUILD_DATE: ${{ needs.check-pr-label.outputs.is_dry_run == 'true' && '2000-01-01' || needs.version.outputs.build_date }}
shell: pwsh
run: |
New-Item -ItemType Directory -Force -Path dist/windows-amd64
$env:CGO_ENABLED = "1"
$env:CGO_CFLAGS = "-DSQLITE_ENABLE_FTS5"
go build -ldflags "-X main.Version=$env:VERSION -X main.BuildDate=$env:BUILD_DATE" -o dist/windows-amd64/github-brain.exe
- name: Create Linux archives
if: runner.os == 'Linux'
run: |
cd dist
tar -czf github-brain-linux-amd64.tar.gz -C linux-amd64 github-brain
tar -czf github-brain-linux-arm64.tar.gz -C linux-arm64 github-brain
rm -rf linux-amd64 linux-arm64
- name: Create macOS archives
if: runner.os == 'macOS'
run: |
cd dist
tar -czf github-brain-darwin-amd64.tar.gz -C darwin-amd64 github-brain
tar -czf github-brain-darwin-arm64.tar.gz -C darwin-arm64 github-brain
rm -rf darwin-amd64 darwin-arm64
- name: Create Windows archive
if: runner.os == 'Windows'
shell: pwsh
run: |
cd dist
Compress-Archive -Path windows-amd64/github-brain.exe -DestinationPath "github-brain-windows-amd64.zip"
Remove-Item -Recurse -Force windows-amd64
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: binaries-${{ runner.os }}
path: dist/*
retention-days: 1
release:
name: Create GitHub Release
needs: [check-pr-label, version, build]
if: needs.check-pr-label.outputs.is_dry_run != 'true'
runs-on: ubuntu-latest
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: dist
pattern: binaries-*
merge-multiple: true
- name: Generate checksums
run: |
cd dist
sha256sum * > SHA256SUMS.txt
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.version.outputs.version }}
name: v${{ needs.version.outputs.version }}
body: |
**Version:** ${{ needs.version.outputs.version }}
**Built:** ${{ needs.version.outputs.build_date }}
**Install via NPM:**
```bash
npm install -g github-brain
```
**Manual download:**
- macOS (Intel): `github-brain-darwin-amd64.tar.gz`
- macOS (Apple Silicon): `github-brain-darwin-arm64.tar.gz`
- Linux (x86_64): `github-brain-linux-amd64.tar.gz`
- Linux (ARM64): `github-brain-linux-arm64.tar.gz`
- Windows: `github-brain-windows-amd64.zip`
Verify with `SHA256SUMS.txt`
files: |
dist/*.tar.gz
dist/*.zip
dist/SHA256SUMS.txt
draft: false
prerelease: false
make_latest: true
publish-npm:
name: Publish to NPM
needs: [check-pr-label, version, build, release]
if: needs.check-pr-label.outputs.is_dry_run != 'true'
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "24"
registry-url: "https://registry.npmjs.org"
- name: Update npm to support trusted publishing
run: npm install -g npm@latest
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
pattern: binaries-*
- name: Prepare platform packages
run: |
VERSION="${{ needs.version.outputs.version }}"
echo "Preparing packages with version $VERSION"
# Extract binaries from archives and place in npm packages
cd artifacts
# macOS ARM64
mkdir -p ../npm/darwin-arm64
tar -xzf binaries-macOS/github-brain-darwin-arm64.tar.gz -C ../npm/darwin-arm64/
# macOS x64
mkdir -p ../npm/darwin-x64
tar -xzf binaries-macOS/github-brain-darwin-amd64.tar.gz -C ../npm/darwin-x64/
# Linux ARM64
mkdir -p ../npm/linux-arm64
tar -xzf binaries-Linux/github-brain-linux-arm64.tar.gz -C ../npm/linux-arm64/
# Linux x64
mkdir -p ../npm/linux-x64
tar -xzf binaries-Linux/github-brain-linux-amd64.tar.gz -C ../npm/linux-x64/
# Windows x64
mkdir -p ../npm/windows
unzip -j binaries-Windows/github-brain-windows-amd64.zip -d ../npm/windows/
cd ..
# Update version in all package.json files (using perl for cross-platform compatibility)
for pkg in package.json npm/*/package.json; do
perl -pi -e "s/\"version\": \"0\.0\.0\"/\"version\": \"$VERSION\"/" "$pkg"
done
# Update optionalDependencies versions in main package.json
perl -pi -e "s/\"github-brain-(darwin-arm64|darwin-x64|linux-arm64|linux-x64|windows)\": \"0\.0\.0\"/\"github-brain-\$1\": \"$VERSION\"/g" package.json
- name: Publish platform packages
run: |
for dir in npm/darwin-arm64 npm/darwin-x64 npm/linux-arm64 npm/linux-x64 npm/windows; do
cd "$dir"
npm publish
cd ../..
done
- name: Publish main package
run: npm publish