diff --git a/.goreleaser.yml b/.goreleaser.yml index a29ce0c0a..3e6a62546 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -17,7 +17,7 @@ builds: flags: - -tags=embedhtml ldflags: - - -s -w -X "github.com/kopia/kopia/repo.BuildVersion={{.Version}}" -X "github.com/kopia/kopia/repo.BuildInfo={{.Commit}}" + - -s -w -X "github.com/kopia/kopia/repo.BuildVersion={{.Version}}" -X "github.com/kopia/kopia/repo.BuildInfo={{.Commit}} -X "github.com/kopia/kopia/repo.BuildGitHubRepo={{.Env.GITHUB_REPOSITORY}}" release: draft: false archives: diff --git a/cli/update_check.go b/cli/update_check.go index 65ef9ad5a..b0c8e8de0 100644 --- a/cli/update_check.go +++ b/cli/update_check.go @@ -33,17 +33,17 @@ ) const ( - latestReleaseGitHubURL = "https://api.github.com/repos/kopia/kopia/releases/latest" - checksumsURL = "https://github.com/kopia/kopia/releases/download/%v/checksums.txt.sig" - autoUpdateNotice = ` + latestReleaseGitHubURLFormat = "https://api.github.com/repos/%v/releases/latest" + checksumsURLFormat = "https://github.com/%v/releases/download/%v/checksums.txt.sig" + autoUpdateNotice = ` NOTICE: Kopia will check for updates on GitHub every 7 days, starting 24 hours after first use. To disable this behavior, set environment variable ` + checkForUpdatesEnvar + `=false Alternatively you can remove the file "%v". ` - updateAvailableNotice = ` + updateAvailableNoticeFormat = ` Upgrade of Kopia from %v to %v is available. -Visit https://github.com/kopia/kopia/releases/latest to download it. +Visit https://github.com/%v/releases/latest to download it. ` ) @@ -116,7 +116,7 @@ func getLatestReleaseNameFromGitHub(ctx context.Context) (string, error) { ctx, cancel := context.WithTimeout(ctx, githubTimeout) defer cancel() - req, err := http.NewRequestWithContext(ctx, "GET", latestReleaseGitHubURL, nil) + req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf(latestReleaseGitHubURLFormat, repo.BuildGitHubRepo), nil) if err != nil { return "", errors.Wrap(err, "unable to get latest release from github") } @@ -147,7 +147,7 @@ func verifyGitHubReleaseIsComplete(ctx context.Context, releaseName string) erro ctx, cancel := context.WithTimeout(ctx, githubTimeout) defer cancel() - req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf(checksumsURL, releaseName), nil) + req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf(checksumsURLFormat, repo.BuildGitHubRepo, releaseName), nil) if err != nil { return errors.Wrap(err, "unable to download releases checksum") } @@ -242,6 +242,11 @@ func maybeCheckGithub(ctx context.Context, us *updateState) error { // maybePrintUpdateNotification prints notification about available version. func maybePrintUpdateNotification(ctx context.Context) { + if repo.BuildGitHubRepo == "" { + // not built from GH repo. + return + } + updatedVersion, err := maybeCheckForUpdates(ctx) if err != nil { log(ctx).Debugf("unable to check for updates: %v", err) @@ -253,7 +258,7 @@ func maybePrintUpdateNotification(ctx context.Context) { return } - log(ctx).Noticef(updateAvailableNotice, ensureVPrefix(repo.BuildVersion), ensureVPrefix(updatedVersion)) + log(ctx).Noticef(updateAvailableNoticeFormat, ensureVPrefix(repo.BuildVersion), ensureVPrefix(updatedVersion), repo.BuildGitHubRepo) } func ensureVPrefix(s string) string { diff --git a/main.go b/main.go index 9ed8f8441..194de46f0 100644 --- a/main.go +++ b/main.go @@ -74,7 +74,7 @@ func main() { return gologging.MustGetLogger(module) }) - app.Version(repo.BuildVersion + " build: " + repo.BuildInfo) + app.Version(repo.BuildVersion + " build: " + repo.BuildInfo + " from: " + repo.BuildGitHubRepo) app.PreAction(logfile.Initialize) app.UsageTemplate(usageTemplate) diff --git a/repo/initialize.go b/repo/initialize.go index 5206d9740..480f90be7 100644 --- a/repo/initialize.go +++ b/repo/initialize.go @@ -17,8 +17,9 @@ // BuildInfo is the build information of Kopia. var ( - BuildInfo = "unknown" - BuildVersion = "v0-unofficial" + BuildInfo = "unknown" + BuildVersion = "v0-unofficial" + BuildGitHubRepo = "" ) const (