Skip to content

Commit d88147c

Browse files
committed
chore: inject version to builds
Signed-off-by: Antonio Murdaca <[email protected]>
1 parent 48b54d7 commit d88147c

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

.packit.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ actions:
3737
- make vendor-tarball VERSION=${PACKIT_PROJECT_VERSION}
3838
create-archive:
3939
- make packit-create-archive VERSION=${PACKIT_PROJECT_VERSION}
40+
fix-spec-file:
41+
- bash -c "sed -i -r \"s/Version:(\s*)\S+/Version:\1${PACKIT_PROJECT_VERSION}%{?dist}/\" build/package/rpm/go-fdo-client.spec"
4042

4143
jobs:
4244
- &copr_fedora

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
COMMIT := $(shell git rev-parse --short HEAD)
22
DATE := $(shell date "+%Y%m%d")
3-
VERSION := git$(DATE).$(COMMIT)
43
PROJECT := go-fdo-client
54

65
SOURCEDIR := $(CURDIR)/build/package/rpm
76
SPEC_FILE_NAME := $(PROJECT).spec
87
SPEC_FILE := $(SOURCEDIR)/$(SPEC_FILE_NAME)
98
GO_VENDOR_TOOLS_FILE := $(SOURCEDIR)/go-vendor-tools.toml
109
GO_VENDOR_TOOLS_FILE_NAME := go-vendor-tools.toml
10+
VERSION ?= $(shell git describe --always --dirty --tags 2>/dev/null || echo "undefined")
1111

1212
SOURCE_TARBALL := $(SOURCEDIR)/$(PROJECT)-$(VERSION).tar.gz
1313
VENDOR_TARBALL := $(SOURCEDIR)/$(PROJECT)-$(VERSION)-vendor.tar.gz
@@ -17,7 +17,7 @@ VENDOR_TARBALL := $(SOURCEDIR)/$(PROJECT)-$(VERSION)-vendor.tar.gz
1717
all: build test
1818

1919
build: tidy fmt vet
20-
go build
20+
go build -ldflags="-X github.com/fido-device-onboard/go-fdo-client/internal/version/version.VERSION=${VERSION}"
2121

2222
tidy:
2323
go mod tidy
@@ -32,7 +32,7 @@ test:
3232
go test -v ./...
3333

3434
# Packit helpers
35-
.PHONY: vendor-tarball packit-create-archive vendor-licenses
35+
.PHONY: vendor-tarball packit-create-archive vendor-licenses render-specfile
3636

3737
vendor-tarball: $(VENDOR_TARBALL)
3838

@@ -81,6 +81,7 @@ RPMBUILD_SPECFILE := $(RPMBUILD_SPECS_DIR)/$(PROJECT)-$(VERSION)
8181
RPMBUILD_TARBALL := $(RPMBUILD_SOURCES_DIR)/$(PROJECT)-$(VERSION).tar.gz
8282
RPMBUILD_VENDOR_TARBALL := $(RPMBUILD_SOURCES_DIR)/$(PROJECT)-$(VERSION)-vendor.tar.gz
8383

84+
render-specfile: $(RPMBUILD_SPECFILE)
8485
# Render a versioned spec into ./rpmbuild/specs (keeps source spec pristine)
8586
$(RPMBUILD_SPECFILE):
8687
mkdir -p $(RPMBUILD_SPECS_DIR)

build/package/rpm/go-fdo-client.spec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
%global common_description %{expand:
99
go-fdo-client is the device-side implementation of FIDO Device Onboard
1010
specification in Go. It provides an FDO client that interacts with
11-
FDO manufacturer, rendezvous, and owner servers to perform device
12-
on-boarding.}
11+
FDO manufacturer and owner servers to perform device on-boarding.}
1312

1413
Name: go-fdo-client
1514
Version: 0
@@ -40,6 +39,7 @@ BuildRequires: golang
4039

4140
%build
4241
%global gomodulesmode GO111MODULE=on
42+
export LDFLAGS="-X %{goipath}/internal/version/version.VERSION=%{version}"
4343
%gobuild -o %{gobuilddir}/bin/go-fdo-client %{goipath}
4444

4545
%install

internal/version/version.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package version
2+
3+
var VERSION = "unknown"

0 commit comments

Comments
 (0)