Skip to content

Commit

Permalink
adding versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
joeygibson committed Jan 23, 2021
1 parent 17617bc commit 7a55640
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ jobs:
- os: macOS-latest
steps:
- name: Checkout code
uses: actions/checkout@v1
- uses: actions/checkout@v2
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.15
- name: Build for release
run: go build
run: go build -ldflags "-X main.sha1ver=`git rev-parse HEAD` -X main.buildTime=`date +'%Y-%m-%d_%T'` -X main.gitTag=${GITHUB_REF#refs/*/v}"
- name: Set program name
run: echo "PROGRAM_NAME=${GITHUB_REPOSITORY#joeygibson/}" >> $GITHUB_ENV
- name: Generate binary name
Expand Down
18 changes: 16 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import (
"os"
)

var (
gitTag string // Git tag
sha1ver string // sha1 revision used to build the program
buildTime string // when the executable was built
)

func main() {
helpFlag := getopt.BoolLong("help", 'H', "show help")
countFlag := getopt.BoolLong("count", 'c', "count rows")
Expand All @@ -17,17 +23,25 @@ func main() {
forceFlag := getopt.BoolLong("force", 'f', "force overwrite of output file")
versionFlag := getopt.BoolLong("version", 'v', "show version")

getopt.SetParameters("<file>")
getopt.Parse()
args := getopt.Args()

if *helpFlag {
fmt.Println("Help!")
getopt.PrintUsage(os.Stderr)
os.Exit(0)
}

if *versionFlag {
fmt.Println("Version!")
var msg string

if gitTag != "" {
msg = fmt.Sprintf("%s - %s - %s", gitTag, sha1ver, buildTime)
} else {
msg = fmt.Sprintf("%s - %s", sha1ver, buildTime)
}

fmt.Println(msg)
os.Exit(0)
}

Expand Down

0 comments on commit 7a55640

Please sign in to comment.