Skip to content

Commit e40bebd

Browse files
committed
Update release workflow to extract version from tag and pass to build process
1 parent cb936e9 commit e40bebd

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

.github/workflows/release.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,15 @@ jobs:
4343
- name: Run unit tests
4444
run: make test-unit
4545

46+
- name: Extract version from tag
47+
id: version
48+
run: |
49+
TAG=${{ github.event.release.tag_name }}
50+
VERSION=${TAG#v}
51+
echo "version=$VERSION" >> $GITHUB_OUTPUT
52+
4653
- name: Build binaries
47-
run: make build
54+
run: make build VERSION=${{ steps.version.outputs.version }}
4855

4956
- name: Upload Linux binary
5057
uses: actions/upload-release-asset@v1

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@ build: imports build-linux build-darwin build-windows
4444

4545
## Build Linux binary.
4646
build-linux: imports
47-
cd cmd/tailor && GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -gcflags "all=-trimpath=$(CURDIR);$(shell go env GOPATH)" -o tailor-linux-amd64
47+
cd cmd/tailor && GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -gcflags "all=-trimpath=$(CURDIR);$(shell go env GOPATH)" -ldflags "-X main.Version=$(VERSION)" -o tailor-linux-amd64
4848
.PHONY: build-linux
4949

5050
## Build macOS binary.
5151
build-darwin: imports
52-
cd cmd/tailor && GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -gcflags "all=-trimpath=$(CURDIR);$(shell go env GOPATH)" -o tailor-darwin-amd64
52+
cd cmd/tailor && GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -gcflags "all=-trimpath=$(CURDIR);$(shell go env GOPATH)" -ldflags "-X main.Version=$(VERSION)" -o tailor-darwin-amd64
5353
.PHONY: build-darwin
5454

5555
## Build Windows binary.
5656
build-windows: imports
57-
cd cmd/tailor && GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -gcflags "all=-trimpath=$(CURDIR);$(shell go env GOPATH)" -o tailor-windows-amd64.exe
57+
cd cmd/tailor && GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -gcflags "all=-trimpath=$(CURDIR);$(shell go env GOPATH)" -ldflags "-X main.Version=$(VERSION)" -o tailor-windows-amd64.exe
5858
.PHONY: build-windows
5959

6060
internal/test/e2e/tailor-test: cmd/tailor/main.go go.mod go.sum pkg/cli/* pkg/commands/* pkg/openshift/* pkg/utils/*

cmd/tailor/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"github.com/opendevstack/tailor/pkg/commands"
1212
)
1313

14+
var Version = "dev"
15+
1416
var (
1517
app = kingpin.New(
1618
"tailor",
@@ -253,7 +255,7 @@ func main() {
253255
command := kingpin.MustParse(app.Parse(os.Args[1:]))
254256

255257
if command == versionCommand.FullCommand() {
256-
fmt.Println("1.3.4+master")
258+
fmt.Println(Version)
257259
return
258260
}
259261

0 commit comments

Comments
 (0)