Skip to content
32 changes: 31 additions & 1 deletion cmd/pythonBuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package cmd

import (
"fmt"
"os"
"path/filepath"
"regexp"
"strings"

"github.com/SAP/jenkins-library/pkg/buildsettings"
"github.com/SAP/jenkins-library/pkg/command"
Expand Down Expand Up @@ -85,6 +89,32 @@ func runPythonBuild(config *pythonBuildOptions, telemetryData *telemetry.CustomD
return fmt.Errorf("failed to publish: %w", err)
}
}

// After build, rename all dist/* files with underscores to dashes in the base name
distDir := "dist"
files, err := os.ReadDir(distDir)
if err == nil {
underscoreName := regexp.MustCompile(`_`)
for _, f := range files {
oldName := f.Name()
// Only rename if the base name contains an underscore and is a typical Python artifact
if strings.Contains(oldName, "_") && (strings.HasSuffix(oldName, ".tar.gz")) {
newName := underscoreName.ReplaceAllStringFunc(oldName, func(s string) string {
return "-"
})
oldPath := filepath.Join(distDir, oldName)
newPath := filepath.Join(distDir, newName)
if err := os.Rename(oldPath, newPath); err != nil {
log.Entry().Warnf("Failed to rename artifact %s to %s: %v", oldName, newName, err)
} else {
log.Entry().Infof("Renamed artifact %s to %s", oldName, newName)
}
}
}
} else {
log.Entry().Warnf("Could not read dist directory for artifact renaming: %v", err)
}

return nil
}

Expand All @@ -104,7 +134,7 @@ func createBuildSettingsInfo(config *pythonBuildOptions) (string, error) {
}
buildSettingsInfo, err := buildsettings.CreateBuildSettingsInfo(&pythonConfig, stepName)
if err != nil {
log.Entry().Warnf("failed to create build settings info: %v", err)
return "", err
}
return buildSettingsInfo, nil
}
Loading