Skip to content

Commit ad2b8a7

Browse files
authored
Configure 'release' (#92)
* Configure GoReleaser * Configure GHA for binary release * Update Makefile (mostly for linker flags) * Update 'version' and template in base command and root
1 parent 1b4d1c9 commit ad2b8a7

File tree

5 files changed

+129
-18
lines changed

5 files changed

+129
-18
lines changed

.github/workflows/release-binary.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Release Binary
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
goreleaser:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Set up Go (from go.mod)
21+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
22+
with:
23+
go-version-file: go.mod
24+
25+
- name: Run GoReleaser
26+
uses: goreleaser/goreleaser-action@9c156ee8a17a598857849441385a2041ef570552 # v6.3.0
27+
with:
28+
distribution: goreleaser
29+
version: latest
30+
args: release --clean
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.goreleaser.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
2+
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
3+
4+
version: 2
5+
6+
before:
7+
hooks:
8+
- go mod tidy
9+
- go generate ./...
10+
11+
builds:
12+
- env:
13+
- CGO_ENABLED=0
14+
goos:
15+
- linux
16+
- windows
17+
- darwin
18+
goarch:
19+
- amd64
20+
- arm64
21+
main: .
22+
binary: mcpd
23+
ldflags:
24+
- -s -w # Strip debug info and symbol table
25+
- -X 'github.com/mozilla-ai/mcpd/v2/internal/cmd.version={{.Version}}' # Bake in version
26+
- -X 'github.com/mozilla-ai/mcpd/v2/internal/cmd.commit={{.Commit}}' # Bake in commit hash
27+
- -X 'github.com/mozilla-ai/mcpd/v2/internal/cmd.date={{.Date}}' # Bake in build date
28+
flags:
29+
- -trimpath # Remove file system paths from binary
30+
archives:
31+
- formats: [tar.gz]
32+
# name template makes the OS and Arch compatible with the results of `uname`.
33+
name_template: >-
34+
{{ .ProjectName }}_
35+
{{- title .Os }}_
36+
{{- if eq .Arch "amd64" }}x86_64
37+
{{- else if eq .Arch "386" }}i386
38+
{{- else }}{{ .Arch }}{{ end }}
39+
{{- if .Arm }}v{{ .Arm }}{{ end }}
40+
# use zip for windows archives
41+
format_overrides:
42+
- goos: windows
43+
formats: [zip]
44+
45+
changelog:
46+
disable: true
47+
48+
release:
49+
replace_existing_draft: true
50+
draft: true
51+
prerelease: auto
52+
footer: >-
53+
54+
---
55+
56+
Released by [GoReleaser](https://github.com/goreleaser/goreleaser).

Makefile

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: build clean docs docs-cli docs-local docs-nav install test uninstall
1+
.PHONY: build build-dev build-linux build-linux-arm64 clean docs docs-cli docs-local docs-nav install local-down local-up test uninstall
22

33
MODULE_PATH := github.com/mozilla-ai/mcpd/v2
44

@@ -13,42 +13,58 @@ INSTALL_DIR := /usr/local/bin
1313
# - e.g., "dev" if git is not available or no commits yet
1414
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
1515

16-
# Linker flags for injecting version
16+
# Get commit hash and date
17+
COMMIT := $(shell git rev-parse HEAD 2>/dev/null || echo "unknown")
18+
DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
19+
20+
# Linker flags for injecting version and optimizations
1721
# The path is MODULE_PATH/package.variableName
18-
LDFLAGS := -X '$(MODULE_PATH)/internal/cmd.version=$(VERSION)'
22+
LDFLAGS := -s -w -X '$(MODULE_PATH)/internal/cmd.version=$(VERSION)' \
23+
-X '$(MODULE_PATH)/internal/cmd.commit=$(COMMIT)' \
24+
-X '$(MODULE_PATH)/internal/cmd.date=$(DATE)'
25+
26+
# Build flags for optimization
27+
BUILDFLAGS := -trimpath
1928

2029
test:
2130
go test ./...
2231

2332
build:
24-
@echo "building mcpd (with flags: ${LDFLAGS})..."
25-
@go build -o mcpd -ldflags="${LDFLAGS}" .
33+
@echo "building mcpd (version: $(VERSION), commit: $(COMMIT))..."
34+
@go build $(BUILDFLAGS) -o mcpd -ldflags="$(LDFLAGS)" .
2635

2736
build-linux:
28-
@echo "building mcpd for amd64/linux (with flags: ${LDFLAGS})..."
29-
@GOOS=linux GOARCH=amd64 go build -o mcpd -ldflags="${LDFLAGS}" .
37+
@echo "building mcpd for amd64/linux (version: $(VERSION), commit: $(COMMIT))..."
38+
@GOOS=linux GOARCH=amd64 go build $(BUILDFLAGS) -o mcpd -ldflags="$(LDFLAGS)" .
3039

3140
build-linux-arm64:
32-
@echo "building mcpd for arm64/linux (with flags: ${LDFLAGS})..."
33-
@GOOS=linux GOARCH=arm64 go build -o mcpd -ldflags="${LDFLAGS}" .
41+
@echo "building mcpd for arm64/linux (version: $(VERSION), commit: $(COMMIT))..."
42+
@GOOS=linux GOARCH=arm64 go build $(BUILDFLAGS) -o mcpd -ldflags="$(LDFLAGS)" .
43+
44+
# For development builds without optimizations (for debugging)
45+
build-dev:
46+
@echo "building mcpd for development (version: $(VERSION), commit: $(COMMIT))..."
47+
@go build -o mcpd -ldflags="-X '$(MODULE_PATH)/internal/cmd.version=$(VERSION)' \
48+
-X '$(MODULE_PATH)/internal/cmd.commit=$(COMMIT)' \
49+
-X '$(MODULE_PATH)/internal/cmd.date=$(DATE)'" .
3450

3551
install: build
3652
@# Copy the executable to the install directory
3753
@# Requires sudo if INSTALL_DIR is a system path like /usr/local/bin
54+
@echo "installing mcpd to $(INSTALL_DIR)..."
3855
@cp mcpd $(INSTALL_DIR)/mcpd
39-
@echo "mcpd installed to $(INSTALL_DIR)/mcpd"
56+
@chmod +x $(INSTALL_DIR)/mcpd
4057

4158
clean:
4259
@# Remove the built executable and any temporary files
60+
@echo "cleaning up local build artifacts..."
4361
@rm -f mcpd # The executable itself
44-
@# Add any other build artifacts here if they accumulate (e.g., cache files)
45-
@echo "build artifacts cleaned"
4662

4763
uninstall:
4864
@# Remove the installed executable from the system
4965
@# Requires sudo if INSTALL_DIR is a system path
66+
@echo "uninstalling mcpd from $(INSTALL_DIR)..."
5067
@rm -f $(INSTALL_DIR)/mcpd
51-
@echo "mcpd uninstalled from $(INSTALL_DIR)/mcpd"
5268

5369
# Runs MkDocs locally
5470
docs: docs-local

cmd/root.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ func NewRootCmd(c *RootCmd) (*cobra.Command, error) {
4646
"define their agent projects, and manage MCP server dependencies",
4747
SilenceUsage: true,
4848
SilenceErrors: true,
49-
Version: cmd.Version(),
5049
}
5150

51+
// Manually set the version template to prevent duplication in output.
52+
rootCmd.SetVersionTemplate("{{.Version}}\n")
53+
rootCmd.Version = cmd.Version()
54+
5255
// Configure app specific global flags that will appear on sub-commands.
5356
if err := flags.InitFlags(rootCmd.PersistentFlags()); err != nil {
5457
return nil, err

internal/cmd/basecmd.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ import (
1313
"github.com/mozilla-ai/mcpd/v2/internal/runtime"
1414
)
1515

16-
// version should not be moved/modified without consulting the Makefile,
17-
// as the path to this var is set on the LDFLAGS variable in the script.
18-
var version = "dev" // Set at build time using -ldflags
16+
var (
17+
// version should not be moved/modified without consulting the Makefile and GoReleaser config,
18+
// as the path to this var is set on the LDFLAGS variable in the script.
19+
version = "dev" // Set via ldflags
20+
commit = "unknown" // Set via ldflags
21+
date = "unknown" // Set via ldflags
22+
)
1923

2024
// Version is used by other packages to retrieve the build version of mcpd.
2125
func Version() string {
22-
return version
26+
return fmt.Sprintf("mcpd %s (%s), built %s", version, commit, date)
2327
}
2428

2529
// AppName returns the name of the mcpd application.

0 commit comments

Comments
 (0)