fix: fix new sdk builder adjustment
Some checks failed
CI Workflow / Check GoReleaser config (pull_request) Successful in 6s
CI Workflow / CI run build and linting (pull_request) Failing after 53s
CI Workflow / Code coverage report (pull_request) Has been skipped
CI Workflow / CI run tests (pull_request) Failing after 15m56s
CI Workflow / Test readiness for publishing provider (pull_request) Successful in 23m35s

This commit is contained in:
Marcel S. Henselin 2026-03-02 08:50:16 +01:00
parent cc08fca97a
commit 469ed9e056
6 changed files with 223 additions and 93 deletions

View file

@ -41,6 +41,8 @@ type Builder struct {
SkipClone bool
SkipCleanup bool
PackagesOnly bool
Verbose bool
Debug bool
}
func (b *Builder) Build() error {
@ -56,13 +58,17 @@ func (b *Builder) Build() error {
if root == nil || *root == "" {
return fmt.Errorf("unable to determine root directory from git")
}
slog.Info(" ... using root directory", "dir", *root)
if b.Verbose {
slog.Info(" ... using root directory", "dir", *root)
}
if !b.PackagesOnly {
slog.Info(" ... Checking needed commands available")
err := checkCommands([]string{})
if err != nil {
return err
if b.Verbose {
slog.Info(" ... Checking needed commands available")
}
chkErr := checkCommands([]string{})
if chkErr != nil {
return chkErr
}
}
@ -92,14 +98,13 @@ func (b *Builder) Build() error {
}
slog.Info("Creating oas repo dir", "dir", fmt.Sprintf("%s/%s", *root, OAS_REPO_NAME))
repoDir, err := createRepoDir(genDir, OAS_REPO, OAS_REPO_NAME, b.SkipClone)
repoDir, err := b.createRepoDir(genDir, OAS_REPO, OAS_REPO_NAME, b.SkipClone)
if err != nil {
return fmt.Errorf("%s", err.Error())
}
slog.Info("Retrieving versions from subdirs")
// TODO - major
verMap, err := getVersions(repoDir)
verMap, err := b.getVersions(repoDir)
if err != nil {
return fmt.Errorf("%s", err.Error())
}
@ -111,7 +116,7 @@ func (b *Builder) Build() error {
}
slog.Info("Creating OAS dir")
err = os.MkdirAll(path.Join(genDir, "oas"), 0o755) //nolint:gosec // this dir is not sensitive, so we can use 0755
err = os.MkdirAll(path.Join(genDir, "oas", "legacy"), 0o755) //nolint:gosec // this dir is not sensitive, so we can use 0755
if err != nil {
return err
}
@ -131,7 +136,7 @@ func (b *Builder) Build() error {
itemVersion,
fmt.Sprintf("%s.json", baseService),
)
dstFile := path.Join(genDir, "oas", fmt.Sprintf("%s.json", service))
dstFile := path.Join(genDir, "oas", "legacy", fmt.Sprintf("%s.json", service))
_, err = copyFile(srcFile, dstFile)
if err != nil {
return fmt.Errorf("%s", err.Error())
@ -534,6 +539,7 @@ func generateServiceFiles(rootDir, generatorDir string) error {
oasFile := path.Join(
generatorDir,
"oas",
"legacy",
fmt.Sprintf("%s%s.json", service.Name(), svcVersion.Name()),
)
if _, oasErr := os.Stat(oasFile); os.IsNotExist(oasErr) {
@ -919,22 +925,32 @@ func getOnlyLatest(m map[string]version) (map[string]version, error) {
return tmpMap, nil
}
func getVersions(dir string) (map[string]version, error) {
func (b *Builder) getVersions(dir string) (map[string]version, error) {
slog.Info("Retrieving versions from subdirs", "func", "getVersions")
res := make(map[string]version)
children, err := os.ReadDir(path.Join(dir, "services"))
if err != nil {
return nil, err
}
if len(children) < 1 {
slog.Error("found no children", "dir", path.Join(dir, "services"))
}
for _, entry := range children {
if !entry.IsDir() {
slog.Info("entry is no dir", "entry", entry.Name())
continue
}
if b.Verbose {
slog.Info("getting versions", "svc", entry.Name())
}
versions, err := os.ReadDir(path.Join(dir, "services", entry.Name()))
if err != nil {
return nil, err
}
m, err2 := extractVersions(entry.Name(), versions)
m, err2 := b.extractVersions(entry.Name(), versions)
if err2 != nil {
return m, err2
}
@ -945,8 +961,12 @@ func getVersions(dir string) (map[string]version, error) {
return res, nil
}
func extractVersions(service string, versionDirs []os.DirEntry) (map[string]version, error) {
func (b *Builder) extractVersions(service string, versionDirs []os.DirEntry) (map[string]version, error) {
res := make(map[string]version)
if len(versionDirs) < 1 {
slog.Error("list of version directories is empty")
return nil, nil
}
for _, vDir := range versionDirs {
if !vDir.IsDir() {
continue
@ -954,6 +974,9 @@ func extractVersions(service string, versionDirs []os.DirEntry) (map[string]vers
r := regexp.MustCompile(`v(\d+)([a-z]+)(\d*)`)
matches := r.FindAllStringSubmatch(vDir.Name(), -1)
if matches == nil {
if b.Debug {
slog.Warn("item did not fulfill regex", "item", vDir.Name())
}
continue
}
svc, ver, err := handleVersion(service, matches[0])
@ -992,20 +1015,23 @@ func handleVersion(service string, match []string) (*string, *version, error) {
return &resStr, &version{verString: verString, major: majVer, minor: minVer}, nil
}
func createRepoDir(root, repoUrl, repoName string, skipClone bool) (string, error) {
func (b *Builder) createRepoDir(root, repoUrl, repoName string, skipClone bool) (string, error) {
targetDir := path.Join(root, repoName)
if !skipClone {
if fileExists(targetDir) {
slog.Warn("target dir exists - skipping", "targetDir", targetDir)
return targetDir, nil
}
_, err := git.Clone(
out, err := git.Clone(
clone.Repository(repoUrl),
clone.Directory(targetDir),
)
if err != nil {
return "", err
}
if b.Verbose {
slog.Info("git clone result", "output", out)
}
}
return targetDir, nil
}

View file

@ -10,6 +10,8 @@ var (
skipCleanup bool
skipClone bool
packagesOnly bool
verbose bool
debug bool
)
var buildCmd = &cobra.Command{
@ -21,6 +23,8 @@ var buildCmd = &cobra.Command{
SkipClone: skipClone,
SkipCleanup: skipCleanup,
PackagesOnly: packagesOnly,
Verbose: verbose,
Debug: debug,
}
return b.Build()
},
@ -32,6 +36,8 @@ func NewBuildCmd() *cobra.Command {
func init() { //nolint:gochecknoinits // This is the standard way to set up Cobra commands
buildCmd.Flags().BoolVarP(&skipCleanup, "skip-clean", "c", false, "Skip cleanup steps")
buildCmd.Flags().BoolVarP(&debug, "debug", "d", false, "Enable debug output")
buildCmd.Flags().BoolVarP(&skipClone, "skip-clone", "g", false, "Skip cloning from git")
buildCmd.Flags().BoolVarP(&packagesOnly, "packages-only", "p", false, "Only generate packages")
buildCmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "verbose - show more logs")
}