From eb1c1a1d8c77b72361250d6c8f995a3506ff3957 Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Fri, 15 Nov 2024 16:25:09 +0300 Subject: [PATCH] fix: add alt prefix for release --- pkg/build/build.go | 53 ++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/pkg/build/build.go b/pkg/build/build.go index ee1022d..b00a969 100644 --- a/pkg/build/build.go +++ b/pkg/build/build.go @@ -36,6 +36,9 @@ import ( _ "github.com/goreleaser/nfpm/v2/arch" _ "github.com/goreleaser/nfpm/v2/deb" _ "github.com/goreleaser/nfpm/v2/rpm" + "mvdan.cc/sh/v3/expand" + "mvdan.cc/sh/v3/interp" + "mvdan.cc/sh/v3/syntax" "github.com/goreleaser/nfpm/v2" "github.com/goreleaser/nfpm/v2/files" @@ -52,9 +55,6 @@ import ( "plemya-x.ru/alr/pkg/loggerctx" "plemya-x.ru/alr/pkg/manager" "plemya-x.ru/alr/pkg/repos" - "mvdan.cc/sh/v3/expand" - "mvdan.cc/sh/v3/interp" - "mvdan.cc/sh/v3/syntax" ) // BuildPackage builds the script at the given path. It returns two slices. One contains the paths @@ -161,7 +161,7 @@ func BuildPackage(ctx context.Context, opts types.BuildOpts) ([]string, []string pkgFormat := getPkgFormat(opts.Manager) - pkgInfo, err := buildPkgMetadata(vars, dirs, pkgFormat, append(repoDeps, builtNames...)) + pkgInfo, err := buildPkgMetadata(vars, dirs, pkgFormat, info, append(repoDeps, builtNames...)) if err != nil { return nil, nil, err } @@ -481,23 +481,18 @@ func executeFunctions(ctx context.Context, dec *decoder.Decoder, dirs types.Dire } // buildPkgMetadata builds the metadata for the package that's going to be built. -func buildPkgMetadata(vars *types.BuildVars, dirs types.Directories, pkgFormat string, deps []string) (*nfpm.Info, error) { - pkgInfo := &nfpm.Info{ - Name: vars.Name, - Description: vars.Description, - Arch: cpu.Arch(), - Platform: "linux", - Version: vars.Version, - Release: strconv.Itoa(vars.Release), - Homepage: vars.Homepage, - License: strings.Join(vars.Licenses, ", "), - Maintainer: vars.Maintainer, - Overridables: nfpm.Overridables{ - Conflicts: vars.Conflicts, - Replaces: vars.Replaces, - Provides: vars.Provides, - Depends: deps, - }, +func buildPkgMetadata(vars *types.BuildVars, dirs types.Directories, pkgFormat string, info *distro.OSRelease, deps []string) (*nfpm.Info, error) { + pkgInfo := getBasePkgInfo(vars) + pkgInfo.Description = vars.Description + pkgInfo.Platform = "linux" + pkgInfo.Homepage = vars.Homepage + pkgInfo.License = strings.Join(vars.Licenses, ", ") + pkgInfo.Maintainer = vars.Maintainer + pkgInfo.Overridables = nfpm.Overridables{ + Conflicts: vars.Conflicts, + Replaces: vars.Replaces, + Provides: vars.Provides, + Depends: deps, } if pkgFormat == "apk" { @@ -507,6 +502,10 @@ func buildPkgMetadata(vars *types.BuildVars, dirs types.Directories, pkgFormat s }) } + if info.ID == "altlinux" { + pkgInfo.Release = "alt" + pkgInfo.Release + } + if vars.Epoch != 0 { pkgInfo.Epoch = strconv.FormatUint(uint64(vars.Epoch), 10) } @@ -643,16 +642,20 @@ func checkForBuiltPackage(mgr manager.Manager, vars *types.BuildVars, pkgFormat, return pkgPath, true, nil } -// pkgFileName returns the filename of the package if it were to be built. -// This is used to check if the package has already been built. -func pkgFileName(vars *types.BuildVars, pkgFormat string) (string, error) { - pkgInfo := &nfpm.Info{ +func getBasePkgInfo(vars *types.BuildVars) *nfpm.Info { + return &nfpm.Info{ Name: vars.Name, Arch: cpu.Arch(), Version: vars.Version, Release: strconv.Itoa(vars.Release), Epoch: strconv.FormatUint(uint64(vars.Epoch), 10), } +} + +// pkgFileName returns the filename of the package if it were to be built. +// This is used to check if the package has already been built. +func pkgFileName(vars *types.BuildVars, pkgFormat string) (string, error) { + pkgInfo := getBasePkgInfo(vars) packager, err := nfpm.Get(pkgFormat) if err != nil {