Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fallback to buildinfo when airversion and goversion is empty #474

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 28 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import (
"flag"
"fmt"
"log"

Check failure on line 6 in main.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

undefined: Println

Check failure on line 6 in main.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

undefined: Println

Check failure on line 6 in main.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

undefined: Println

Check failure on line 6 in main.go

View workflow job for this annotation

GitHub Actions / build (macos-latest)

undefined: Println

Check failure on line 6 in main.go

View workflow job for this annotation

GitHub Actions / build (macos-latest)

undefined: Println

Check failure on line 6 in main.go

View workflow job for this annotation

GitHub Actions / build (macos-latest)

undefined: Println
"os"
"os/signal"
"runtime"
"runtime/debug"
"syscall"

"github.com/cosmtrek/air/runner"
Expand Down Expand Up @@ -43,13 +45,38 @@
flag.CommandLine.Parse(args)
}

type versionInfo struct {
airVersion string
goVersion string
}

func GetVersionInfo() versionInfo {
if len(airVersion) != 0 && len(goVersion) != 0 {
return versionInfo{
airVersion: airVersion,
goVersion: goVersion,
}
}
if info, ok := debug.ReadBuildInfo(); ok {
return versionInfo{
airVersion: info.Main.Version,
goVersion: runtime.Version(),
}
}
return versionInfo{
airVersion: "(unknown)",
goVersion: runtime.Version(),
}
}

func main() {
versionInfo := GetVersionInfo()
fmt.Printf(`
__ _ ___
/ /\ | | | |_)
/_/--\ |_| |_| \_ %s, built with Go %s

`, airVersion, goVersion)
`, versionInfo.airVersion, versionInfo.goVersion)

if showVersion {
return
Expand Down
2 changes: 2 additions & 0 deletions runner/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ func defaultConfig() Config {
Log: "build-errors.log",
IncludeExt: []string{"go", "tpl", "tmpl", "html"},
IncludeDir: []string{},
PreCmd: []string{},
PostCmd: []string{},
ExcludeFile: []string{},
IncludeFile: []string{},
ExcludeDir: []string{"assets", "tmp", "vendor", "testdata"},
Expand Down
6 changes: 4 additions & 2 deletions version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package main

var airVersion string
var goVersion string
var (
airVersion string
goVersion string
)