Skip to content

Commit 446e929

Browse files
committed
cleanups
1 parent 343ea91 commit 446e929

2 files changed

Lines changed: 20 additions & 31 deletions

File tree

dev-tools/mage/settings.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,9 @@ func (s *Settings) WithManifestInfo(ctx context.Context) (*Settings, error) {
906906
// VersionWithBuildMetadata preserves the build ID for Independent Agent Releases while
907907
// omitting the prerelease — snapshot state is captured in Build.Snapshot.
908908
clone.Packaging.AgentPackageVersion = parsedVersion.VersionWithBuildMetadata()
909-
clone.Build.AgentCoreCommitHash = agentCoreProject.CommitHash
909+
if clone.Packaging.CoreSource == CoreSourceManifest {
910+
clone.Build.AgentCoreCommitHash = agentCoreProject.CommitHash
911+
}
910912
clone.Build.DependenciesVersion = parsedVersion.VersionWithPrerelease()
911913
return clone, nil
912914
}

magefile.go

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -645,48 +645,35 @@ func Package(ctx context.Context) error {
645645
return errors.New("elastic-agent package is expected to build at least one platform package")
646646
}
647647

648-
switch cfg.Packaging.CoreSource {
649-
case devtools.CoreSourceLocal, "":
650-
// Apply only snapshot and version from the manifest — not the commit hash.
651-
// AgentCoreCommitHash() will return the git HEAD hash (the commit the
652-
// compiler actually baked into the binary).
653-
cfgWithManifest, err := cfg.WithManifestInfo(ctx)
654-
if err != nil {
655-
return fmt.Errorf("failed downloading manifest: %w", err)
656-
}
657-
cfg = cfg.WithSnapshot(cfgWithManifest.Build.Snapshot).WithAgentCoreVersion(cfgWithManifest.AgentCoreVersion())
658-
ctx = devtools.ContextWithSettings(ctx, cfg)
659-
mg.CtxDeps(ctx, PackageAgentCore)
660-
case devtools.CoreSourceManifest:
661-
var err error
662-
cfg, err = cfg.WithManifestInfo(ctx)
663-
if err != nil {
664-
return fmt.Errorf("failed downloading manifest: %w", err)
665-
}
666-
if cfg.Packaging.Manifest == nil {
667-
return errors.New("AGENT_CORE_SOURCE=manifest requires MANIFEST_URL to be set")
668-
}
669-
ctx = devtools.ContextWithSettings(ctx, cfg)
670-
default:
671-
return fmt.Errorf("unknown AGENT_CORE_SOURCE=%q (want %q or %q)",
672-
cfg.Packaging.CoreSource, devtools.CoreSourceLocal, devtools.CoreSourceManifest)
648+
cfg, err := cfg.WithManifestInfo(ctx)
649+
if err != nil {
650+
return fmt.Errorf("failed downloading manifest: %w", err)
673651
}
674652

675-
pkgSpec, err := devtools.LoadElasticAgentPackageSpec(cfg.ElasticBeatsDir)
676-
if err != nil {
677-
return err
653+
if cfg.Packaging.CoreSource == devtools.CoreSourceManifest && cfg.Packaging.Manifest == nil {
654+
return errors.New("AGENT_CORE_SOURCE=manifest requires MANIFEST_URL to be set")
678655
}
679656

680-
if cfg.Packaging.ManifestURL != "" {
657+
pkgSpec, err := devtools.LoadElasticAgentPackageSpec(cfg.ElasticBeatsDir)
658+
659+
if cfg.Packaging.Manifest != nil {
681660
var filters []packaging.ComponentFilter
682-
if cfg.Packaging.CoreSource != devtools.CoreSourceManifest {
661+
switch cfg.Packaging.CoreSource {
662+
case devtools.CoreSourceLocal, "":
663+
mg.CtxDeps(ctx, PackageAgentCore)
683664
// Skip the manifest's elastic-agent-core; we compiled it above.
684665
filters = append(filters, packaging.WithoutProjectName(devtools.AgentCoreProjectName))
666+
case devtools.CoreSourceManifest:
667+
668+
default:
669+
return fmt.Errorf("unknown AGENT_CORE_SOURCE=%q (want %q or %q)",
670+
cfg.Packaging.CoreSource, devtools.CoreSourceLocal, devtools.CoreSourceManifest)
685671
}
686672
if err := downloadManifest(ctx, cfg, pkgSpec, filters...); err != nil {
687673
return fmt.Errorf("failed downloading manifest components: %w", err)
688674
}
689675
}
676+
690677
return packageAgent(ctx, cfg, pkgSpec)
691678
}
692679

0 commit comments

Comments
 (0)