From 12c0e81f6e4de53da2099fdf286658778fab11c6 Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Tue, 27 Oct 2026 14:39:58 +1100 Subject: [PATCH] fix: Create output directory if required when creating zip package --- pkg/cmd/package/support/pack.go | 6 ++++++ pkg/cmd/package/zip/create/create.go | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/cmd/package/support/pack.go b/pkg/cmd/package/support/pack.go index 8904c290..09bb9f5e 100644 --- a/pkg/cmd/package/support/pack.go +++ b/pkg/cmd/package/support/pack.go @@ -235,6 +235,12 @@ func BuildPackage(opts *PackageCreateOptions, outFileName string) (*os.File, err } func BuildPackageWithContents(opts *PackageCreateOptions, outFileName string, contents *PackageContents) (*os.File, error) { + // Try and create the output folder + err := os.MkdirAll(opts.OutFolder.Value, os.ModePerm) + if err != nil { + return nil, fmt.Errorf("could not create output directory: %w", err) + } + outFilePath := filepath.Join(opts.OutFolder.Value, outFileName) outPath, err := filepath.Abs(opts.OutFolder.Value) if err != nil { diff --git a/pkg/cmd/package/zip/create/create.go b/pkg/cmd/package/zip/create/create.go index d90c45b0..e0bb6be0 100644 --- a/pkg/cmd/package/zip/create/create.go +++ b/pkg/cmd/package/zip/create/create.go @@ -78,9 +78,9 @@ func createRun(cmd *cobra.Command, opts *pack.PackageCreateOptions) error { fmt.Fprintf(opts.Writer, "\nAutomation Command: %s\n", autoCmd) } - outFilePath := pack.BuildOutFileName("zip", opts.Id.Value, opts.Version.Value) + outFileName := pack.BuildOutFileName("zip", opts.Id.Value, opts.Version.Value) - zip, err := pack.BuildPackage(opts, outFilePath) + zip, err := pack.BuildPackage(opts, outFileName) if zip != nil { pack.PrintPackageCreated(cmd, outputFormat, zip.Name()) }