Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

Commit

Permalink
Merge pull request #6 from korosuke613/set-version
Browse files Browse the repository at this point in the history
fix: the problem of version not being displayed
  • Loading branch information
korosuke613 authored Mar 23, 2021
2 parents bb9ad7f + 95c5e5a commit 608da45
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.5.7/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'"
- name: +release
run: earthly --secret GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} --ci --use-inline-cache --push +release
Expand Down
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ builds:
- windows
- darwin
ldflags:
- "-s -w -X \"github.com/korosuke613/tempura/cmd.version={{.Version}}\" -X \"github.com/korosuke613/tempura/cmd.commit={{.ShortCommit}}\" -X \"github.com/korosuke613/tempura/cmd.date={{.Date}}\""
- "-s -w -X \"github.com/korosuke613/tempura/cmd.version={{.Version}}\" "
archives:
- replacements:
darwin: Darwin
Expand Down
7 changes: 6 additions & 1 deletion Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ lint:
build:
FROM +deps

RUN go build -o build/tempura ./main.go
COPY .git ./.git
RUN export VERSION=$(git tag | tail -1) \
&& go build -o build/tempura \
-ldflags "-s -w -X \"github.com/korosuke613/tempura/cmd.version=$VERSION\" " \
./main.go
RUN ./build/tempura -v
SAVE ARTIFACT build/tempura /tempura AS LOCAL build/tempura

goreleaser-setup:
Expand Down
18 changes: 14 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import (
"github.com/korosuke613/tempura/lib"
"github.com/spf13/cobra"
"os"
"runtime/debug"
)

var (
version = "dev"
commit = "none"
date = "unknown"
version string
inputFilePath string
templateFilePath string
outputFilePath string
Expand Down Expand Up @@ -84,5 +83,16 @@ func newRootCmd() *cobra.Command {
}

func printVersion() {
fmt.Printf("version: %s, commit: %s, date: %s\n", version, commit, date)
trueVersion := version

if version == "" {
info, ok := debug.ReadBuildInfo()
if ok {
trueVersion = info.Main.Version
}else{
trueVersion = "(devel)"
}
}

fmt.Printf("tempura version: %s\n", trueVersion)
}

0 comments on commit 608da45

Please sign in to comment.