Skip to content

fix: Manually format external URL #1168

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

Merged
merged 1 commit into from
Apr 25, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 32 additions & 18 deletions buildinfo/buildinfo.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package buildinfo

import (
"path"
"fmt"
"runtime/debug"
"sync"
"time"
Expand All @@ -14,36 +14,50 @@ var (
buildInfoValid bool
readBuildInfo sync.Once

externalURL string
readExternalURL sync.Once

version string
readVersion sync.Once

// Injected with ldflags at build!
tag string
)

// Version returns the semantic version of the build.
// Use golang.org/x/mod/semver to compare versions.
func Version() string {
revision, valid := revision()
if valid {
revision = "+" + revision[:7]
}
if tag == "" {
return "v0.0.0-devel" + revision
}
if semver.Build(tag) == "" {
tag += revision
}
return "v" + tag
readVersion.Do(func() {
revision, valid := revision()
if valid {
revision = "+" + revision[:7]
}
if tag == "" {
version = "v0.0.0-devel" + revision
return
}
if semver.Build(tag) == "" {
tag += revision
}
version = "v" + tag
})
return version
}

// ExternalURL returns a URL referencing the current Coder version.
// For production builds, this will link directly to a release.
// For development builds, this will link to a commit.
func ExternalURL() string {
repo := "https://github.com/coder/coder"
revision, valid := revision()
if !valid {
return repo
}
return path.Join(repo, "commit", revision)
readExternalURL.Do(func() {
repo := "https://github.com/coder/coder"
revision, valid := revision()
if !valid {
externalURL = repo
return
}
externalURL = fmt.Sprintf("%s/commit/%s", repo, revision)
})
return externalURL
}

// Time returns when the Git revision was published.
Expand Down
5 changes: 4 additions & 1 deletion provisionerd/provisionerd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ func TestProvisionerd(t *testing.T) {

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