Skip to content

Commit

Permalink
add build-time version metadata (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelquigley committed Nov 2, 2022
1 parent 1938896 commit e062a9f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Go package
name: Core Build

on: [push]

jobs:
build:
ubuntu-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -27,7 +27,7 @@ jobs:
CI: ""

- name: go build
run: go build -v ./...
run: go build -ldflags "-X github.com/openziti-test-kitchen/zrok/build.Version=${{ github.ref }} -X github.com/openziti-test-kitchen/zrok/build.Hash=${{ github.sha }}" ./...

- name: test
run: go test -v ./...
14 changes: 14 additions & 0 deletions build/metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package build

import "fmt"

var Version string
var Hash string

func String() string {
if Version != "" {
return fmt.Sprintf("%v [%v]", Version, Hash)
} else {
return "<developer_build>"
}
}
2 changes: 0 additions & 2 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ var str *store.Store
var mtr *metricsAgent
var idb influxdb2.Client

const version = "v0.2.0"

func Run(inCfg *Config) error {
cfg = inCfg

Expand Down
3 changes: 2 additions & 1 deletion controller/enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"github.com/go-openapi/runtime/middleware"
"github.com/openziti-test-kitchen/zrok/build"
"github.com/openziti-test-kitchen/zrok/controller/store"
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
"github.com/openziti-test-kitchen/zrok/rest_server_zrok/operations/identity"
Expand Down Expand Up @@ -165,7 +166,7 @@ func (self *enableHandler) createEdgeRouterPolicy(id string, edge *rest_manageme
func (self *enableHandler) zrokTags() *rest_model_edge.Tags {
return &rest_model_edge.Tags{
SubTags: map[string]interface{}{
"zrok": version,
"zrok": build.String(),
},
}
}
3 changes: 2 additions & 1 deletion controller/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"github.com/go-openapi/runtime/middleware"
"github.com/openziti-test-kitchen/zrok/build"
"github.com/openziti-test-kitchen/zrok/controller/store"
"github.com/openziti-test-kitchen/zrok/model"
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
Expand Down Expand Up @@ -264,7 +265,7 @@ func (self *tunnelHandler) proxyUrl(svcName string) string {
func (self *tunnelHandler) zrokTags(svcName string) *rest_model.Tags {
return &rest_model.Tags{
SubTags: map[string]interface{}{
"zrok": version,
"zrok": build.String(),
"zrok-service-name": svcName,
},
}
Expand Down
4 changes: 3 additions & 1 deletion controller/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package controller

import (
"github.com/go-openapi/runtime/middleware"
"github.com/openziti-test-kitchen/zrok/build"
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
"github.com/openziti-test-kitchen/zrok/rest_server_zrok/operations/metadata"
)

func versionHandler(_ metadata.VersionParams) middleware.Responder {
return metadata.NewVersionOK().WithPayload(version)
return metadata.NewVersionOK().WithPayload(rest_model_zrok.Version(build.String()))
}

0 comments on commit e062a9f

Please sign in to comment.