Skip to content

Commit

Permalink
Fix datadog by applying ProviderOrgs to getting the next SHA (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
iwahbe authored Aug 29, 2023
1 parent c20bb05 commit 2149a46
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
26 changes: 17 additions & 9 deletions upgrade/steps-helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,9 @@ func gitRefsOf(ctx context.Context, url, kind string) (gitRepoRefs, error) {
return gitRepoRefs{refsToBranches, kind}, nil
}

type gitRepoRefs struct{
type gitRepoRefs struct {
refsToLabel map[string]string
kind string
kind string
}

func (g gitRepoRefs) shaOf(label string) (string, bool) {
Expand Down Expand Up @@ -384,6 +384,18 @@ func latestRelease(ctx context.Context, repo string) (*semver.Version, error) {
return semver.NewVersion(result.Latest.TagName)
}

func getGitHubPath(repoPath string) (string, error) {
if prefix, repo, found := strings.Cut(repoPath, "/terraform-providers/"); found {
name := strings.TrimPrefix(repo, "terraform-provider-")
org, ok := ProviderOrgs[name]
if !ok {
return "", fmt.Errorf("terraform-providers based path: missing remap for '%s'", name)
}
repoPath = prefix + "/" + org + "/" + repo
}
return repoPath, nil
}

// getRepoExpectedLocation will return one of the following:
// 1) --repo-path: if set, returns the specified repo path
// 2) current working directory: returns the path to the cwd if it is a provider directory
Expand All @@ -400,13 +412,9 @@ func getRepoExpectedLocation(ctx Context, cwd, repoPath string) (string, error)
repoPath = repoPath[:match[0]]
}

if prefix, repo, found := strings.Cut(repoPath, "/terraform-providers/"); found {
name := strings.TrimPrefix(repo, "terraform-provider-")
org, ok := ProviderOrgs[name]
if !ok {
return "", fmt.Errorf("terraform-providers based path: missing remap for '%s'", name)
}
repoPath = prefix + "/" + org + "/" + repo
repoPath, err := getGitHubPath(repoPath)
if err != nil {
return "", fmt.Errorf("repo location: %w", err)
}

// from github.com/org/repo to $GOPATH/src/github.com/org
Expand Down
7 changes: 5 additions & 2 deletions upgrade/steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,11 @@ func UpgradeProviderVersion(
// It they are versioning correctly, `go mod tidy` will resolve the SHA to a tag.
steps = append(steps,
step.F("Lookup Tag SHA", func() (string, error) {
refs, err := gitRefsOf(ctx, "https://"+modPathWithoutVersion(goMod.Upstream.Path),
path, err := getGitHubPath(goMod.Upstream.Path)
if err != nil {
return "", err
}
refs, err := gitRefsOf(ctx, "https://"+modPathWithoutVersion(path),
"tags")
if err != nil {
return "", err
Expand Down Expand Up @@ -559,7 +563,6 @@ func MajorVersionBump(ctx Context, goMod *GoMod, target *UpstreamUpgradeTarget,
return UpdateFile(desc+" in "+path, path, func(src []byte) ([]byte, error) {
old := strings.ReplaceAll(s, "{}", prev)
new := strings.ReplaceAll(s, "{}", "provider/"+nextMajorVersion)

return bytes.ReplaceAll(src, []byte(old), []byte(new)), nil
})
}
Expand Down

0 comments on commit 2149a46

Please sign in to comment.