Skip to content

Commit

Permalink
Fix attribution and checksum generation for successful patch applicat…
Browse files Browse the repository at this point in the history
…ion (#3060)
  • Loading branch information
abhay-krishna authored Apr 5, 2024
1 parent 0fe2dc4 commit a2bfc53
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
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

0 comments on commit a2bfc53

Please sign in to comment.