Skip to content

Commit

Permalink
Merge pull request #1487 from aquaproj/feat/support-templating-go-mod…
Browse files Browse the repository at this point in the history
…ule-path

feat: support template in go_install package's path attribute
  • Loading branch information
suzuki-shunsuke committed Dec 28, 2022
2 parents 56673fd + c35f3cb commit 55d337a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
11 changes: 10 additions & 1 deletion pkg/config/package.go
Expand Up @@ -311,6 +311,11 @@ func (cpkg *Package) RenderURL(rt *runtime.Runtime) (string, error) {
return s, nil
}

func (cpkg *Package) RenderPath() (string, error) {
pkgInfo := cpkg.PackageInfo
return cpkg.RenderTemplateString(pkgInfo.GetPath(), &runtime.Runtime{})
}

func (cpkg *Package) GetPkgPath(rootDir string, rt *runtime.Runtime) (string, error) {
pkgInfo := cpkg.PackageInfo
pkg := cpkg.Package
Expand All @@ -324,7 +329,11 @@ func (cpkg *Package) GetPkgPath(rootDir string, rt *runtime.Runtime) (string, er
case PkgInfoTypeGo:
return filepath.Join(rootDir, "pkgs", pkgInfo.GetType(), "github.com", pkgInfo.RepoOwner, pkgInfo.RepoName, pkg.Version, "src"), nil
case PkgInfoTypeGoInstall:
return filepath.Join(rootDir, "pkgs", pkgInfo.GetType(), pkgInfo.GetPath(), pkg.Version, "bin"), nil
p, err := cpkg.RenderPath()
if err != nil {
return "", fmt.Errorf("render Go Module Path: %w", err)
}
return filepath.Join(rootDir, "pkgs", pkgInfo.GetType(), p, pkg.Version, "bin"), nil
case PkgInfoTypeGitHubContent, PkgInfoTypeGitHubRelease:
return filepath.Join(rootDir, "pkgs", pkgInfo.GetType(), "github.com", pkgInfo.RepoOwner, pkgInfo.RepoName, pkg.Version, assetName), nil
case PkgInfoTypeHTTP:
Expand Down
7 changes: 5 additions & 2 deletions pkg/installpackage/download.go
Expand Up @@ -188,8 +188,11 @@ func (inst *Installer) download(ctx context.Context, logE *logrus.Entry, param *
}

func (inst *Installer) downloadGoInstall(ctx context.Context, pkg *config.Package, dest string, logE *logrus.Entry) error {
pkgInfo := pkg.PackageInfo
goPkgPath := pkgInfo.GetPath() + "@" + pkg.Package.Version
p, err := pkg.RenderPath()
if err != nil {
return fmt.Errorf("render Go Module Path: %w", err)
}
goPkgPath := p + "@" + pkg.Package.Version
logE.WithFields(logrus.Fields{
"gobin": dest,
"go_package_path": goPkgPath,
Expand Down

0 comments on commit 55d337a

Please sign in to comment.