Skip to content

Commit

Permalink
embed version in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
hidetatz committed Aug 16, 2023
1 parent fb3eca6 commit 4ab52f6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

- name: build files
run: |
make
VERSION=${{ steps.version.outputs.ver }} make rel-build
tar -zcvf ${{ steps.version.outputs.ver }}.linux_amd64.tar.gz ./shiba
- uses: softprops/action-gh-release@v1
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ SRCS = $(shell find . -type f -name '*.go' -print)

$(BIN): $(SRCS) go.mod go.sum
go mod tidy
# go build -o $(BIN) $(SRCS) # for debug
go build -o $(BIN) -ldflags="-s -w" $(SRCS)
go build -o $(BIN) $(SRCS)

rel-build:
go mod tidy
go build -o $(BIN) -ldflags="-s -w -X main.version=$$VERSION" $(SRCS)

.PHONY: install
install:
Expand Down
8 changes: 6 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
)

const version = "v0.0.1"
var version string

func wout(f string, a ...any) {
fmt.Fprintf(os.Stdout, f+"\n", a...)
Expand Down Expand Up @@ -59,7 +59,11 @@ func run(args []string) int {
}

func showversion() {
fmt.Println(version)
if version != "" {
fmt.Println(version)
return
}
fmt.Println("unknown version")
}

func showhelp() {
Expand Down

0 comments on commit 4ab52f6

Please sign in to comment.