upgrade

package module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 10, 2019 License: MIT Imports: 11 Imported by: 0

README

tool-upgrade-go

A library for golang that helps upgrade tools to newer versions with ease.

Usage

Artifact Repository structure
# over-simplified example of directory and file structure required
# mycompany.com web server directory or artifact repository

# binaries must be suffixed with _${GOOS}_${GOARCH}
% find path/to/dist
path/to/dist
path/to/dist/coolTool_darwin_amd64
path/to/dist/coolTool_linux_amd64
path/to/dist/coolTool_windows_amd64

% cat path/to/coolTool/.version-latest
1.2.2

# copy new binaries into place
% mkdir -p path/to/coolTool/1.2.3
% cp path/to/dist/coolTool_* path/to/coolTool/1.2.3

# update version channel
% echo "1.2.3" > path/to/coolTool/.version-latest

# full path structure
% find path/to/coolTool
path/to/coolTool
path/to/coolTool/1.2.2
path/to/coolTool/1.2.2/coolTool_darwin_amd64
path/to/coolTool/1.2.2/coolTool_linux_amd64
path/to/coolTool/1.2.2/coolTool_windows_amd64
path/to/coolTool/1.2.3
path/to/coolTool/1.2.3/coolTool_darwin_amd64
path/to/coolTool/1.2.3/coolTool_linux_amd64
path/to/coolTool/1.2.3/coolTool_windows_amd64
path/to/coolTool/.version-latest
Check for updates and upgrade if needed

tool-upgrade-go will upgrade to the version available in the version channel. It leverages GOOS and GOARCH of the current runtime to determine which platform architecture to download for the upgrade. In practice, this is often done using a CLI subcommand.

import "github.com/VeritasOS/tool-upgrade-go"

func main() {
  needUpgrade, err := upgrade.CheckAndNotifyIfOutOfDate(
    "coolTool", // tool name
    "1.2.2",    // current (installed) version
    "https://mycompany.com/path/to/coolTool", // artifact repo base
    ".version-", // version channel prefix
    "latest",    // version channel
  )

  if needUpgrade {
    err := upgrade.Upgrade(
      "coolTool",  // tool name
      "1.2.2",     // current (installed) version
      "https://mycompany.com/path/to/coolTool", // artifact repo base
      ".version-", // version channel prefix
      "latest",    // version channel name
      false,       // force upgrade when available version is the same or older
    )
  }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AvailableVersion

func AvailableVersion(repo string, filePrefix string, channel string) (semver.Version, error)

func CheckAndNotifyIfOutOfDate

func CheckAndNotifyIfOutOfDate(tool string, currentVersion string, repo string, filePrefix string, versionStable string, hoursToCheckForUpdate float64, upgradeCommand string) (bool, error)

CheckAndNotifyIfOutOfDate checks if this utility is out of date compared to the repository. It uses a caching strategy to avoid costly checks with every run.

func CurrentVersion

func CurrentVersion(version string) (semver.Version, error)

func Download

func Download(repo string, version string, tool string) (string, error)

func GetHome

func GetHome() string

func RemoveBackup

func RemoveBackup() (string, string, error)

func Upgrade

func Upgrade(tool string, currentVersion string, repo string, filePrefix string, versionStable string, upgradeForce *bool) error

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址