Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix attribution and checksum generation for successful patch application #3060

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions tools/version-tracker/pkg/commands/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,10 @@ func Run(upgradeOptions *types.UpgradeOptions) error {

// If project has patches, attempt to apply them. Track failed patches and files that failed to apply, if any.
if projectHasPatches {
appliedPatchesCount, failedPatch, applyFailedFiles, patchApplySucceeded, err := applyPatchesToRepo(projectRootFilepath, projectRepo, latestRevision)
appliedPatchesCount, failedPatch, applyFailedFiles, err := applyPatchesToRepo(projectRootFilepath, projectRepo, latestRevision, totalPatchCount)
if appliedPatchesCount == totalPatchCount {
patchApplySucceeded = true
}
if err != nil {
return fmt.Errorf("applying patches to repository: %v", err)
}
Expand Down Expand Up @@ -453,7 +456,7 @@ func getLatestEKSDistroRelease(client *gogithub.Client, branch string) (int, str

releaseNumberInt, err := strconv.Atoi(strings.TrimRight(string(releaseNumber), "\n"))
if err != nil {
return 0, "", fmt.Errorf("error converting release number to integer: %v", err)
return 0, "", fmt.Errorf("converting release number to integer: %v", err)
}

kubeVersionTrimmed := strings.TrimRight(string(kubeVersion), "\n")
Expand Down Expand Up @@ -545,8 +548,9 @@ func updateUpstreamProjectsTrackerFile(projectsList *types.ProjectsList, targetR

// applyPatchesToRepo runs a Make command to apply patches to the cloned repository of the project
// being upgraded.
func applyPatchesToRepo(projectRootFilepath, projectRepo, latestVersion string) (string, string, string, bool, error) {
var patchesApplied, failedPatch, failedFilesInPatch string
func applyPatchesToRepo(projectRootFilepath, projectRepo, latestVersion string, totalPatchCount int) (int, string, string, error) {
var patchesApplied int
var failedPatch, failedFilesInPatch string
patchApplySucceeded := true

applyPatchesCommandSequence := fmt.Sprintf("make -C %s patch-repo", projectRootFilepath)
Expand All @@ -556,23 +560,26 @@ func applyPatchesToRepo(projectRootFilepath, projectRepo, latestVersion string)
if strings.Contains(applyPatchesOutput, constants.FailedPatchApplyMarker) {
patchApplySucceeded = false
} else {
return "", "", "", false, fmt.Errorf("running patch-repo Make command: %v", err)
return 0, "", "", fmt.Errorf("running patch-repo Make command: %v", err)
}
}

if !patchApplySucceeded {
if patchApplySucceeded {
patchesApplied = totalPatchCount
} else {
failedFiles := []string{}
gitDescribeRegex := regexp.MustCompile(fmt.Sprintf("%s(-([0-9]+)-g.*)?", latestVersion))
gitDescribeCmd := exec.Command("git", "-C", filepath.Join(projectRootFilepath, projectRepo), "describe", "--tag")
gitDescribeOutput, err := command.ExecCommand(gitDescribeCmd)
if err != nil {
return "", "", "", false, fmt.Errorf("running git describe command: %v", err)
return 0, "", "", fmt.Errorf("running git describe command: %v", err)
}
gitDescribeMatches := gitDescribeRegex.FindStringSubmatch(gitDescribeOutput)
if gitDescribeMatches[1] == "" {
patchesApplied = "0"
} else {
patchesApplied = gitDescribeMatches[2]
if gitDescribeMatches[1] != "" {
patchesApplied, err = strconv.Atoi(gitDescribeMatches[2])
if err != nil {
return 0, "", "", fmt.Errorf("converting patch count to integer %v", err)
}
}

failedPatchRegex := regexp.MustCompile(constants.FailedPatchApplyRegex)
Expand All @@ -587,7 +594,7 @@ func applyPatchesToRepo(projectRootFilepath, projectRepo, latestVersion string)
failedFilesInPatch = strings.Join(failedFiles, ",")
}

return patchesApplied, failedPatch, failedFilesInPatch, patchApplySucceeded, nil
return patchesApplied, failedPatch, failedFilesInPatch, nil
}

// updateChecksumsAttributionFiles runs a Make command to update the checksums and attribution files
Expand Down
2 changes: 1 addition & 1 deletion tools/version-tracker/pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ By submitting this pull request, I confirm that you can use, modify, copy, and r
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.`
PatchesCommentBody = `# This pull request is incomplete!
## Failed patch details
**Only %s/%d patches were applied!**
**Only %d/%d patches were applied!**
%s
The following files in the above patch did not apply successfully:
%s
Expand Down