gitrel

package module
v0.0.0-...-6921436 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2019 License: MIT Imports: 10 Imported by: 1

README

Gitrel - Github Release Updater for Go

This library been replaced by ghru - please use that project instead.

Gitrel is a package for golang to allow binary updating from the latest release assets on Github.

It downloads pre-compiled binaries from your latest release, and replaces the current running version.

Binaries must be attached to your latest Github release (assets), compressed with bzip2 (bz2), and named accordingly: <name>_<version>_<os>_<architecture>.bz2, eg:

myapp_1.2.3_linux_amd64.bz2
myapp_1.2.3_linux_386.bz2
myapp_1.2.3_darwin_386.bz2
myapp_1.2.3_darwin_amd64.bz2
myapp_1.2.3_windows_amd64.exe.bz2
myapp_1.2.3_windows_386.exe.bz2

Gitrel does not compare semantic versioning, so it will always assume that if the latest release version on Github differs from the current version, then it is an update. If an update is run and the application version matches the latest release tag, then the update is skipped. If an update is available however Gitrel cannot find a match of release asset (ie: operating system and artitecture), then the update is aborted. It does not matter what the running binary is called, it will be updated provided the user running the update has permissions to read & write to the running binary and binary directory.

Install

go get -u github.com/axllent/gitrel

Example usage

The update command is gitrel.Update("myuser/myapp", "myapp", currentVersion), where:

  • myuser/myapp is your github name (handle) and the repo name
  • myapp is the name of your app for your binaries (generally the same as the repo)
  • currentVersion is the version of the running application

How you define your current running version is entirely up to you, but you must provide it otherwise Gitrel cannot compare with the latest release.

package main

import (
	"flag"
	"fmt"
	"log"

	"github.com/axllent/gitrel"
)

func main() {

	update := flag.Bool("u", false, "updater to latest release")

	flag.Parse()

	var currentVersion = "0.1.2"

	if *update {
		rel, err := gitrel.Update("myuser/myapp", "myapp", currentVersion)
		if err != nil {
			log.Fatal(err)
			return
		}
		fmt.Printf("Updated %s to version %s\n", os.Args[0], rel)
		return
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DownloadToFile

func DownloadToFile(url string, filepath string) error

DownloadToFile downloads a URL to a file

func Latest

func Latest(repo string, name string) (string, string, string, error)

Latest fetches the latest release info Returns version number, filename & download url

func ReplaceFile

func ReplaceFile(dst string, src string) error

ReplaceFile replaces one file with another Running files cannot be overwritten, so it has to be moved and the new binary saved to the original path. This requires read & write permissions to both the original file and directory

func Update

func Update(repo string, appName string, currentVersion string) (string, error)

Update the running binary with the latest release binary from Github

Types

type Repository

type Repository struct {
	Assets []struct {
		BrowserDownloadURL string `json:"browser_download_url"`
		CreatedAt          string `json:"created_at"`
		ID                 int64  `json:"id"`
		Name               string `json:"name"`
		Size               int64  `json:"size"`
	} `json:"assets"`
	Name        string `json:"name"`
	Prerelease  bool   `json:"prerelease"`
	PublishedAt string `json:"published_at"`
	TagName     string `json:"tag_name"`
}

Repository struct for Github release json

Jump to

Keyboard shortcuts

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