gorelease

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2020 License: Apache-2.0 Imports: 18 Imported by: 0

README

gorelease

Docker Repository on Quay

idiomatic build and release single-binary go applications

https://console.cloud.google.com/storage/browser/gorelease

version: v0.1.0
env:
  CGO_ENABLED: 0
  GO111MODULE: on
flags:
  - -ldflags="-X 'main.Version=v0.1.0'"

targets:

  - name: "gorelease"
    file: main.go
    platforms:
      windows: ["386", "amd64", "arm"]
      linux: ["386", "amd64"]

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuildRelease = func(release *Release) error {
	for _, t := range release.Targets {
		if err := Build(&t); err != nil {
			return err
		}
	}
	return nil
}
View Source
var ErrorBlankFileName = errors.New("target has blank file name")
View Source
var ErrorDuplicateNames = errors.New("release has targets with duplicate names")
View Source
var ErrorVersionNotSet = errors.New("version is not set")

Functions

func DistList

func DistList() map[string][]string

DistList is a function that will gather all dists by calling `go tool dist list`

Types

type BuildFunc

type BuildFunc func(*Target) error
var Build BuildFunc = func(target *Target) error {
	for _, b := range target.FileBuilds {
		cmd := b.Command()
		log.Print(buildCmdLog(b, cmd))
		out, _, err := runCmd(cmd)
		if len(out) > 0 {
			log.Print(string(out))
		}
		if err != nil {
			return err
		}
	}
	return nil
}

Build is a basic BuildFunc

type BuildReleaseFunc

type BuildReleaseFunc func(*Release) error

type FileBuild

type FileBuild struct {
	Name    string   // file name
	BinPath string   // final path of built executable
	Env     []string // env passed to go build
	Args    []string // args passed to go build
	GOOS    string
	GOARCH  string
}

func MakeFileBuild

func MakeFileBuild(t Target, goos, goarch string) FileBuild

MakeFileBuild creates FileBuild for Target

func (*FileBuild) Command

func (b *FileBuild) Command() *exec.Cmd

type GCSResult

type GCSResult map[string]string

local path: url

type PrepareFunc

type PrepareFunc func(*Release) error
var Prepare PrepareFunc = func(release *Release) error {

	if release.Version == "" {
		return ErrorVersionNotSet
	}

	if isAllPlatforms(release.Platforms) {
		release.Platforms = DistList()
	}

	glob := release

	for i, t := range release.Targets {

		if t.Version == "" {
			t.Version = glob.Version
		}
		if t.DestDir == "" {
			t.DestDir = glob.DestDir
		}
		if t.FilePath == "" {
			return ErrorBlankFileName
		}
		if t.Name == "" {
			t.Name = glob.Name
		}
		if t.Env == nil {
			t.Env = glob.Env
		}
		if t.Flags == nil {
			t.Flags = glob.Flags
		}
		if isAllPlatforms(t.Platforms) {
			t.Platforms = DistList()
		}
		if t.Platforms == nil {
			t.Platforms = glob.Platforms
		}

		for goos, goarchs := range t.Platforms {
			for _, goarch := range goarchs {
				build := MakeFileBuild(t, goos, goarch)
				t.FileBuilds = append(t.FileBuilds, build)
			}
		}
		release.Targets[i] = t
	}

	if hasDuplicateNames(release) {
		return ErrorDuplicateNames
	}
	return nil
}

Prepare is a basic PrepareFunc

type Release

type Release struct {
	Target  `yaml:",inline"`
	Targets []Target `yaml:"targets"`
}

func FromFile

func FromFile(path string) *Release

FromFile creates Release from given path

func (*Release) ForEachTarget

func (r *Release) ForEachTarget(f func(t *Target) error) error

ForEach performs func f for each Target in Release

func (*Release) ForEachTargetBuild

func (r *Release) ForEachTargetBuild(f func(t *Target, f *FileBuild) error) error

type ReleaseFunc

type ReleaseFunc func(*Release) error

func GCSRelease

func GCSRelease(bucket string, result GCSResult) ReleaseFunc

GCSRelease is Google Cloud Storage ReleaseFunc

type Target

type Target struct {
	FilePath string `yaml:"file"`    // file to compile
	Name     string `yaml:"name"`    // name of executable
	Version  string `yaml:"version"` // version of release
	DestDir  string `yaml:"dir"`     // dir when bin is stored

	Env       map[string]string   `yaml:"env"`       // env passed to go build
	Flags     []string            `yaml:"flags"`     // flags passed to go build
	Platforms map[string][]string `yaml:"platforms"` // for what platforms build

	FileBuilds []FileBuild `yaml:"-"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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