Skip to content

Commit 8d25961

Browse files
committed
auto versioning with goreleaser
1 parent 531f255 commit 8d25961

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

.github/workflows/goreleaser.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ jobs:
1313
uses: actions/checkout@v2
1414
with:
1515
fetch-depth: 0
16+
-
17+
name: Set outputs
18+
id: vars
19+
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
1620
-
1721
name: Set up Go
1822
uses: actions/setup-go@v2
@@ -27,3 +31,5 @@ jobs:
2731
args: release --rm-dist
2832
env:
2933
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
VERSION: ${{ github.event.release.tag_name }}
35+
COMMIT: ${{ steps.vars.outputs.sha_short }}

.goreleaser.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ builds:
55
- windows
66
- darwin
77
- linux
8+
ldflags:
9+
- -X github.com/base2Services/bastion-cli/entrypoint.Version={{.Env.VERSION}}
10+
- -X github.com/base2Services/bastion-cli/entrypoint.Build={{.Env.COMMIT}}
811
archives:
912
- format_overrides:
1013
- goos: windows

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
VERSION ?= latest
2+
GIT_COMMIT ?= $(shell git rev-parse --short HEAD)
3+
14
help:
25
echo "=== Download goreleaser from https://github.com/goreleaser/goreleaser/releases ===="
36
echo "=== Check https://goreleaser.com/ for alternative installation instructions ==== "
47
echo "make build - build bastion cli requires Go 1.15"
58
echo "make snapshot - create release binaries"
69

710
build:
8-
go build -o bin/bastion
11+
go build -o bin/bastion -ldflags "-X 'github.com/base2Services/bastion-cli/entrypoint.Version=$(VERSION)' -X 'github.com/base2Services/bastion-cli/entrypoint.Build=$(GIT_COMMIT)'"
912

10-
install:
11-
go build -o bastion && cp ./bastion /usr/local/bin/bastion
13+
install: build
14+
cp ./bin/bastion /usr/local/bin/bastion
1215

1316
snapshot:
1417
goreleaser --snapshot --rm-dist

entrypoint/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
package entrypoint
22

33
import (
4+
"fmt"
45
"log"
56
"os"
67

78
"github.com/base2Services/bastion-cli/bastion"
89
"github.com/urfave/cli/v2"
910
)
1011

12+
var Version = "latest"
13+
var Build = "build"
14+
1115
func CliMain() {
1216
app := &cli.App{
1317
Name: "bastion",
1418
Usage: "manage on-demand EC2 bastions",
15-
Version: "0.1.3",
19+
Version: fmt.Sprintf("%s_%s", Version, Build),
1620
Commands: []*cli.Command{
1721
{
1822
Name: "launch",

0 commit comments

Comments
 (0)