Skip to content

Commit 7bd85f2

Browse files
authored
Merge pull request #3 from user-cube/build-version
Update build information
2 parents 06a453d + e7373ee commit 7bd85f2

3 files changed

Lines changed: 36 additions & 5 deletions

File tree

.github/workflows/release.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,25 @@ jobs:
2828

2929
- name: Extract version from tag
3030
id: extract_version
31-
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
31+
run: |
32+
# Extract version from tag (remove 'v' prefix if present)
33+
TAG=${GITHUB_REF#refs/tags/}
34+
VERSION=${TAG#v}
35+
echo "VERSION=${VERSION}" >> $GITHUB_ENV
36+
echo "Using version: ${VERSION}"
37+
38+
- name: Set build variables
39+
id: build_vars
40+
run: |
41+
# Get the short commit hash
42+
COMMIT_SHA=$(git rev-parse --short HEAD)
43+
echo "COMMIT_SHA=${COMMIT_SHA}" >> $GITHUB_ENV
44+
echo "Using commit: ${COMMIT_SHA}"
45+
46+
# Set build date in ISO 8601 format
47+
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
48+
echo "BUILD_DATE=${BUILD_DATE}" >> $GITHUB_ENV
49+
echo "Using build date: ${BUILD_DATE}"
3250
3351
# More assembly might be required: Docker logins, GPG, etc.
3452
# It all depends on your needs.
@@ -42,7 +60,9 @@ jobs:
4260
args: release --clean
4361
env:
4462
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45-
# Pass the extracted version to GoReleaser
63+
# Pass the build variables to GoReleaser
4664
VERSION: ${{ env.VERSION }}
65+
GIT_COMMIT: ${{ env.COMMIT_SHA }}
66+
BUILD_DATE: ${{ env.BUILD_DATE }}
4767
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution
4868
# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}

Makefile

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ release: clean
4545
echo "Error: goreleaser not found. Install with 'go install github.com/goreleaser/goreleaser@latest'"; \
4646
exit 1; \
4747
fi
48-
@VERSION=$(VERSION) goreleaser release --clean
48+
@VERSION=$(VERSION) GIT_COMMIT=$(COMMIT) BUILD_DATE=$(BUILD_DATE) goreleaser release --clean
4949

5050
.PHONY: release-snapshot
5151
release-snapshot: clean
@@ -54,7 +54,17 @@ release-snapshot: clean
5454
echo "Error: goreleaser not found. Install with 'go install github.com/goreleaser/goreleaser@latest'"; \
5555
exit 1; \
5656
fi
57-
@VERSION=$(VERSION) goreleaser release --snapshot --clean
57+
@VERSION=$(VERSION) GIT_COMMIT=$(COMMIT) BUILD_DATE=$(BUILD_DATE) goreleaser release --snapshot --clean
58+
59+
.PHONY: build-release
60+
build-release: clean
61+
@echo "Building release version of kontext $(VERSION) ($(COMMIT))"
62+
@go build $(LDFLAGS) -o kontext main.go
63+
@echo "Built kontext binary with release information"
64+
@echo "Version: $(VERSION)"
65+
@echo "Commit: $(COMMIT)"
66+
@echo "Build Date: $(BUILD_DATE)"
67+
@echo "Run ./kontext version to verify"
5868

5969
.PHONY: help
6070
help:
@@ -69,4 +79,5 @@ help:
6979
@echo " lint - Run linters (requires golangci-lint)"
7080
@echo " release - Create a full release using GoReleaser"
7181
@echo " release-snapshot - Create a local release snapshot for testing (no publish)"
82+
@echo " build-release - Build kontext binary with release information"
7283
@echo " help - Show this help message"

goreleaser.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ builds:
1414
- env:
1515
- CGO_ENABLED=0
1616
ldflags:
17-
- -s -w -X github.com/user-cube/kontext/cmd.Version={{ .Env.VERSION }} -X github.com/user-cube/kontext/cmd.GitCommit={{.ShortCommit}} -X github.com/user-cube/kontext/cmd.BuildDate={{.Date}}
17+
- -s -w -X github.com/user-cube/kontext/cmd.Version={{ .Env.VERSION }} -X github.com/user-cube/kontext/cmd.GitCommit={{ .Env.GIT_COMMIT }} -X github.com/user-cube/kontext/cmd.BuildDate={{ .Env.BUILD_DATE }}
1818
goos:
1919
- linux
2020
- darwin

0 commit comments

Comments
 (0)