Skip to content

Commit

Permalink
infra(magefile): add version directive
Browse files Browse the repository at this point in the history
  • Loading branch information
sharpvik committed Jan 28, 2023
1 parent bedd27f commit 721872e
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,32 @@
package main

import (
"fmt"

"github.com/magefile/mage/sh"
)

func Install() error {
version, err := sh.Output("git", "describe", "--tags", "--abbrev=0")
func Install() (err error) {
version, err := version()
if err != nil {
return err
return
}
_, err = sh.Output("go", "install", "-ldflags", "-X main.version="+version)
_, err = sh.Output(
"go", "install",
"-ldflags", "-w -s -X main.version="+version,
)
return
}

func Version() error {
version, err := version()
if err != nil {
return err
}
fmt.Println(version)
return nil
}

func version() (string, error) {
return sh.Output("git", "describe", "--tags", "--abbrev=0")
}

0 comments on commit 721872e

Please sign in to comment.