-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #265 from grafana/set-build-version
Set version from runtime build info
- Loading branch information
Showing
4 changed files
with
52 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Package version provide information about the build version | ||
package version | ||
|
||
import ( | ||
"runtime/debug" | ||
) | ||
|
||
const xk6DisruptorPath = "github.com/grafana/xk6-disruptor" | ||
|
||
// DisruptorVersion returns the version of the currently executed disruptor | ||
func DisruptorVersion() string { | ||
if bi, ok := debug.ReadBuildInfo(); ok { | ||
for _, d := range bi.Deps { | ||
if d.Path == xk6DisruptorPath { | ||
if d.Replace != nil { | ||
return d.Replace.Version | ||
} | ||
return d.Version | ||
} | ||
} | ||
} | ||
|
||
return "" | ||
} | ||
|
||
// AgentImage returns the name of the agent image that corresponds to | ||
// this version of the extension. | ||
func AgentImage() string { | ||
tag := "latest" | ||
|
||
// if a specific version of the disruptor was built, use it for agent's tag | ||
// (go test sets version to "") | ||
dv := DisruptorVersion() | ||
if dv != "" && dv != "(devel)" { | ||
tag = dv | ||
} | ||
|
||
return "ghcr.io/grafana/xk6-disruptor-agent:" + tag | ||
} |