mirror of
https://github.com/EnumeratedDev/bpm.git
synced 2026-09-16 10:36:12 +00:00
Change 'extract_to_bpm_source' field to 'extract_to' and 'clone_to'
This commit is contained in:
+44
-12
@@ -338,21 +338,41 @@ func CompileSourcePackage(archiveFilename, outputDirectory string, skipChecks bo
|
|||||||
|
|
||||||
func downloadPackageFiles(pkgInfo *PackageInfo, tempDirectory string) error {
|
func downloadPackageFiles(pkgInfo *PackageInfo, tempDirectory string) error {
|
||||||
for _, download := range pkgInfo.Downloads {
|
for _, download := range pkgInfo.Downloads {
|
||||||
// Replace variables in download url
|
// Replace variables
|
||||||
downloadUrl := download.Url
|
replaceVars := func(s string) string {
|
||||||
downloadUrl, err := envsubst.Eval(downloadUrl, func(s string) string {
|
|
||||||
switch s {
|
switch s {
|
||||||
case "BPM_PKG_VERSION":
|
case "BPM_PKG_VERSION":
|
||||||
return pkgInfo.Version
|
return pkgInfo.Version
|
||||||
case "BPM_PKG_NAME":
|
case "BPM_PKG_NAME":
|
||||||
return pkgInfo.Name
|
return pkgInfo.Name
|
||||||
|
case "BPM_SOURCE":
|
||||||
|
return path.Join(tempDirectory, "source/")
|
||||||
default:
|
default:
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
|
downloadUrl, err := envsubst.Eval(strings.TrimSpace(download.Url), replaceVars)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
extractTo, err := envsubst.Eval(strings.TrimSpace(download.ExtractTo), replaceVars)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
cloneTo, err := envsubst.Eval(strings.TrimSpace(download.CloneTo), replaceVars)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make relative paths absolute
|
||||||
|
if extractTo != "" && extractTo[0] != '/' {
|
||||||
|
extractTo = path.Join(tempDirectory, extractTo)
|
||||||
|
}
|
||||||
|
// Make relative paths absolute
|
||||||
|
if cloneTo != "" && cloneTo[0] != '/' {
|
||||||
|
cloneTo = path.Join(tempDirectory, cloneTo)
|
||||||
|
}
|
||||||
|
|
||||||
switch download.Type {
|
switch download.Type {
|
||||||
case "", "file":
|
case "", "file":
|
||||||
@@ -390,8 +410,12 @@ func downloadPackageFiles(pkgInfo *PackageInfo, tempDirectory string) error {
|
|||||||
if !download.NoExtract && (strings.Contains(filepath, ".tar") || strings.HasSuffix(filepath, ".tgz")) {
|
if !download.NoExtract && (strings.Contains(filepath, ".tar") || strings.HasSuffix(filepath, ".tgz")) {
|
||||||
cmd := exec.Command("tar", "xvf", filepath, "--strip-components="+strconv.Itoa(download.ExtractStripComponents))
|
cmd := exec.Command("tar", "xvf", filepath, "--strip-components="+strconv.Itoa(download.ExtractStripComponents))
|
||||||
cmd.Dir = tempDirectory
|
cmd.Dir = tempDirectory
|
||||||
if download.ExtractToBPMSource {
|
if extractTo != "" {
|
||||||
cmd.Args = append(cmd.Args, "-C", path.Join(tempDirectory, "source"))
|
err := os.MkdirAll(extractTo, 0755)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
cmd.Args = append(cmd.Args, "-C", extractTo)
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
@@ -403,8 +427,12 @@ func downloadPackageFiles(pkgInfo *PackageInfo, tempDirectory string) error {
|
|||||||
}
|
}
|
||||||
} else if !download.NoExtract && strings.HasSuffix(filepath, ".zip") {
|
} else if !download.NoExtract && strings.HasSuffix(filepath, ".zip") {
|
||||||
cmd := exec.Command("unzip", filepath)
|
cmd := exec.Command("unzip", filepath)
|
||||||
if download.ExtractToBPMSource {
|
if extractTo != "" {
|
||||||
cmd.Args = append(cmd.Args, "-d", path.Join(tempDirectory, "source"))
|
err := os.MkdirAll(extractTo, 0755)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
cmd.Args = append(cmd.Args, "-d", extractTo)
|
||||||
} else {
|
} else {
|
||||||
err := os.Mkdir(path.Join(tempDirectory, strings.TrimSuffix(path.Base(filepath), ".zip")), 0755)
|
err := os.Mkdir(path.Join(tempDirectory, strings.TrimSuffix(path.Base(filepath), ".zip")), 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -444,8 +472,12 @@ func downloadPackageFiles(pkgInfo *PackageInfo, tempDirectory string) error {
|
|||||||
if gitBranch != "" {
|
if gitBranch != "" {
|
||||||
cmd.Args = slices.Insert(cmd.Args, len(cmd.Args)-1, "--branch="+gitBranch)
|
cmd.Args = slices.Insert(cmd.Args, len(cmd.Args)-1, "--branch="+gitBranch)
|
||||||
}
|
}
|
||||||
if download.ExtractToBPMSource {
|
if cloneTo != "" {
|
||||||
cmd.Args = append(cmd.Args, path.Join(tempDirectory, "source"))
|
err := os.MkdirAll(cloneTo, 0755)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
cmd.Args = append(cmd.Args, cloneTo)
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
@@ -458,8 +490,8 @@ func downloadPackageFiles(pkgInfo *PackageInfo, tempDirectory string) error {
|
|||||||
|
|
||||||
if download.Checksum != "skip" {
|
if download.Checksum != "skip" {
|
||||||
cmd := exec.Command("git", "rev-parse", "HEAD")
|
cmd := exec.Command("git", "rev-parse", "HEAD")
|
||||||
if download.ExtractToBPMSource {
|
if cloneTo != "" {
|
||||||
cmd.Dir = path.Join(tempDirectory, "source")
|
cmd.Dir = cloneTo
|
||||||
} else {
|
} else {
|
||||||
cmd.Dir = path.Join(tempDirectory, strings.TrimSuffix(path.Base(downloadUrl), ".git"))
|
cmd.Dir = path.Join(tempDirectory, strings.TrimSuffix(path.Base(downloadUrl), ".git"))
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-6
@@ -47,14 +47,20 @@ type PackageInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PackageDownload struct {
|
type PackageDownload struct {
|
||||||
Url string `yaml:"url"`
|
Url string `yaml:"url"`
|
||||||
Type string `yaml:"type,omitempty"`
|
Type string `yaml:"type,omitempty"`
|
||||||
|
Filepath string `yaml:"filepath,omitempty,omitempty"`
|
||||||
|
|
||||||
|
// Archive options
|
||||||
NoExtract bool `yaml:"no_extract,omitempty"`
|
NoExtract bool `yaml:"no_extract,omitempty"`
|
||||||
ExtractToBPMSource bool `yaml:"extract_to_bpm_source,omitempty"`
|
ExtractTo string `yaml:"extract_to,omitempty"`
|
||||||
ExtractStripComponents int `yaml:"extract_strip_components,omitempty"`
|
ExtractStripComponents int `yaml:"extract_strip_components,omitempty"`
|
||||||
GitBranch string `yaml:"git_branch,omitempty"`
|
|
||||||
Filepath string `yaml:"filepath,omitempty,omitempty"`
|
// Git options
|
||||||
Checksum string `yaml:"checksum,omitempty"`
|
CloneTo string `yaml:"clone_to,omitempty"`
|
||||||
|
GitBranch string `yaml:"git_branch,omitempty"`
|
||||||
|
|
||||||
|
Checksum string `yaml:"checksum,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PackageFileEntry struct {
|
type PackageFileEntry struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user