Skip to content

Commit

Permalink
add warning messages to magefile
Browse files Browse the repository at this point in the history
  • Loading branch information
fearful-symmetry committed Oct 10, 2023
1 parent 2f18b1e commit 3b90cfd
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -979,10 +979,10 @@ func packageAgent(platforms []string, packagingFn func()) {
panic(err)
}

packagesMissing := false
packagesCopied := 0

if !requiredPackagesPresent(pwd, b, packageVersion, requiredPackages) {
fmt.Printf("--- Package %s\n", pwd)
cmd := exec.Command("mage", "package")
cmd.Dir = pwd
cmd.Stdout = os.Stdout
Expand All @@ -1008,6 +1008,14 @@ func packageAgent(platforms []string, packagingFn func()) {
targetPath := filepath.Join(archivePath, rp)
os.MkdirAll(targetPath, 0755)
for _, f := range files {
// safety check; if the user has an older version of the beats repo,
// for example right after a relase where you've `git pulled` from on repo and not the other,
// they might end up with a mishmash of packages from different versions.
// check to see if we have mismatched versions.
if !strings.Contains(f, packageVersion) {
fmt.Printf("WARNING: the file %s doesn't match agent version %s, beats might be out of date\n", f, packageVersion)
}

targetFile := filepath.Join(targetPath, filepath.Base(f))
packagesCopied += 1
if err := sh.Copy(targetFile, f); err != nil {
Expand All @@ -1017,8 +1025,8 @@ func packageAgent(platforms []string, packagingFn func()) {
}
// a very basic footcannon protector; if packages are missing and we need to rebuild them, check to see if those files were copied
// if we needed to repackage beats but still somehow copied nothing, could indicate an issue. Usually due to beats and agent being at different versions.
if packagesMissing && packagesCopied == 0 {
fmt.Printf(">>> WARNING: no packages were copied, but we repackaged beats anyway. Check binary to see if intended beats are there.")
if packagesCopied == 0 {
fmt.Printf(">>> WARNING: no packages were copied, but we repackaged beats anyway. Check binary to see if intended beats are there.\n")
}
}
}
Expand Down Expand Up @@ -1153,6 +1161,7 @@ func copyComponentSpecs(componentName, versionedDropPath string) (string, error)
targetPath := filepath.Join(versionedDropPath, specFileName)

if _, err := os.Stat(targetPath); err != nil {
fmt.Printf(">> File %s does not exist, reverting to local specfile\n", targetPath)
// spec not present copy from local
sourceSpecFile := filepath.Join("specs", specFileName)
if mg.Verbose() {
Expand Down

0 comments on commit 3b90cfd

Please sign in to comment.