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 checksums and attribution generation during upgrade #3009

Merged
merged 1 commit into from
Mar 13, 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
50 changes: 27 additions & 23 deletions tools/version-tracker/pkg/commands/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion tools/version-tracker/pkg/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down