Skip to content

Commit

Permalink
Make release testdata files mutable only by API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
abhay-krishna committed May 14, 2024
1 parent 7a207a0 commit 0073f6b
Show file tree
Hide file tree
Showing 13 changed files with 726 additions and 713 deletions.
2 changes: 1 addition & 1 deletion release/cli/pkg/assets/tagger/tagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func BuildToolingGitTagAssigner(rc *releasetypes.ReleaseConfig, gitTagPath, over
if overrideBranch != "" {
branchName = overrideBranch
}
gitTag, err := filereader.ReadGitTag(gitTagPath, rc.BuildRepoSource, branchName)
gitTag, err := filereader.ReadGitTag(gitTagPath, rc.BuildRepoSource, branchName, rc.DryRun)
if err != nil {
return "", errors.Cause(err)
}
Expand Down
2 changes: 1 addition & 1 deletion release/cli/pkg/bundles/cilium.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func GetCiliumBundle(r *releasetypes.ReleaseConfig) (anywherev1alpha1.CiliumBund
}

ciliumContainerRegistry := "public.ecr.aws/isovalent"
ciliumGitTag, err := filereader.ReadGitTag(constants.CiliumProjectPath, r.BuildRepoSource, r.BuildRepoBranchName)
ciliumGitTag, err := filereader.ReadGitTag(constants.CiliumProjectPath, r.BuildRepoSource, r.BuildRepoBranchName, r.DryRun)
if err != nil {
return anywherev1alpha1.CiliumBundle{}, errors.Cause(err)
}
Expand Down
2 changes: 1 addition & 1 deletion release/cli/pkg/bundles/eksa.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func GetEksaBundle(r *releasetypes.ReleaseConfig, imageDigests releasetypes.Imag
} else {
componentChecksum = version.GenerateComponentHash(artifactHashes, r.DryRun)
}
version, err := version.BuildComponentVersion(version.NewCliVersioner(r.ReleaseVersion, r.CliRepoSource), componentChecksum)
version, err := version.BuildComponentVersion(version.NewCliVersioner(r), componentChecksum)
if err != nil {
return anywherev1alpha1.EksaBundle{}, errors.Wrapf(err, "failed generating version for eksa bundle")
}
Expand Down
2 changes: 2 additions & 0 deletions release/cli/pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ const (
SuccessIcon = "✅"
FakeComponentChecksum = "abcdef1"
FakeGitCommit = "0123456789abcdef0123456789abcdef01234567"
FakeGitTag = "v1.2.3"
ReleaseFolderName = "release"
MainBranchName = "main"
EksDReleaseComponentsUrl = "https://distro.eks.amazonaws.com/crds/releases.distro.eks.amazonaws.com-v1alpha1.yaml"
YamlSeparator = "\n---\n"

Expand Down
9 changes: 6 additions & 3 deletions release/cli/pkg/filereader/file_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func GetNextEksADevBuildNumber(releaseVersion string, r *releasetypes.ReleaseCon

var latestReleaseKey, latestBuildVersion string
var currentEksaBuildNumber int
if r.BuildRepoBranchName == "main" {
if r.BuildRepoBranchName == constants.MainBranchName {
latestReleaseKey = "LATEST_RELEASE_VERSION"
} else {
latestReleaseKey = fmt.Sprintf("%s/LATEST_RELEASE_VERSION", r.BuildRepoBranchName)
Expand Down Expand Up @@ -263,7 +263,7 @@ func GetCurrentEksADevReleaseVersion(releaseVersion string, r *releasetypes.Rele

func PutEksAReleaseVersion(version string, r *releasetypes.ReleaseConfig) error {
var currentReleaseKey string
if r.BuildRepoBranchName == "main" {
if r.BuildRepoBranchName == constants.MainBranchName {
currentReleaseKey = "LATEST_RELEASE_VERSION"
} else {
currentReleaseKey = fmt.Sprintf("%s/LATEST_RELEASE_VERSION", r.BuildRepoBranchName)
Expand Down Expand Up @@ -336,7 +336,10 @@ func ReadHttpFile(uri string) ([]byte, error) {
return data, nil
}

func ReadGitTag(projectPath, gitRootPath, branch string) (string, error) {
func ReadGitTag(projectPath, gitRootPath, branch string, dryRun bool) (string, error) {
if dryRun {
return constants.FakeGitTag, nil
}
currentBranch, err := git.GetCurrentBranch(gitRootPath)
if err != nil {
return "", fmt.Errorf("error getting current branch: %v", err)
Expand Down
13 changes: 7 additions & 6 deletions release/cli/pkg/images/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/aws/eks-anywhere/release/cli/pkg/aws/ecr"
"github.com/aws/eks-anywhere/release/cli/pkg/aws/ecrpublic"
"github.com/aws/eks-anywhere/release/cli/pkg/aws/s3"
"github.com/aws/eks-anywhere/release/cli/pkg/constants"
"github.com/aws/eks-anywhere/release/cli/pkg/filereader"
"github.com/aws/eks-anywhere/release/cli/pkg/retrier"
releasetypes "github.com/aws/eks-anywhere/release/cli/pkg/types"
Expand Down Expand Up @@ -62,7 +63,7 @@ func PollForExistence(devRelease bool, authConfig *docker.AuthConfiguration, ima
// checks whether the error occured during download is an ImageNotFound error and retries the
// download operation for a maximum of 60 retries, with a wait time of 30 seconds per retry.
retrier := retrier.NewRetrier(60*time.Minute, retrier.WithRetryPolicy(func(totalRetries int, err error) (retry bool, wait time.Duration) {
if branchName == "main" && artifactutils.IsImageNotFoundError(err) && totalRetries < 60 {
if branchName == constants.MainBranchName && artifactutils.IsImageNotFoundError(err) && totalRetries < 60 {
return true, 30 * time.Second
}
return false, 0
Expand Down Expand Up @@ -132,7 +133,7 @@ func GetSourceImageURI(r *releasetypes.ReleaseConfig, name, repoName string, tag
if r.DevRelease || r.ReleaseEnvironment == "development" {
latestTag = artifactutils.GetLatestUploadDestination(r.BuildRepoBranchName)
if imageTagConfiguration.SourceLatestTagFromECR && !r.DryRun {
if (strings.Contains(name, "eks-anywhere-packages") || strings.Contains(name, "ecr-token-refresher")) && r.BuildRepoBranchName != "main" {
if (strings.Contains(name, "eks-anywhere-packages") || strings.Contains(name, "ecr-token-refresher")) && r.BuildRepoBranchName != constants.MainBranchName {
latestTag, _, err = ecr.FilterECRRepoByTagPrefix(r.SourceClients.ECR.EcrClient, repoName, "v0.0.0", false)
} else {
latestTag, err = ecr.GetLatestImageSha(r.SourceClients.ECR.EcrClient, repoName)
Expand Down Expand Up @@ -166,7 +167,7 @@ func GetSourceImageURI(r *releasetypes.ReleaseConfig, name, repoName string, tag
sourceEcrAuthConfig := r.SourceClients.ECR.AuthConfig
err := PollForExistence(r.DevRelease, sourceEcrAuthConfig, sourceImageUri, r.SourceContainerRegistry, r.ReleaseEnvironment, r.BuildRepoBranchName)
if err != nil {
if r.BuildRepoBranchName != "main" {
if r.BuildRepoBranchName != constants.MainBranchName {
fmt.Printf("Tag corresponding to %s branch not found for %s image. Using image artifact from main\n", r.BuildRepoBranchName, repoName)
var gitTagFromMain string
if strings.Contains(name, "bottlerocket-bootstrap") {
Expand All @@ -176,13 +177,13 @@ func GetSourceImageURI(r *releasetypes.ReleaseConfig, name, repoName string, tag
if hasSeparateTagPerReleaseBranch {
gitTagPath = filepath.Join(tagOptions["projectPath"], tagOptions["eksDReleaseChannel"])
}
gitTagFromMain, err = filereader.ReadGitTag(gitTagPath, r.BuildRepoSource, "main")
gitTagFromMain, err = filereader.ReadGitTag(gitTagPath, r.BuildRepoSource, constants.MainBranchName, r.DryRun)
if err != nil {
return "", "", errors.Cause(err)
}
}
sourceImageUri = strings.NewReplacer(r.BuildRepoBranchName, "latest", tagOptions["gitTag"], gitTagFromMain).Replace(sourceImageUri)
sourcedFromBranch = "main"
sourcedFromBranch = constants.MainBranchName
} else {
return "", "", errors.Cause(err)
}
Expand Down Expand Up @@ -337,7 +338,7 @@ func GetPreviousReleaseImageSemver(r *releasetypes.ReleaseConfig, releaseImageUr
if strings.Contains(image.URI, releaseImageUri) {
imageUri := image.URI
var differential int
if r.BuildRepoBranchName == "main" {
if r.BuildRepoBranchName == constants.MainBranchName {
differential = 1
} else {
differential = 2
Expand Down
14 changes: 7 additions & 7 deletions release/cli/pkg/operations/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func DownloadArtifacts(ctx context.Context, r *releasetypes.ReleaseConfig, eksaA
// checks whether the error occured during download is an ObjectNotFound error and retries the
// download operation for a maximum of 60 retries, with a wait time of 30 seconds per retry.
s3Retrier := retrier.NewRetrier(60*time.Minute, retrier.WithRetryPolicy(func(totalRetries int, err error) (retry bool, wait time.Duration) {
if r.BuildRepoBranchName == "main" && artifactutils.IsObjectNotFoundError(err) && totalRetries < 60 {
if r.BuildRepoBranchName == constants.MainBranchName && artifactutils.IsObjectNotFoundError(err) && totalRetries < 60 {
return true, 30 * time.Second
}
return false, 0
Expand Down Expand Up @@ -93,13 +93,13 @@ func handleArchiveDownload(_ context.Context, r *releasetypes.ReleaseConfig, art
return nil
})
if err != nil {
if r.BuildRepoBranchName != "main" {
if r.BuildRepoBranchName != constants.MainBranchName {
var latestSourceS3PrefixFromMain string
fmt.Printf("Artifact corresponding to %s branch not found for %s archive. Using artifact from main\n", r.BuildRepoBranchName, sourceS3Key)
if strings.Contains(sourceS3Key, "eksctl-anywhere") {
latestSourceS3PrefixFromMain = strings.NewReplacer(r.CliRepoBranchName, "latest").Replace(sourceS3Prefix)
} else {
gitTagFromMain, err := filereader.ReadGitTag(artifact.Archive.ProjectPath, r.BuildRepoSource, "main")
gitTagFromMain, err := filereader.ReadGitTag(artifact.Archive.ProjectPath, r.BuildRepoSource, constants.MainBranchName, r.DryRun)
if err != nil {
return errors.Cause(err)
}
Expand Down Expand Up @@ -142,13 +142,13 @@ func handleArchiveDownload(_ context.Context, r *releasetypes.ReleaseConfig, art
return nil
})
if err != nil {
if r.BuildRepoBranchName != "main" {
if r.BuildRepoBranchName != constants.MainBranchName {
var latestSourceS3PrefixFromMain string
fmt.Printf("Artifact corresponding to %s branch not found for %s archive. Using artifact from main\n", r.BuildRepoBranchName, sourceS3Key)
if strings.Contains(sourceS3Key, "eksctl-anywhere") {
latestSourceS3PrefixFromMain = strings.NewReplacer(r.CliRepoBranchName, "latest").Replace(sourceS3Prefix)
} else {
gitTagFromMain, err := filereader.ReadGitTag(artifact.Archive.ProjectPath, r.BuildRepoSource, "main")
gitTagFromMain, err := filereader.ReadGitTag(artifact.Archive.ProjectPath, r.BuildRepoSource, constants.MainBranchName, r.DryRun)
if err != nil {
return errors.Cause(err)
}
Expand Down Expand Up @@ -185,9 +185,9 @@ func handleManifestDownload(_ context.Context, r *releasetypes.ReleaseConfig, ar
return nil
})
if err != nil {
if r.BuildRepoBranchName != "main" {
if r.BuildRepoBranchName != constants.MainBranchName {
fmt.Printf("Artifact corresponding to %s branch not found for %s manifest. Using artifact from main\n", r.BuildRepoBranchName, sourceS3Key)
gitTagFromMain, err := filereader.ReadGitTag(artifact.Manifest.ProjectPath, r.BuildRepoSource, "main")
gitTagFromMain, err := filereader.ReadGitTag(artifact.Manifest.ProjectPath, r.BuildRepoSource, constants.MainBranchName, r.DryRun)
if err != nil {
return errors.Cause(err)
}
Expand Down
4 changes: 2 additions & 2 deletions release/cli/pkg/operations/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func SetRepoHeads(r *releasetypes.ReleaseConfig) error {
return errors.Cause(err)
}

if r.BuildRepoBranchName != "main" {
if r.BuildRepoBranchName != constants.MainBranchName {
fmt.Printf("Checking out build-tooling repo at branch %s\n", r.BuildRepoBranchName)
out, err = git.CheckoutRepo(r.BuildRepoSource, r.BuildRepoBranchName)
fmt.Println(out)
Expand All @@ -68,7 +68,7 @@ func SetRepoHeads(r *releasetypes.ReleaseConfig) error {
}
}

if r.CliRepoBranchName != "main" {
if r.CliRepoBranchName != constants.MainBranchName {
fmt.Printf("Checking out CLI repo at branch %s\n", r.CliRepoBranchName)
out, err = git.CheckoutRepo(r.CliRepoSource, r.CliRepoBranchName)
fmt.Println(out)
Expand Down
Loading

0 comments on commit 0073f6b

Please sign in to comment.