Skip to content

Commit ae300f3

Browse files
authored
Merge pull request #16 from securebuildhq/divolgin/set-release-versions
set release versions
2 parents e8cc51a + 6af1749 commit ae300f3

File tree

12 files changed

+86
-31
lines changed

12 files changed

+86
-31
lines changed

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

.github/workflows/release.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ jobs:
2525
cache: true
2626

2727
- name: Build worker (linux/amd64 and linux/arm64)
28-
run: make build-worker-release
28+
run: |
29+
export VERSION="${GITHUB_REF#refs/tags/v}"
30+
export GIT_SHA="${GITHUB_SHA}"
31+
make build-worker-release
2932
3033
- name: Stage worker binaries
3134
run: |
@@ -54,6 +57,11 @@ jobs:
5457
- name: Install dependencies
5558
run: cd securebuild-app && npm ci
5659

60+
- name: Set VERSION in build-info
61+
run: |
62+
VERSION="${GITHUB_REF#refs/tags/v}"
63+
sed -i "s/VERSION: string = \"0.0.0\"/VERSION: string = \"$VERSION\"/" securebuild-app/lib/build-info.ts
64+
5765
- name: Build
5866
run: cd securebuild-app && npm run build
5967
env:
@@ -91,6 +99,11 @@ jobs:
9199
- name: Install dependencies
92100
run: cd securebuild-www && npm ci
93101

102+
- name: Set VERSION in build-info
103+
run: |
104+
VERSION="${GITHUB_REF#refs/tags/v}"
105+
sed -i "s/VERSION: string = \"0.0.0\"/VERSION: string = \"$VERSION\"/" securebuild-www/lib/build-info.ts
106+
94107
- name: Build
95108
run: cd securebuild-www && npm run build
96109
env:

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ seurebuild-www/node_modules
66
node_modules
77
test-results
88
playwright-report
9-
.envrc
109
.direnv
1110
yarn.lock
1211
/data/

Makefile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ GO_MODULE_FILES := go.mod go.sum
3939
# Disable CGO for all Go builds to create static binaries
4040
export CGO_ENABLED=0
4141

42+
# Build version info (set at build time; release workflow overrides VERSION and GIT_SHA)
43+
VERSION_PACKAGE := github.com/securebuildhq/securebuild/pkg/buildversion
44+
VERSION ?= 0.0.0-dev
45+
GIT_SHA ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
46+
BUILD_TIME ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
47+
BUILD_LDFLAGS := -X $(VERSION_PACKAGE).version=$(VERSION) -X $(VERSION_PACKAGE).gitSHA=$(GIT_SHA) -X $(VERSION_PACKAGE).buildTime=$(BUILD_TIME)
48+
4249
.PHONY: migrate
4350
migrate:
4451
@echo "Running migrations..."
@@ -113,7 +120,7 @@ bin/worker: bin/builder-linux-amd64 bin/builder-linux-arm64 $(GO_SOURCES) $(GO_M
113120
@echo "Copying builder binaries for embedding..."
114121
cp bin/builder-linux-amd64 pkg/builder/builder-linux-amd64
115122
cp bin/builder-linux-arm64 pkg/builder/builder-linux-arm64
116-
go build -o bin/worker cmd/main.go
123+
go build -ldflags "$(BUILD_LDFLAGS)" -o bin/worker cmd/main.go
117124
@echo "Cleaning up copied builder binaries..."
118125
rm -f pkg/builder/builder-linux-amd64 pkg/builder/builder-linux-arm64
119126

@@ -122,14 +129,15 @@ build-worker: bin/worker
122129

123130
# Cross-compiled worker binaries for release (linux/amd64 and linux/arm64).
124131
# Embeds both builder binaries so the worker can build for either arch.
132+
# Set VERSION and GIT_SHA in CI (e.g. VERSION=1.2.3 GIT_SHA=abc1234 make build-worker-release).
125133
.PHONY: build-worker-release
126134
build-worker-release: bin/builder-linux-amd64 bin/builder-linux-arm64
127135
@echo "Building worker for linux/amd64..."
128136
cp bin/builder-linux-amd64 pkg/builder/builder-linux-amd64
129137
cp bin/builder-linux-arm64 pkg/builder/builder-linux-arm64
130-
GOOS=linux GOARCH=amd64 go build -o bin/securebuild-worker-linux-amd64 cmd/main.go
138+
GOOS=linux GOARCH=amd64 go build -ldflags "$(BUILD_LDFLAGS)" -o bin/securebuild-worker-linux-amd64 cmd/main.go
131139
@echo "Building worker for linux/arm64..."
132-
GOOS=linux GOARCH=arm64 go build -o bin/securebuild-worker-linux-arm64 cmd/main.go
140+
GOOS=linux GOARCH=arm64 go build -ldflags "$(BUILD_LDFLAGS)" -o bin/securebuild-worker-linux-arm64 cmd/main.go
133141
@echo "Cleaning up copied builder binaries..."
134142
rm -f pkg/builder/builder-linux-amd64 pkg/builder/builder-linux-arm64
135143

cmd/cli/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ func RootCmd() *cobra.Command {
1010
}
1111

1212
rootCmd.AddCommand(RunCmd())
13+
rootCmd.AddCommand(VersionCmd())
1314
rootCmd.AddCommand(OCIProxyCmd())
1415
rootCmd.AddCommand(APKProxyCmd())
1516
rootCmd.AddCommand(RebuildPackageCmd())

cmd/cli/version.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package cli
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/securebuildhq/securebuild/pkg/buildversion"
7+
"github.com/spf13/cobra"
8+
)
9+
10+
func VersionCmd() *cobra.Command {
11+
return &cobra.Command{
12+
Use: "version",
13+
Short: "Print version, git SHA, and build time",
14+
RunE: func(cmd *cobra.Command, args []string) error {
15+
fmt.Printf("version: %s\n", buildversion.Version())
16+
fmt.Printf("git SHA: %s\n", buildversion.GitSHA())
17+
fmt.Printf("build time: %s\n", buildversion.BuildTime())
18+
return nil
19+
},
20+
}
21+
}

pkg/buildversion/buildversion.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Package buildversion holds version, git SHA, and build time
2+
// set at build time via ldflags.
3+
package buildversion
4+
5+
var (
6+
version string
7+
gitSHA string
8+
buildTime string
9+
)
10+
11+
// Version returns the version string (e.g. "1.2.3" or "0.0.0-dev").
12+
func Version() string {
13+
if version == "" {
14+
return "0.0.0-dev"
15+
}
16+
return version
17+
}
18+
19+
// GitSHA returns the git commit SHA at build time.
20+
func GitSHA() string {
21+
if gitSHA == "" {
22+
return "unknown"
23+
}
24+
return gitSHA
25+
}
26+
27+
// BuildTime returns the build timestamp (UTC).
28+
func BuildTime() string {
29+
if buildTime == "" {
30+
return "unknown"
31+
}
32+
return buildTime
33+
}

securebuild-app/app/debug/page.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
"use client";
22

33
import React from "react";
4-
import { DEPLOY_TIME, VERSION } from "@/lib/build-info";
5-
6-
// Constants for deployment time and version (these will be written during the build process)
7-
8-
// BEGIN AUTOMATED REPLACE
9-
// const DEPLOY_TIME: string = "UNKNOWN";
10-
// const VERSION: string = "0.0.0";
11-
// END AUTOMATED REPLACE
4+
import { VERSION } from "@/lib/build-info";
125

136
export default function DebugPage() {
147
return (
@@ -26,10 +19,6 @@ export default function DebugPage() {
2619
</tr>
2720
</thead>
2821
<tbody>
29-
<tr>
30-
<td className="px-4 py-2 border-b border-border">DEPLOY_TIME (UTC)</td>
31-
<td className="px-4 py-2 border-b border-border">{DEPLOY_TIME}</td>
32-
</tr>
3322
<tr>
3423
<td className="px-4 py-2 border-b">VERSION</td>
3524
<td className="px-4 py-2 border-b">{VERSION}</td>

securebuild-app/components/dashboard-sidebar.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import Link from "next/link"
44
import { usePathname } from "next/navigation"
55
import { LayoutDashboard, Rocket, Package, Image, Users, Users2, CreditCard, FolderTree, FileCode, Shield, FileSearch } from "lucide-react"
6-
import { DEPLOY_TIME, VERSION } from "@/lib/build-info";
6+
import { VERSION } from "@/lib/build-info";
77

88
export default function DashboardSidebar() {
99
const pathname = usePathname()
@@ -186,7 +186,6 @@ export default function DashboardSidebar() {
186186
</div>
187187
<div className="p-4 mt-auto border-t border-zinc-200 dark:border-zinc-700">
188188
<p className="text-xs text-zinc-500 dark:text-zinc-400">Version: {VERSION}</p>
189-
<p className="text-xs text-zinc-500 dark:text-zinc-400">Deployed: {DEPLOY_TIME}</p>
190189
</div>
191190
</div>
192191
)

securebuild-app/lib/build-info.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
// BEGIN AUTOMATED REPLACE
2-
export const DEPLOY_TIME: string = "UNKNOWN";
32
export const VERSION: string = "0.0.0";
43
// END AUTOMATED REPLACE

0 commit comments

Comments
 (0)