build

package
v1.20.89 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2024 License: Zlib Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OutHashFile       = 0x00001 // 输出updates.json(hash文件)
	HashNeedProject   = 0x00002 // hash文件需要用程序名
	HashNeedVersion   = 0x00004 // hash文件需要带版本号
	HashNeedModel     = 0x00008 // hash输出带model
	HashNeedOs        = 0x00010 // hash输出带os
	TargetNeedVersion = 0x00020
	TargetNeedModel   = 0x00040
	TargetNeedOs      = 0x00080
	TargetNeedDate    = 0x00100
	NeedArchiveHash   = 0x02000 // hashFile需要添加到压缩文件中
	OnlyPackOut       = 0x04000
	NotArchive        = 0x08000 //不需要压缩
	ArchiveVersion    = 0x10000 //压缩目录带版本
	ArchiveProject    = 0x20000 //压缩目录带产品名(ProjectName)
	NotCheckTpl       = 0x40000 //不需要检测模板 *.tpl
	NotCheckPackFile  = 0x80000 //不对 exclude, include 检测
)
View Source
const (
	RegexPrefix = "regex|"
	PathPrefix  = "path|"
)

Variables

View Source
var Default = &Builder{}

Default builder instance.

Functions

func AddFlag added in v1.20.56

func AddFlag(f string, bit int)

func DefaultDateFormat added in v1.20.55

func DefaultDateFormat(d time.Time) string

func GetFlag added in v1.20.56

func GetFlag(f string) int

Types

type Bit added in v1.20.41

type Bit int32

func ToBit added in v1.20.41

func ToBit(b string) Bit

func (Bit) Bit added in v1.20.41

func (a Bit) Bit(bit int32) bool

type Build

type Build struct {
	ID          string                          `yaml:"id,omitempty" json:"id,omitempty"`
	Goos        []string                        `yaml:"goos,omitempty" json:"goos,omitempty"`
	GoArch      []string                        `yaml:"goarch,omitempty" json:"goarch,omitempty"`
	GoArm       []string                        `yaml:"goarm,omitempty" json:"goarm,omitempty"`
	GoMips      []string                        `yaml:"gomips,omitempty" json:"gomips,omitempty"`
	GoAmd64     []string                        `yaml:"goamd64,omitempty" json:"goamd64,omitempty"`
	Executor    map[string]string               `yaml:"executor" json:"executor"` //生成的执行文件名,不同的操作系统对应不同的执行文件,"drawin":"projectName-mac",“linux":"projectName-linux","windows":"projectName-win.exe"
	ModulePath  string                          `yaml:"module_path" json:"module_path"`
	ProductId   string                          `yaml:"product_id" json:"product_id"`
	ProjectName string                          `yaml:"project_name" json:"project_name"`
	Target      string                          `yaml:"target,omitempty" json:"target,omitempty"` //生成目标目录
	Dir         string                          `yaml:"dir,omitempty" json:"dir,omitempty"`
	Main        string                          `yaml:"main,omitempty" json:"main,omitempty"`
	GoBinary    string                          `yaml:"go_binary,omitempty" json:"go_binary,omitempty"`
	Command     string                          `yaml:"command,omitempty" json:"command,omitempty"`
	Package     Package                         `yaml:"package" json:"package"`
	Details     `yaml:",inline" json:",inline"` // nolint: tagliatelle
}

Build contains the build configuration section.

type Builder

type Builder struct{}

Builder is golang builder.

func (*Builder) Build

func (*Builder) Build(ctx *Context, build Build, opts Options) error

Build builds a golang build.

func (*Builder) BuildHashFileName added in v1.20.42

func (b *Builder) BuildHashFileName(ctx *Context, bit Bit, filename string) string

func (*Builder) BuildTargetFileName added in v1.20.49

func (b *Builder) BuildTargetFileName(ctx *Context, bit Bit, filename string) string

func (*Builder) Clean

func (*Builder) Clean(ctx *Context, build Build, options Options) error

func (*Builder) Package

func (b *Builder) Package(ctx *Context, build Build, out *PackOut) error

Package 打包

func (*Builder) WithDefaults

func (*Builder) WithDefaults(build Build) (Build, error)

WithDefaults sets the defaults for a golang build and returns it.

type Config

type Config struct {
	ProductId   string
	ProjectName string
	Version     string
	Model       string
	Os          string
	Env         []string
}

type Context

type Context struct {
	stdctx.Context
	Config     Config
	Env        Env
	Git        Git
	Semver     Semver
	Runtime    Runtime
	DateFormat DateFormatFunc
	Date       time.Time
	Snapshot   bool
}

Context carries along some data through the pipes.

func NewContext

func NewContext(config Config) *Context

NewContext context.

func NewWithTimeout

func NewWithTimeout(config Config, timeout time.Duration) (*Context, stdctx.CancelFunc)

NewWithTimeout new context with the given timeout.

func WrapContext

func WrapContext(ctx stdctx.Context, config Config) *Context

WrapContext wraps an existing context.

type DateFormatFunc added in v1.20.55

type DateFormatFunc func(d time.Time) string

type Details

type Details struct {
	Buildmode string      `yaml:"buildmode,omitempty" json:"buildmode,omitempty"`
	Ldflags   StringArray `yaml:"ldflags,omitempty" json:"ldflags,omitempty"`
	Tags      FlagArray   `yaml:"tags,omitempty" json:"tags,omitempty"`
	Flags     FlagArray   `yaml:"flags,omitempty" json:"flags,omitempty"`
	AsmFlags  StringArray `yaml:"asm_flags,omitempty" json:"asm_flags,omitempty"`
	GcFlags   StringArray `yaml:"gc_flags,omitempty" json:"gc_flags,omitempty"`
	Env       []string    `yaml:"env,omitempty" json:"env,omitempty"`
}

type Env

type Env map[string]string

Env is the environment variables.

func ToEnv

func ToEnv(env []string) Env

ToEnv converts a list of strings to an Env (aka a map[string]string).

func (Env) Copy

func (e Env) Copy() Env

Copy returns a copy of the environment.

func (Env) Strings

func (e Env) Strings() []string

Strings returns the current environment as a list of strings, suitable for os executions.

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error is returned on any template error.

func (Error) Error

func (e Error) Error() string

func (Error) Unwrap

func (e Error) Unwrap() error

type ExpectedSingleEnvErr

type ExpectedSingleEnvErr struct{}

func (ExpectedSingleEnvErr) Error

func (e ExpectedSingleEnvErr) Error() string

type Fields

type Fields map[string]interface{}

Fields that will be available to the template engine.

type FlagArray

type FlagArray []string

type Git

type Git struct {
	Branch      string
	CurrentTag  string
	PreviousTag string
	Commit      string
	ShortCommit string
	FullCommit  string
	FirstCommit string
	URL         string
	Summary     string
	TagSubject  string
	TagContents string
	TagBody     string
	CommitDate  time.Time
	Dirty       bool
}

Git includes tags and diffs used in some point.

type HashFile added in v1.20.55

type HashFile struct {
	Os          string     `json:"os"`
	Version     string     `json:"version"`
	Model       string     `json:"model"`
	ProductId   string     `json:"product_id"`
	ProductCode string     `json:"product_code"`
	ProjectName string     `json:"project_name"`
	Packs       []PackFile `json:"files"`
}

type Options

type Options struct {
	Name   string
	Path   string
	Ext    string
	Target string
	Goos   string
	Goarch string
}

Options to be passed down to a builder.

type PackCheck added in v1.20.34

type PackCheck func(path, name string, isDir bool) bool

type PackCompleted added in v1.8.76

type PackCompleted func(out *PackOut, pf *PackFile, completed bool)

type PackFile added in v1.8.75

type PackFile struct {
	Name string `json:"name"`
	MD5  string `json:"md5"`
	Size int64  `json:"size"`
	Url  string `json:"url,omitempty"`
}

type PackOut added in v1.9.14

type PackOut struct {
	Version     string      `json:"version"`
	Path        string      `json:"path"` // ./build
	PackagePath string      `json:"packagePath"`
	PublishPath string      `json:"publishPath"`
	Name        string      `json:"name"` // file name
	Ext         string      `json:"ext"`  // file ext
	Target      string      `json:"target"`
	Url         string      `json:"url"`
	Hash        string      `json:"hash"` // updates.json 文件名(包括路径)
	Data        interface{} `json:"-"`    //自定义
}

type Package

type Package struct {
	ProductCode string   `yaml:"productCode" json:"productCode"` //产品编号
	Model       string   `yaml:"model" json:"model"`             //prod, test, dev
	Os          string   `yaml:"os" json:"os"`                   //操作系统 windows,linux,darwin
	Format      string   `yaml:"format" json:"format"`           //zip, tar.gz, tgz, tar, cab(windows), setup
	Dist        string   `yaml:"dist" json:"dist"`               //输出目录
	PackagePath string   `yaml:"packagePath" json:"packagePath"` // 包目录 dist/package_path, 默认 dist/packages
	PublishPath string   `yaml:"publishPath" json:"publishPath"` // 发布目录 dist/publish_path 默认 dist/publishes
	Target      string   `yaml:"target" json:"target"`           //输出文件名,可以为空
	Hash        string   `yaml:"hash" json:"hash"`               //输出pack 总的包描述文件,如: updates.json
	BaseUrl     string   `yaml:"baseUrl" json:"baseUrl"`         //文件存储基本地址(oss,如阿里云)
	MgrHost     string   `yaml:"mgrHost" json:"mgrHost"`         //版本管理后台host,需要把打包的信息保存到后台进行管理,比如: http://xxx.com:port
	Flag        string   `yaml:"flag" json:"flag"`               //标识 @see OutHashFile
	Exclude     []string `yaml:"exclude" json:"exclude"`         //打包不包括的选项
	Include     []string `yaml:"include" json:"include"`         //打包包括的选项
	// contains filtered or unexported fields
}

func (*Package) CheckOs added in v1.20.80

func (p *Package) CheckOs(name string) bool

func (*Package) ExcludeCheck added in v1.20.34

func (p *Package) ExcludeCheck(path, name string, isDir bool) bool

func (*Package) Ignore

func (p *Package) Ignore(path, name string, isDir bool) bool

func (*Package) IncludeCheck added in v1.20.34

func (p *Package) IncludeCheck(path, name string, isDir bool) bool

func (*Package) IsFlag added in v1.20.41

func (p *Package) IsFlag(o int32) bool

func (*Package) Parse added in v1.20.41

func (p *Package) Parse()

func (*Package) WithCompleted added in v1.8.99

func (p *Package) WithCompleted(check PackCompleted)

func (*Package) WithExcludeCheck added in v1.20.34

func (p *Package) WithExcludeCheck(check PackCheck)

func (*Package) WithIncludeCheck added in v1.20.34

func (p *Package) WithIncludeCheck(check PackCheck)

type Regex added in v1.20.84

type Regex struct {
	Path bool
	Exp  *regexp.Regexp
}

type Runtime

type Runtime struct {
	Goos   string
	Goarch string
}

type Semver

type Semver struct {
	Major      uint64
	Minor      uint64
	Patch      uint64
	Prerelease string
}

Semver represents a semantic version.

type StringArray

type StringArray []string

StringArray is a wrapper for an array of strings.

type Template

type Template struct {
	// contains filtered or unexported fields
}

Template holds data that can be applied to a template string.

func NewEmptyTemplate added in v1.20.38

func NewEmptyTemplate() *Template

func NewTemplate

func NewTemplate(ctx *Context) *Template

NewTemplate Template.

func (*Template) AddField added in v1.20.38

func (t *Template) AddField(key string, value interface{}) *Template

func (*Template) Apply

func (t *Template) Apply(s string) (string, error)

Apply applies the given string against the Fields stored in the template.

func (*Template) ApplyAll

func (t *Template) ApplyAll(in ...string) ([]string, error)

ApplyAll applies all the given strings against the Fields stored in the template. Application stops as soon as an error is encountered.

func (*Template) ApplySingleEnvOnly

func (t *Template) ApplySingleEnvOnly(s string) (string, error)

ApplySingleEnvOnly enforces template to only contain a single environment variable and nothing else.

func (*Template) Bool

func (t *Template) Bool(s string) (bool, error)

Bool Apply the given string, and converts it to a bool.

func (*Template) WithBuildOptions

func (t *Template) WithBuildOptions(opts Options) *Template

func (*Template) WithEnv

func (t *Template) WithEnv(e map[string]string) *Template

WithEnv overrides template's env field with the given environment map.

func (*Template) WithEnvS

func (t *Template) WithEnvS(envs []string) *Template

WithEnvS overrides template's env field with the given KEY=VALUE list of environment variables.

func (*Template) WithExtraFields

func (t *Template) WithExtraFields(f Fields) *Template

WithExtraFields allows to add new more custom fields to the template. It will override fields with the same name.

Jump to

Keyboard shortcuts

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