diff --git a/tools/version-tracker/pkg/commands/display/display.go b/tools/version-tracker/pkg/commands/display/display.go index 9f27ce04a4..0b2468eae7 100644 --- a/tools/version-tracker/pkg/commands/display/display.go +++ b/tools/version-tracker/pkg/commands/display/display.go @@ -13,6 +13,7 @@ import ( "gopkg.in/yaml.v3" "github.com/aws/eks-anywhere-build-tooling/tools/version-tracker/pkg/constants" + "github.com/aws/eks-anywhere-build-tooling/tools/version-tracker/pkg/ecrpublic" "github.com/aws/eks-anywhere-build-tooling/tools/version-tracker/pkg/git" "github.com/aws/eks-anywhere-build-tooling/tools/version-tracker/pkg/github" "github.com/aws/eks-anywhere-build-tooling/tools/version-tracker/pkg/types" @@ -20,6 +21,8 @@ import ( // Run contains the business logic to execute the `display` subcommand. func Run(displayOptions *types.DisplayOptions) error { + projectName := displayOptions.ProjectName + // Check if branch name environment variable has been set. branchName, ok := os.LookupEnv(constants.BranchNameEnvVar) if !ok { @@ -126,10 +129,18 @@ func Run(displayOptions *types.DisplayOptions) error { isTrackedByCommitHash = true } - // Get latest revision for the project from GitHub. - latestRevision, _, err := github.GetLatestRevision(client, org, repoName, currentRevision, branchName, isTrackedByCommitHash, releaseBranched) - if err != nil { - return fmt.Errorf("getting latest revision from GitHub: %v", err) + var latestRevision string + if projectName == "cilium/cilium" { + latestRevision, _, err = ecrpublic.GetLatestRevision(constants.CiliumImageRepository, currentRevision, branchName) + if err != nil { + return fmt.Errorf("getting latest revision from ECR Public: %v", err) + } + } else { + // Get latest revision for the project from GitHub. + latestRevision, _, err = github.GetLatestRevision(client, org, repoName, currentRevision, branchName, isTrackedByCommitHash, releaseBranched) + if err != nil { + return fmt.Errorf("getting latest revision from GitHub: %v", err) + } } // Check if we should print only the latest version of the project. diff --git a/tools/version-tracker/pkg/commands/upgrade/upgrade.go b/tools/version-tracker/pkg/commands/upgrade/upgrade.go index 529f4883ca..320ec33929 100644 --- a/tools/version-tracker/pkg/commands/upgrade/upgrade.go +++ b/tools/version-tracker/pkg/commands/upgrade/upgrade.go @@ -218,7 +218,7 @@ func Run(upgradeOptions *types.UpgradeOptions) error { var latestRevision string var needsUpgrade bool if projectName == "cilium/cilium" { - latestRevision, needsUpgrade, err = ecrpublic.GetLatestRevision(constants.CiliumImageRepository, currentRevision) + latestRevision, needsUpgrade, err = ecrpublic.GetLatestRevision(constants.CiliumImageRepository, currentRevision, branchName) if err != nil { return fmt.Errorf("getting latest revision from ECR Public: %v", err) } diff --git a/tools/version-tracker/pkg/ecrpublic/ecrpublic.go b/tools/version-tracker/pkg/ecrpublic/ecrpublic.go index 8ebb54e444..a15ed00688 100644 --- a/tools/version-tracker/pkg/ecrpublic/ecrpublic.go +++ b/tools/version-tracker/pkg/ecrpublic/ecrpublic.go @@ -4,14 +4,16 @@ import ( "encoding/json" "fmt" "os/exec" + "regexp" "strings" "github.com/aws/eks-anywhere/pkg/semver" + "github.com/aws/eks-anywhere-build-tooling/tools/version-tracker/pkg/constants" "github.com/aws/eks-anywhere-build-tooling/tools/version-tracker/pkg/util/command" ) -func GetLatestRevision(imageRepository, currentRevision string) (string, bool, error) { +func GetLatestRevision(imageRepository, currentRevision, branchName string) (string, bool, error) { var latestRevision string currentRevisionSemver, err := semver.New(currentRevision) if err != nil { @@ -21,7 +23,7 @@ func GetLatestRevision(imageRepository, currentRevision string) (string, bool, e skopeoListTagsCmd := exec.Command("skopeo", "list-tags", fmt.Sprintf("docker://%s", imageRepository)) listTagsOutput, err := command.ExecCommand(skopeoListTagsCmd) if err != nil { - return "", false, fmt.Errorf("running Go version command: %v", err) + return "", false, fmt.Errorf("running Skopeo list-tags command: %v", err) } var tagsList interface{} @@ -44,6 +46,13 @@ func GetLatestRevision(imageRepository, currentRevision string) (string, bool, e return "", false, fmt.Errorf("getting semver for Cilium tag [%s]: %v", tag, err) } + if branchName != constants.MainBranchName { + tagRegex := regexp.MustCompile(fmt.Sprintf(`^v%d.%d.\d+`, currentRevisionSemver.Major, currentRevisionSemver.Minor)) + if !tagRegex.MatchString(tag) { + continue + } + } + if tagSemver.GreaterThan(latestRevisionSemver) { latestRevisionSemver = tagSemver latestRevision = tag