Run version function before anything else and set the version variable to its output
ci/woodpecker/push/woodpecker Pipeline was successful
Details
ci/woodpecker/push/woodpecker Pipeline was successful
Details
This commit is contained in:
parent
24c807a941
commit
8ceb61de9a
54
build.go
54
build.go
|
@ -160,6 +160,30 @@ func buildPackage(ctx context.Context, script string, mgr manager.Manager) ([]st
|
||||||
dec.LikeDistros = false
|
dec.LikeDistros = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn, ok := dec.GetFunc("version")
|
||||||
|
if ok {
|
||||||
|
log.Info("Executing version()").Send()
|
||||||
|
|
||||||
|
buf := &bytes.Buffer{}
|
||||||
|
|
||||||
|
err = fn(
|
||||||
|
ctx,
|
||||||
|
interp.Dir(filepath.Dir(script)),
|
||||||
|
interp.StdIO(os.Stdin, buf, os.Stderr),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
newVer := strings.TrimSpace(buf.String())
|
||||||
|
err = setVersion(ctx, runner, newVer)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Info("Updating version").Str("new", newVer).Send()
|
||||||
|
}
|
||||||
|
|
||||||
var vars BuildVars
|
var vars BuildVars
|
||||||
err = dec.DecodeVars(&vars)
|
err = dec.DecodeVars(&vars)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -249,7 +273,7 @@ func buildPackage(ctx context.Context, script string, mgr manager.Manager) ([]st
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
fn, ok := dec.GetFunc("prepare")
|
fn, ok = dec.GetFunc("prepare")
|
||||||
if ok {
|
if ok {
|
||||||
log.Info("Executing prepare()").Send()
|
log.Info("Executing prepare()").Send()
|
||||||
|
|
||||||
|
@ -259,26 +283,6 @@ func buildPackage(ctx context.Context, script string, mgr manager.Manager) ([]st
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn, ok = dec.GetFunc("version")
|
|
||||||
if ok {
|
|
||||||
log.Info("Executing version()").Send()
|
|
||||||
|
|
||||||
buf := &bytes.Buffer{}
|
|
||||||
|
|
||||||
err = fn(
|
|
||||||
ctx,
|
|
||||||
interp.Dir(srcdir),
|
|
||||||
interp.StdIO(os.Stdin, buf, os.Stderr),
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
vars.Version = strings.TrimSpace(buf.String())
|
|
||||||
|
|
||||||
log.Info("Updating version").Str("new", vars.Version).Send()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn, ok = dec.GetFunc("build")
|
fn, ok = dec.GetFunc("build")
|
||||||
if ok {
|
if ok {
|
||||||
log.Info("Executing build()").Send()
|
log.Info("Executing build()").Send()
|
||||||
|
@ -617,6 +621,14 @@ func archMatches(architectures []string) bool {
|
||||||
return slices.Contains(architectures, arch)
|
return slices.Contains(architectures, arch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setVersion(ctx context.Context, r *interp.Runner, to string) error {
|
||||||
|
fl, err := syntax.NewParser().Parse(strings.NewReader("version='"+to+"'"), "")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return r.Run(ctx, fl)
|
||||||
|
}
|
||||||
|
|
||||||
func uniq(ss ...*[]string) {
|
func uniq(ss ...*[]string) {
|
||||||
for _, s := range ss {
|
for _, s := range ss {
|
||||||
slices.Sort(*s)
|
slices.Sort(*s)
|
||||||
|
|
|
@ -226,15 +226,11 @@ The rest of the scripts are available in all packages.
|
||||||
|
|
||||||
This section documents user-defined functions that can be added to build scripts. Any functions marked with `(*)` are required.
|
This section documents user-defined functions that can be added to build scripts. Any functions marked with `(*)` are required.
|
||||||
|
|
||||||
All functions are executed in the `$srcdir` directory
|
All functions except for `version()` are executed in the `$srcdir` directory
|
||||||
|
|
||||||
### prepare
|
|
||||||
|
|
||||||
The `prepare()` function runs first. It is meant to prepare the sources for building and packaging. This is the function in which patches should be applied, for example, by the `patch` command, and where tools like `go generate` should be executed.
|
|
||||||
|
|
||||||
### version
|
### version
|
||||||
|
|
||||||
The `version()` function updates the `version` variable. This allows for automatically deriving the version from sources. This is most useful for git packages, which usually don't need to be changed, so their `version` variable stays the same.
|
The `version()` function is the first to run. It updates the `version` variable. This allows for automatically deriving the version from sources. This is most useful for git packages, which usually don't need to be changed, so their `version` variable stays the same.
|
||||||
|
|
||||||
An example of using this for git:
|
An example of using this for git:
|
||||||
|
|
||||||
|
@ -247,6 +243,12 @@ version() {
|
||||||
|
|
||||||
The AUR equivalent is the [`pkgver()` function](https://wiki.archlinux.org/title/VCS_package_guidelines#The_pkgver()_function)
|
The AUR equivalent is the [`pkgver()` function](https://wiki.archlinux.org/title/VCS_package_guidelines#The_pkgver()_function)
|
||||||
|
|
||||||
|
This function does not run in `$srcdir` because it is executed before the source directory is even created. Instead, it runs in `$repodir`.
|
||||||
|
|
||||||
|
### prepare
|
||||||
|
|
||||||
|
The `prepare()` function is meant to prepare the sources for building and packaging. This is the function in which patches should be applied, for example, by the `patch` command, and where tools like `go generate` should be executed.
|
||||||
|
|
||||||
### build
|
### build
|
||||||
|
|
||||||
The `build()` function is where the package is actually built. Use the same commands that would be used to manually compile the software. Often, this function is just one line:
|
The `build()` function is where the package is actually built. Use the same commands that would be used to manually compile the software. Often, this function is just one line:
|
||||||
|
|
Loading…
Reference in New Issue