Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions cmd/stackpack/stackpack_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ func StackpackPackageCommand(cli *di.Deps) *cobra.Command {
args := &PackageArgs{}
cmd := &cobra.Command{
Use: "package",
Short: "Package a stackpack into a zip file",
Long: `Package a stackpack into a zip file.
Short: "Package a stackpack into an .sts file",
Long: `Package a stackpack into an .sts file.

Creates a zip file containing all required stackpack files and directories:
Creates an .sts file containing all required stackpack files and directories:
- provisioning/ (directory)
- README.md (file)
- resources/ (directory)
- stackpack.yaml (file)

The zip file is named <stackpack_name>-<version>.zip where the name and
The .sts file is named <stackpack_name>-<version>.sts where the name and
version are extracted from stackpack.yaml and created in the current directory.`,
Example: `# Package stackpack in current directory
sts stackpack package
Expand All @@ -94,16 +94,16 @@ sts stackpack package
sts stackpack package -d ./my-stackpack

# Package with custom archive filename
sts stackpack package -f my-custom-archive.zip
sts stackpack package -f my-custom-archive.sts

# Force overwrite existing zip file
# Force overwrite existing .sts file
sts stackpack package --force`,
RunE: cli.CmdRunE(RunStackpackPackageCommand(args)),
}

cmd.Flags().StringVarP(&args.StackpackDir, "stackpack-directory", "d", "", "Path to stackpack directory (defaults to current directory)")
cmd.Flags().StringVarP(&args.ArchiveFile, "archive-file", "f", "", "Path to the zip file to create (defaults to <stackpack_name>-<version>.zip in current directory)")
cmd.Flags().BoolVar(&args.Force, "force", false, "Overwrite existing zip file without prompting")
cmd.Flags().StringVarP(&args.ArchiveFile, "archive-file", "f", "", "Path to the .sts file to create (defaults to <stackpack_name>-<version>.sts in current directory)")
cmd.Flags().BoolVar(&args.Force, "force", false, "Overwrite existing .sts file without prompting")

return cmd
}
Expand Down Expand Up @@ -140,7 +140,7 @@ func RunStackpackPackageCommand(args *PackageArgs) func(cli *di.Deps, cmd *cobra
if err != nil {
return common.NewRuntimeError(fmt.Errorf("failed to get current working directory: %w", err))
}
zipFileName := fmt.Sprintf("%s-%s.zip", stackpackInfo.Name, stackpackInfo.Version)
zipFileName := fmt.Sprintf("%s-%s.sts", stackpackInfo.Name, stackpackInfo.Version)
args.ArchiveFile = filepath.Join(currentDir, zipFileName)
} else {
// Convert to absolute path
Expand All @@ -156,9 +156,9 @@ func RunStackpackPackageCommand(args *PackageArgs) func(cli *di.Deps, cmd *cobra
return common.NewCLIArgParseError(err)
}

// Check if zip file exists and handle force flag
// Check if .sts file exists and handle force flag
if _, err := os.Stat(args.ArchiveFile); err == nil && !args.Force {
return common.NewRuntimeError(fmt.Errorf("zip file already exists: %s (use --force to overwrite)", args.ArchiveFile))
return common.NewRuntimeError(fmt.Errorf(".sts file already exists: %s (use --force to overwrite)", args.ArchiveFile))
}

// Create output directory if it doesn't exist
Expand All @@ -167,9 +167,9 @@ func RunStackpackPackageCommand(args *PackageArgs) func(cli *di.Deps, cmd *cobra
return common.NewRuntimeError(fmt.Errorf("failed to create output directory: %w", err))
}

// Create zip file
// Create .sts file
if err := createStackpackZip(args.StackpackDir, args.ArchiveFile); err != nil {
return common.NewRuntimeError(fmt.Errorf("failed to create zip file: %w", err))
return common.NewRuntimeError(fmt.Errorf("failed to create .sts file: %w", err))
}

if cli.IsJson() {
Expand All @@ -184,7 +184,7 @@ func RunStackpackPackageCommand(args *PackageArgs) func(cli *di.Deps, cmd *cobra
cli.Printer.Successf("Stackpack packaged successfully!")
cli.Printer.PrintLn("")
cli.Printer.PrintLn(fmt.Sprintf("Stackpack: %s (v%s)", stackpackInfo.Name, stackpackInfo.Version))
cli.Printer.PrintLn(fmt.Sprintf("Zip file: %s", args.ArchiveFile))
cli.Printer.PrintLn(fmt.Sprintf(".sts file: %s", args.ArchiveFile))
}

return nil
Expand All @@ -207,7 +207,7 @@ func validateStackpackDirectory(dir string) error {
func createStackpackZip(sourceDir, zipPath string) error {
zipFile, err := os.Create(zipPath)
if err != nil {
return fmt.Errorf("failed to create zip file: %w", err)
return fmt.Errorf("failed to create .sts file: %w", err)
}
defer zipFile.Close()

Expand Down
12 changes: 6 additions & 6 deletions cmd/stackpack/stackpack_package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestStackpackPackageCommand_DefaultBehavior(t *testing.T) {
require.NoError(t, err)

// Verify zip file was created in current directory
expectedZipPath := filepath.Join(tempDir, "test-stackpack-1.0.0.zip")
expectedZipPath := filepath.Join(tempDir, "test-stackpack-1.0.0.sts")
_, err = os.Stat(expectedZipPath)
assert.NoError(t, err, "Zip file should be created")

Expand All @@ -97,7 +97,7 @@ func TestStackpackPackageCommand_CustomArchiveFile(t *testing.T) {
require.NoError(t, os.MkdirAll(stackpackDir, 0755))
createTestStackpack(t, stackpackDir, "my-stackpack", "2.1.0")

customZipPath := filepath.Join(tempDir, "custom-name.zip")
customZipPath := filepath.Join(tempDir, "custom-name.sts")
cli, cmd := setupStackPackPackageCmd(t)

_, err = di.ExecuteCommandWithContext(&cli.Deps, cmd, "-d", stackpackDir, "-f", customZipPath)
Expand All @@ -122,7 +122,7 @@ func TestStackpackPackageCommand_ForceFlag(t *testing.T) {
require.NoError(t, os.MkdirAll(stackpackDir, 0755))
createTestStackpack(t, stackpackDir, "test-stackpack", "1.0.0")

zipPath := filepath.Join(tempDir, "test-stackpack-1.0.0.zip")
zipPath := filepath.Join(tempDir, "test-stackpack-1.0.0.sts")

// Create existing zip file
require.NoError(t, os.WriteFile(zipPath, []byte("existing content"), 0644))
Expand All @@ -132,7 +132,7 @@ func TestStackpackPackageCommand_ForceFlag(t *testing.T) {
// Test without force flag - should fail
_, err = di.ExecuteCommandWithContext(&cli.Deps, cmd, "-d", stackpackDir, "-f", zipPath)
require.Error(t, err)
assert.Contains(t, err.Error(), "zip file already exists")
assert.Contains(t, err.Error(), ".sts file already exists")
assert.Contains(t, err.Error(), "--force")

// Test with force flag - should succeed
Expand Down Expand Up @@ -178,7 +178,7 @@ func TestStackpackPackageCommand_JSONOutput(t *testing.T) {
assert.Equal(t, true, jsonOutput["success"])
assert.Equal(t, "json-test", jsonOutput["stackpack_name"])
assert.Equal(t, "3.0.0", jsonOutput["stackpack_version"])
assert.Contains(t, jsonOutput["zip_file"], "json-test-3.0.0.zip")
assert.Contains(t, jsonOutput["zip_file"], "json-test-3.0.0.sts")
assert.Contains(t, jsonOutput["source_dir"], stackpackDir)

// Verify no text output for JSON mode
Expand Down Expand Up @@ -329,7 +329,7 @@ func TestStackpackPackageCommand_CreateOutputDirectory(t *testing.T) {

// Create nested output directory path that doesn't exist
outputDir := filepath.Join(tempDir, "output", "nested", "path")
zipPath := filepath.Join(outputDir, "custom.zip")
zipPath := filepath.Join(outputDir, "custom.sts")

cli, cmd := setupStackPackPackageCmd(t)

Expand Down
10 changes: 5 additions & 5 deletions cmd/stackpack/stackpack_test_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ This command will:
1. Read the stackpack name and version from ` + stackpackConfigFile + `
2. Create a temporary copy of the stackpack directory
3. Update the version in the temporary copy with -cli-test.N suffix
4. Package the stackpack from the temporary copy into a zip file
5. Upload the zip file to the server (with confirmation)
4. Package the stackpack from the temporary copy into an .sts file
5. Upload the .sts file to the server (with confirmation)
6. Install the stackpack (if not installed) or upgrade it (if already installed)

The original stackpack directory is left untouched. The version is automatically incremented for each test run.
Expand Down Expand Up @@ -183,7 +183,7 @@ func RunStackpackTestCommand(args *TestArgs) di.CmdWithApiFn {

// Set archive file in current directory
currentDir, _ := os.Getwd()
packageArgs.ArchiveFile = filepath.Join(currentDir, fmt.Sprintf("%s-%s.zip", originalInfo.Name, newVersion))
packageArgs.ArchiveFile = filepath.Join(currentDir, fmt.Sprintf("%s-%s.sts", originalInfo.Name, newVersion))

if err := runPackageStep(cli, packageArgs); err != nil {
return err
Expand Down Expand Up @@ -241,9 +241,9 @@ func RunStackpackTestCommand(args *TestArgs) di.CmdWithApiFn {
cli.Printer.PrintLn("")
cli.Printer.Success("🎉 Test sequence completed successfully!")

// Clean up zip file
// Clean up .sts file
if err := os.Remove(packageArgs.ArchiveFile); err != nil {
cli.Printer.PrintLn(fmt.Sprintf("Note: Could not clean up zip file %s: %v", packageArgs.ArchiveFile, err))
cli.Printer.PrintLn(fmt.Sprintf("Note: Could not clean up .sts file %s: %v", packageArgs.ArchiveFile, err))
}

return nil
Expand Down
Binary file removed cmd/stackpack/test-stackpack-1.0.0-cli-test.10000.zip
Binary file not shown.