fix: Manually format external URL (#1168)

path.Join escaped the double slash!
This commit is contained in:
Kyle Carberry
2022-04-25 17:22:31 -05:00
committed by GitHub
parent 159024a196
commit 947e8f9d2e
2 changed files with 36 additions and 19 deletions

View File

@ -1,7 +1,7 @@
package buildinfo package buildinfo
import ( import (
"path" "fmt"
"runtime/debug" "runtime/debug"
"sync" "sync"
"time" "time"
@ -14,6 +14,12 @@ var (
buildInfoValid bool buildInfoValid bool
readBuildInfo sync.Once readBuildInfo sync.Once
externalURL string
readExternalURL sync.Once
version string
readVersion sync.Once
// Injected with ldflags at build! // Injected with ldflags at build!
tag string tag string
) )
@ -21,29 +27,37 @@ var (
// Version returns the semantic version of the build. // Version returns the semantic version of the build.
// Use golang.org/x/mod/semver to compare versions. // Use golang.org/x/mod/semver to compare versions.
func Version() string { func Version() string {
revision, valid := revision() readVersion.Do(func() {
if valid { revision, valid := revision()
revision = "+" + revision[:7] if valid {
} revision = "+" + revision[:7]
if tag == "" { }
return "v0.0.0-devel" + revision if tag == "" {
} version = "v0.0.0-devel" + revision
if semver.Build(tag) == "" { return
tag += revision }
} if semver.Build(tag) == "" {
return "v" + tag tag += revision
}
version = "v" + tag
})
return version
} }
// ExternalURL returns a URL referencing the current Coder version. // ExternalURL returns a URL referencing the current Coder version.
// For production builds, this will link directly to a release. // For production builds, this will link directly to a release.
// For development builds, this will link to a commit. // For development builds, this will link to a commit.
func ExternalURL() string { func ExternalURL() string {
repo := "https://github.com/coder/coder" readExternalURL.Do(func() {
revision, valid := revision() repo := "https://github.com/coder/coder"
if !valid { revision, valid := revision()
return repo if !valid {
} externalURL = repo
return path.Join(repo, "commit", revision) return
}
externalURL = fmt.Sprintf("%s/commit/%s", repo, revision)
})
return externalURL
} }
// Time returns when the Git revision was published. // Time returns when the Git revision was published.

View File

@ -501,6 +501,7 @@ func TestProvisionerd(t *testing.T) {
t.Run("ShutdownFromJob", func(t *testing.T) { t.Run("ShutdownFromJob", func(t *testing.T) {
t.Parallel() t.Parallel()
var completed sync.Once
var updated sync.Once var updated sync.Once
updateChan := make(chan struct{}) updateChan := make(chan struct{})
completeChan := make(chan struct{}) completeChan := make(chan struct{})
@ -532,7 +533,9 @@ func TestProvisionerd(t *testing.T) {
}, nil }, nil
}, },
failJob: func(ctx context.Context, job *proto.FailedJob) (*proto.Empty, error) { failJob: func(ctx context.Context, job *proto.FailedJob) (*proto.Empty, error) {
close(completeChan) completed.Do(func() {
close(completeChan)
})
return &proto.Empty{}, nil return &proto.Empty{}, nil
}, },
}), nil }), nil