Skip to content

Commit

Permalink
Merge pull request #99 from opentofu/speed_testing
Browse files Browse the repository at this point in the history
Speed up module/provider bump 2x
  • Loading branch information
cam72cam authored Dec 12, 2023
2 parents 3fd0154 + fbeaa3d commit d748f26
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 95 deletions.
4 changes: 2 additions & 2 deletions src/cmd/bump-versions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func main() {
os.Exit(1)
}

err = modules.Parallel(20, func(m module.Module) error {
err = modules.Parallel(200, func(m module.Module) error {
return m.UpdateMetadataFile()
})
if err != nil {
Expand All @@ -49,7 +49,7 @@ func main() {
logger.Error("Failed to list providers", slog.Any("err", err))
os.Exit(1)
}
err = providers.Parallel(20, func(p provider.Provider) error {
err = providers.Parallel(200, func(p provider.Provider) error {
return p.UpdateMetadataFile()
})
if err != nil {
Expand Down
14 changes: 4 additions & 10 deletions src/internal/module/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,14 @@ import (
func (m Module) UpdateMetadataFile() error {
m.Logger.Info("Beginning version bump process for module", slog.String("module", m.Namespace+"/"+m.Name+"/"+m.TargetSystem))

shouldUpdate, err := m.shouldUpdateMetadataFile()
meta, err := m.BuildMetadata()
if err != nil {
m.Logger.Error("Failed to determine update status", slog.Any("err", err))
return err
}
if !shouldUpdate {
m.Logger.Info("No version bump required")
if meta == nil {
return nil
}

meta, err := m.BuildMetadata()
if err != nil {
return err
}

return m.WriteMetadata(*meta)
}

Expand All @@ -36,7 +29,8 @@ func (m Module) UpdateMetadataFile() error {
func (m Module) BuildMetadata() (*Metadata, error) {
tags, err := m.getSemverTags()
if err != nil {
return nil, err
m.Logger.Error("Unable to fetch semver tags, skipping", slog.Any("err", err))
return nil, nil
}

meta, err := m.ReadMetadata()
Expand Down
73 changes: 0 additions & 73 deletions src/internal/module/update.go

This file was deleted.

17 changes: 16 additions & 1 deletion src/internal/provider/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package provider

import (
"fmt"
"log/slog"
"slices"

"github.com/opentofu/registry-stable/internal"
Expand Down Expand Up @@ -57,12 +58,26 @@ func (p Provider) buildMetadata() (*Metadata, error) {
// fetch ALL the releases
releases, err := p.getSemverTags()
if err != nil {
return nil, err
p.Logger.Error("Unable to fetch semver tags, skipping", slog.Any("err", err))
return nil, nil
}

// filter the releases to only include those that do not already exist in the metadata
newReleases := meta.filterNewReleases(releases)

if len(newReleases) == 0 {
p.Logger.Info("No version bump required, all versions exist")
return nil, nil
}

shouldUpdate, err := p.shouldUpdateMetadataFile()
if err != nil {
p.Logger.Error("Failed to determine update status, forcing update", slog.Any("err", err))
} else if !shouldUpdate {
p.Logger.Info("No version bump required, latest versions exist")
return nil, nil
}

type versionResult struct {
v *Version
err error
Expand Down
12 changes: 3 additions & 9 deletions src/internal/provider/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,15 @@ import (
func (p Provider) UpdateMetadataFile() error {
p.Logger.Info("Beginning version bump process")

shouldUpdate, err := p.shouldUpdateMetadataFile()
meta, err := p.buildMetadata()
if err != nil {
p.Logger.Error("Failed to determine update status", slog.Any("err", err))
p.Logger.Error("Failed to version bump provider", slog.Any("err", err))
return err
}
if !shouldUpdate {
p.Logger.Info("No version bump required")
if meta == nil {
return nil
}

meta, err := p.buildMetadata()
if err != nil {
p.Logger.Error("Failed to version bump provider", slog.Any("err", err))
return err
}
p.Logger.Info("Completed provider version bump successfully")
return p.WriteMetadata(*meta)
}
Expand Down

0 comments on commit d748f26

Please sign in to comment.