Skip to content

Commit

Permalink
Build with version number
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewLester committed Jul 15, 2023
1 parent 148a7b3 commit d66a8d4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
with:
name: ntpal-binary-${{ matrix.os }}
path: ${{ github.workspace }}/bin/ntpal-${{ matrix.os }}
env:
VERSION: ${github.ref/v/}

release:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ SHELL := /bin/bash -f
all: ntpal site

ntpal:
go build -o bin/ntpal github.com/AndrewLester/ntpal/cmd/ntpal
go build -o bin/ntpal -ldflags "-X main.version=${VERSION}" github.com/AndrewLester/ntpal/cmd/ntpal

site:
go build -o bin/site github.com/AndrewLester/ntpal/cmd/site
go build -o bin/site -ldflags "-X main.version=${VERSION}" github.com/AndrewLester/ntpal/cmd/site

clean:
rm -rf bin
10 changes: 10 additions & 0 deletions cmd/ntpal/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/AndrewLester/ntpal/pkg/ntpal"
)

var version string // This is set by the linker

const defaultConfigPath = "/etc/ntp.conf"
const defaultDriftPath = "/etc/ntp.drift"

Expand All @@ -22,15 +24,23 @@ func main() {
var query string
var noDaemon bool
var stop bool
var isVersion bool
flag.StringVar(&config, "config", defaultConfigPath, "Path to the NTP config file.")
flag.StringVar(&drift, "drift", defaultDriftPath, "Path to the NTP drift file.")
flag.StringVar(&query, "query", "", "Address to query.")
flag.StringVar(&query, "q", query, "Address to query.")
flag.BoolVar(&noDaemon, "no-daemon", false, "Don't run ntpal as a daemon.")
flag.BoolVar(&stop, "stop", false, "Stop the ntpal daemon.")
flag.BoolVar(&stop, "s", stop, "Stop the ntpal daemon.")
flag.BoolVar(&isVersion, "version", false, "Check the NTPal version.")
flag.BoolVar(&isVersion, "v", isVersion, "Check the NTPal version.")
flag.Parse()

if isVersion {
fmt.Println("NTPal", version)
return
}

port := os.Getenv("NTP_PORT")
if port == "" {
if query != "" {
Expand Down
5 changes: 4 additions & 1 deletion cmd/site/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/AndrewLester/ntpal/pkg/ntpal"
)

var version string // This is set by the linker

type SyncRequest struct {
Orig string
}
Expand All @@ -29,7 +31,8 @@ func main() {

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
data := map[string]string{
"Region": strings.ToUpper(os.Getenv("FLY_REGION")),
"Region": strings.ToUpper(os.Getenv("FLY_REGION")),
"Version": version,
}

// Set these headers to bump performance.now() precision to 5 microseconds
Expand Down
4 changes: 3 additions & 1 deletion internal/templates/templates/index.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,9 @@ <h2>According to this server,</h2>
{{ if .Region }}
<p class="region">
Server hosted in the {{.Region}} region, running
<a href="https://github.com/AndrewLester/NTPal">NTPal</a>.
<a href="https://github.com/AndrewLester/NTPal">
NTPal {{ if .Version }} {{.Version}} {{ end }} </a
>.
</p>
{{ end }}

Expand Down

0 comments on commit d66a8d4

Please sign in to comment.