-
Notifications
You must be signed in to change notification settings - Fork 0
328 lines (281 loc) · 12.3 KB
/
release.yml
File metadata and controls
328 lines (281 loc) · 12.3 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
name: Build and Release Installers
on:
push:
tags:
- 'v*'
- '[0-9]+.[0-9]+.[0-9]+'
workflow_dispatch:
inputs:
version:
description: 'Version to build (e.g., 1.0.3 or v1.0.3)'
required: true
type: string
permissions:
contents: write
jobs:
build-windows:
name: Build Windows Installer
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Build Windows binary
run: |
go mod tidy
# Install goversioninfo for Windows version metadata
go install github.com/josephspurrier/goversioninfo/cmd/goversioninfo@latest
# Extract version number from tag (remove 'v' prefix)
# Debug: Show what ref_name we got
Write-Host "GitHub ref_name: ${{ github.ref_name }}"
Write-Host "GitHub ref: ${{ github.ref }}"
Write-Host "GitHub event_name: ${{ github.event_name }}"
$VERSION = "${{ github.ref_name }}" -replace '^v', ''
# Validate that we have a proper version format
if ($VERSION -notmatch '^\d+\.\d+\.\d+') {
Write-Host "ERROR: Invalid version format: $VERSION"
Write-Host "Expected format: X.Y.Z (e.g., 1.0.4)"
if ("${{ github.event_name }}" -eq "workflow_dispatch") {
$VERSION = "${{ github.event.inputs.version }}" -replace '^v', ''
Write-Host "Using workflow_dispatch version: $VERSION"
} else {
Write-Host "Extracting version from git tags..."
$VERSION = (git describe --tags --abbrev=0) -replace '^v', ''
Write-Host "Found version from git tags: $VERSION"
}
}
Write-Host "Using version: $VERSION"
$VERSION_PARTS = $VERSION -split '\.'
$MAJOR = if ($VERSION_PARTS.Length -gt 0 -and $VERSION_PARTS[0] -match '^\d+$') { $VERSION_PARTS[0] } else { "1" }
$MINOR = if ($VERSION_PARTS.Length -gt 1 -and $VERSION_PARTS[1] -match '^\d+$') { $VERSION_PARTS[1] } else { "0" }
$PATCH = if ($VERSION_PARTS.Length -gt 2 -and $VERSION_PARTS[2] -match '^\d+$') { $VERSION_PARTS[2] } else { "0" }
$BUILD = "0"
# Create versioninfo.json with format expected by goversioninfo
$versionInfo = @{
FixedFileInfo = @{
FileVersion = @{
Major = [int]$MAJOR
Minor = [int]$MINOR
Patch = [int]$PATCH
Build = [int]$BUILD
}
ProductVersion = @{
Major = [int]$MAJOR
Minor = [int]$MINOR
Patch = [int]$PATCH
Build = [int]$BUILD
}
FileFlagsMask = "3f"
FileFlags = "00"
FileOS = "040004"
FileType = "01"
FileSubType = "00"
}
StringFileInfo = @{
Comments = "TerminusAI CLI agent"
CompanyName = "TerminusAI"
FileDescription = "CLI AI agent that understands and executes tasks with your approval"
FileVersion = "$MAJOR.$MINOR.$PATCH.$BUILD"
InternalName = "terminusai"
LegalCopyright = "Copyright © 2024 TerminusAI"
LegalTrademarks = ""
OriginalFilename = "terminusai.exe"
PrivateBuild = ""
ProductName = "TerminusAI"
ProductVersion = "$MAJOR.$MINOR.$PATCH.$BUILD"
SpecialBuild = ""
}
VarFileInfo = @{
Translation = @{
LangID = "0409"
CharsetID = "04B0"
}
}
}
$versionInfo | ConvertTo-Json -Depth 10 | Set-Content versioninfo.json
# Debug: Show the generated versioninfo.json
Write-Host "Generated versioninfo.json:"
Get-Content versioninfo.json
# Generate version resource in the correct directory
goversioninfo -64=true
# Move resource.syso to cmd/terminusai directory where main.go is located
if (Test-Path "resource.syso") {
Move-Item "resource.syso" "cmd\terminusai\resource.syso" -Force
Write-Host "✓ resource.syso moved to cmd/terminusai directory"
$resourceSize = (Get-Item "cmd\terminusai\resource.syso").Length
Write-Host "Resource file size: $resourceSize bytes"
} else {
Write-Host "✗ resource.syso not found - version info may not be embedded"
}
# Extract version without 'v' prefix for build flags
$VERSION_NO_V = $VERSION
# Build with version info
go build -ldflags "-X 'terminusai/cmd/terminusai/commands.Version=$VERSION_NO_V' -X 'terminusai/cmd/terminusai/commands.BuildVersion=$VERSION_NO_V'" -o terminusai.exe ./cmd/terminusai
- name: Sign Windows binary
if: ${{ vars.ENABLE_SIGNING == 'true' }}
uses: dlemstra/code-sign-action@v1
with:
certificate: '${{ secrets.CERTIFICATE_BASE64 }}'
folder: '.'
recursive: false
files: |
terminusai.exe
- name: Build Windows Installer
run: |
# Extract version number from tag (remove 'v' prefix)
$VERSION = "${{ github.ref_name }}" -replace '^v', ''
# Build installer with correct version
& "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" "build\terminusai.iss" "/O+" "/DMyAppVersion=$VERSION"
- name: Sign Windows Installer
if: ${{ vars.ENABLE_SIGNING == 'true' }}
uses: dlemstra/code-sign-action@v1
with:
certificate: '${{ secrets.CERTIFICATE_BASE64 }}'
folder: 'build/Output'
recursive: false
files: |
*.exe
- name: Upload Windows Installer
uses: actions/upload-artifact@v4
with:
name: terminusai-windows-installer
path: build/Output/terminusai-setup.exe
build-macos:
name: Build macOS Binary
runs-on: macos-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Build macOS universal binary
run: |
go mod tidy
# Extract version for metadata
VERSION="${{ github.ref_name }}"
VERSION_NO_V="${VERSION#v}"
# Enhanced build flags with version metadata
BUILD_FLAGS="-X 'terminusai/cmd/terminusai/commands.Version=$VERSION' -X 'terminusai/cmd/terminusai/commands.BuildVersion=$VERSION_NO_V' -X 'terminusai/cmd/terminusai/commands.BuildDate=$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
# Build for Intel Macs
GOOS=darwin GOARCH=amd64 go build -ldflags "$BUILD_FLAGS" -o terminusai-amd64 ./cmd/terminusai
# Build for Apple Silicon
GOOS=darwin GOARCH=arm64 go build -ldflags "$BUILD_FLAGS" -o terminusai-arm64 ./cmd/terminusai
# Create universal binary
lipo -create -output terminusai-macos-universal terminusai-amd64 terminusai-arm64
# Set extended attributes for version info (macOS specific)
xattr -w com.apple.metadata:kMDItemVersion "$VERSION_NO_V" terminusai-macos-universal
xattr -w com.apple.metadata:kMDItemCopyright "Copyright © 2024 TerminusAI" terminusai-macos-universal
# macOS signing disabled - requires Apple Developer certificate
# - name: Sign macOS binary
# if: ${{ vars.ENABLE_SIGNING == 'true' && secrets.APPLE_CERTIFICATE_BASE64 != '' }}
# run: |
# echo "macOS signing requires Apple Developer certificate - skipped"
- name: Upload macOS Binary
uses: actions/upload-artifact@v4
with:
name: terminusai-macos-binary
path: terminusai-macos-universal
build-linux:
name: Build Linux Binary
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Build Linux binary
run: |
go mod tidy
# Extract version for metadata
VERSION="${{ github.ref_name }}"
VERSION_NO_V="${VERSION#v}"
BUILD_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)
# Enhanced build flags with version metadata and ELF section
BUILD_FLAGS="-X 'terminusai/cmd/terminusai/commands.Version=$VERSION' -X 'terminusai/cmd/terminusai/commands.BuildVersion=$VERSION_NO_V' -X 'terminusai/cmd/terminusai/commands.BuildDate=$BUILD_DATE' -s -w"
# Build Linux binary with version metadata
GOOS=linux GOARCH=amd64 go build -ldflags "$BUILD_FLAGS" -o terminusai-linux-amd64 ./cmd/terminusai
# Add version info to ELF binary using objcopy
echo "TerminusAI $VERSION_NO_V" > version.txt
echo "Build Date: $BUILD_DATE" >> version.txt
echo "Copyright © 2024 TerminusAI" >> version.txt
objcopy --add-section .version=version.txt terminusai-linux-amd64
rm version.txt
- name: Create Linux binary checksum and metadata
run: |
# Create SHA256 checksum for integrity verification
sha256sum terminusai-linux-amd64 > terminusai-linux-amd64.sha256
# Create metadata file with build information
cat > terminusai-linux-amd64.info << EOF
Binary: terminusai-linux-amd64
Version: ${{ github.ref_name }}
Architecture: linux/amd64
Build Date: $(date -u +%Y-%m-%dT%H:%M:%SZ)
Repository: ${{ github.repository }}
Commit: ${{ github.sha }}
EOF
echo "Linux binary checksum and metadata created:"
cat terminusai-linux-amd64.sha256
cat terminusai-linux-amd64.info
- name: Upload Linux Binary
uses: actions/upload-artifact@v4
with:
name: terminusai-linux-binary
path: |
terminusai-linux-amd64
terminusai-linux-amd64.sha256
terminusai-linux-amd64.info
create-release:
name: Create GitHub Release
needs: [build-windows, build-macos, build-linux]
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
- name: Extract version changelog
id: changelog
run: |
# Extract version number from tag (remove 'v' prefix)
VERSION="${{ github.ref_name }}"
VERSION_NO_V="${VERSION#v}"
# Extract changelog for this version from CHANGELOG.md
echo "Extracting changelog for version $VERSION_NO_V"
# Use awk to extract the section for this version
CHANGELOG_CONTENT=$(awk "
/^## \[$VERSION_NO_V\]/ { found=1; next }
/^## \[/ && found { exit }
found && /^$/ { if (content) print \"\" }
found && !/^$/ { content=1; print }
" CHANGELOG.md)
# If no specific version found, fall back to auto-generated notes
if [ -z "$CHANGELOG_CONTENT" ]; then
echo "No changelog found for version $VERSION_NO_V, using auto-generated notes"
echo "use_generated_notes=true" >> $GITHUB_OUTPUT
else
echo "Found changelog for version $VERSION_NO_V"
echo "use_generated_notes=false" >> $GITHUB_OUTPUT
# Save changelog to file for use in release
echo "$CHANGELOG_CONTENT" > version_changelog.md
echo "Changelog content:"
cat version_changelog.md
fi
- name: Create Release
uses: softprops/action-gh-release@v2
with:
files: |
terminusai-windows-installer/terminusai-setup.exe
terminusai-macos-binary/terminusai-macos-universal
terminusai-linux-binary/terminusai-linux-amd64
terminusai-linux-binary/terminusai-linux-amd64.sha256
terminusai-linux-binary/terminusai-linux-amd64.info
body_path: ${{ steps.changelog.outputs.use_generated_notes == 'true' && '' || 'version_changelog.md' }}
generate_release_notes: ${{ steps.changelog.outputs.use_generated_notes == 'true' }}