From 1145eda74de09a59d1bb1175e01e715d290ed2a8 Mon Sep 17 00:00:00 2001 From: Abhay Krishna Arunachalam Date: Wed, 13 Mar 2024 16:01:41 -0700 Subject: [PATCH] Fix checksums and attribution generation during upgrade --- .../pkg/commands/upgrade/upgrade.go | 50 ++++++++++--------- tools/version-tracker/pkg/github/github.go | 2 +- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/tools/version-tracker/pkg/commands/upgrade/upgrade.go b/tools/version-tracker/pkg/commands/upgrade/upgrade.go index bcc1be7b40..9a45099b0c 100644 --- a/tools/version-tracker/pkg/commands/upgrade/upgrade.go +++ b/tools/version-tracker/pkg/commands/upgrade/upgrade.go @@ -266,38 +266,42 @@ func Run(upgradeOptions *types.UpgradeOptions) error { } updatedFiles = append(updatedFiles, projectReadmePath) - // Update the checksums file and attribution file(s) corresponding to the project. + // 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) if err != nil { return fmt.Errorf("applying patches to repository: %v", err) } - if patchApplySucceeded { - if _, err := os.Stat(filepath.Join(projectRootFilepath, constants.ChecksumsFile)); err == nil { - logger.Info("Updating project checksums and attribution files") - projectChecksumsFileRelativePath := filepath.Join(projectPath, constants.ChecksumsFile) - err = updateChecksumsAttributionFiles(projectRootFilepath) - if err != nil { - return fmt.Errorf("updating project checksums and attribution files: %v", err) - } - updatedFiles = append(updatedFiles, projectChecksumsFileRelativePath) + if !patchApplySucceeded { + patchesWarningComment = fmt.Sprintf(constants.PatchesCommentBody, appliedPatchesCount, totalPatchCount, failedPatch, applyFailedFiles) + } + } - // Attribution files can have a binary name prefix so we use a common prefix regular expression - // and glob them to cover all possibilities. - projectAttributionFileGlob, err := filepath.Glob(filepath.Join(projectRootFilepath, constants.AttributionsFilePattern)) + // If project doesn't have patches, or it does and they were applied successfully, then update the checksums file + // and attribution file(s) corresponding to the project. + if !projectHasPatches || patchApplySucceeded { + if _, err := os.Stat(filepath.Join(projectRootFilepath, constants.ChecksumsFile)); err == nil { + logger.Info("Updating project checksums and attribution files") + projectChecksumsFileRelativePath := filepath.Join(projectPath, constants.ChecksumsFile) + err = updateChecksumsAttributionFiles(projectRootFilepath) + if err != nil { + return fmt.Errorf("updating project checksums and attribution files: %v", err) + } + updatedFiles = append(updatedFiles, projectChecksumsFileRelativePath) + + // Attribution files can have a binary name prefix so we use a common prefix regular expression + // and glob them to cover all possibilities. + projectAttributionFileGlob, err := filepath.Glob(filepath.Join(projectRootFilepath, constants.AttributionsFilePattern)) + if err != nil { + return fmt.Errorf("finding filenames matching attribution file pattern [%s]: %v", constants.AttributionsFilePattern, err) + } + for _, attributionFile := range projectAttributionFileGlob { + attributionFileRelativePath, err := filepath.Rel(buildToolingRepoPath, attributionFile) if err != nil { - return fmt.Errorf("finding filenames matching attribution file pattern [%s]: %v", constants.AttributionsFilePattern, err) - } - for _, attributionFile := range projectAttributionFileGlob { - attributionFileRelativePath, err := filepath.Rel(buildToolingRepoPath, attributionFile) - if err != nil { - return fmt.Errorf("getting relative path for attribution file: %v", err) - } - updatedFiles = append(updatedFiles, attributionFileRelativePath) + return fmt.Errorf("getting relative path for attribution file: %v", err) } + updatedFiles = append(updatedFiles, attributionFileRelativePath) } - } else { - patchesWarningComment = fmt.Sprintf(constants.PatchesCommentBody, appliedPatchesCount, totalPatchCount, failedPatch, applyFailedFiles) } } diff --git a/tools/version-tracker/pkg/github/github.go b/tools/version-tracker/pkg/github/github.go index 4ad2d1b9b6..32d5ac268c 100644 --- a/tools/version-tracker/pkg/github/github.go +++ b/tools/version-tracker/pkg/github/github.go @@ -348,7 +348,7 @@ func CreatePullRequest(client *github.Client, org, repo, title, body, baseRepoOw // Check if there is already a pull request from the head branch to the base branch. pullRequests, _, err := client.PullRequests.List(context.Background(), baseRepoOwner, constants.BuildToolingRepoName, &github.PullRequestListOptions{ - Base: fmt.Sprintf("%s:%s", baseRepoOwner, baseBranch), + Base: baseBranch, Head: fmt.Sprintf("%s:%s", headRepoOwner, headBranch), }) if err != nil {