mirror of
https://github.com/rocky-linux/srpmproc.git
synced 2024-12-04 18:36:26 +00:00
Repaired manual commits feature and added some bugfixes:
- Manual commits work properly again, and are passed to "tagless mode" for version discovery + tagging - Fixed tagless mode issue with rpmspec warnings, only stdout is considered - Fixed tagless mode issue where renamed folders were not properly overwritten, causing potential bad commits -Skip G.
This commit is contained in:
parent
4f975913b4
commit
44725a727d
@ -38,8 +38,8 @@ func GetTagImportRegex(pd *data.ProcessData) *regexp.Regexp {
|
|||||||
// if we are ok with importing that reference. We are looking for the traditional <prefix><version><suffix> pattern, like "c9s", and also the
|
// if we are ok with importing that reference. We are looking for the traditional <prefix><version><suffix> pattern, like "c9s", and also the
|
||||||
// modular "stream-<NAME>-<VERSION>-rhel-<VERSION> branch pattern as well
|
// modular "stream-<NAME>-<VERSION>-rhel-<VERSION> branch pattern as well
|
||||||
func TaglessRefOk(tag string, pd *data.ProcessData) bool {
|
func TaglessRefOk(tag string, pd *data.ProcessData) bool {
|
||||||
// First case is very easy: if we are "refs/heads/<prefix><version><suffix>" , then this is def. a branch we should import
|
// First case is very easy: if we are exactly "refs/heads/<prefix><version><suffix>" , then this is def. a branch we should import
|
||||||
if strings.HasPrefix(tag, fmt.Sprintf("refs/heads/%s%d%s", pd.ImportBranchPrefix, pd.Version, pd.BranchSuffix)) {
|
if tag == fmt.Sprintf("refs/heads/%s%d%s", pd.ImportBranchPrefix, pd.Version, pd.BranchSuffix) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -413,17 +413,9 @@ func ProcessRPM(pd *data.ProcessData) (*srpmprocpb.ProcessResponse, error) {
|
|||||||
if pd.SingleTag != "" {
|
if pd.SingleTag != "" {
|
||||||
md.Branches = []string{fmt.Sprintf("refs/tags/%s", pd.SingleTag)}
|
md.Branches = []string{fmt.Sprintf("refs/tags/%s", pd.SingleTag)}
|
||||||
} else if len(pd.ManualCommits) > 0 {
|
} else if len(pd.ManualCommits) > 0 {
|
||||||
md.Branches = []string{}
|
log.Println("Manual commits were listed for import. Switching to perform a tagless import of these commit(s).")
|
||||||
for _, commit := range pd.ManualCommits {
|
pd.TaglessMode = true
|
||||||
branchCommit := strings.Split(commit, ":")
|
return processRPMTagless(pd)
|
||||||
if len(branchCommit) != 2 {
|
|
||||||
return nil, fmt.Errorf("invalid manual commit list")
|
|
||||||
}
|
|
||||||
|
|
||||||
head := fmt.Sprintf("refs/tags/imports/%s/%s-%s", branchCommit[0], md.Name, branchCommit[1])
|
|
||||||
md.Branches = append(md.Branches, head)
|
|
||||||
commitPin[head] = branchCommit[1]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we have no valid branches to consider, then we'll automatically switch to attempt a tagless import:
|
// If we have no valid branches to consider, then we'll automatically switch to attempt a tagless import:
|
||||||
@ -813,6 +805,20 @@ func processRPMTagless(pd *data.ProcessData) (*srpmprocpb.ProcessResponse, error
|
|||||||
sourceWorktree := *md.Worktree
|
sourceWorktree := *md.Worktree
|
||||||
localPath := ""
|
localPath := ""
|
||||||
|
|
||||||
|
// if a manual commit list is provided, we want to create our md.Branches[] array in a special format:
|
||||||
|
if len(pd.ManualCommits) > 0 {
|
||||||
|
md.Branches = []string{}
|
||||||
|
for _, commit := range pd.ManualCommits {
|
||||||
|
branchCommit := strings.Split(commit, ":")
|
||||||
|
if len(branchCommit) != 2 {
|
||||||
|
return nil, fmt.Errorf("invalid manual commit list")
|
||||||
|
}
|
||||||
|
|
||||||
|
head := fmt.Sprintf("COMMIT:%s:%s", branchCommit[0], branchCommit[1])
|
||||||
|
md.Branches = append(md.Branches, head)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, branch := range md.Branches {
|
for _, branch := range md.Branches {
|
||||||
md.Repo = &sourceRepo
|
md.Repo = &sourceRepo
|
||||||
md.Worktree = &sourceWorktree
|
md.Worktree = &sourceWorktree
|
||||||
@ -832,13 +838,35 @@ func processRPMTagless(pd *data.ProcessData) (*srpmprocpb.ProcessResponse, error
|
|||||||
return nil, fmt.Errorf("Could not create temporary directory: %s", localPath)
|
return nil, fmt.Errorf("Could not create temporary directory: %s", localPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// we'll make our branch we're processing more presentable if it's in the COMMIT:<branch>:<hash> format:
|
||||||
|
if strings.HasPrefix(branch, "COMMIT:") {
|
||||||
|
branch = fmt.Sprintf("refs/heads/%s", strings.Split(branch, ":")[1])
|
||||||
|
}
|
||||||
|
|
||||||
// Clone repo into the temporary path, but only the tag we're interested in:
|
// Clone repo into the temporary path, but only the tag we're interested in:
|
||||||
// (TODO: will probably need to assign this a variable or use the md struct gitrepo object to perform a successful tag+push later)
|
// (TODO: will probably need to assign this a variable or use the md struct gitrepo object to perform a successful tag+push later)
|
||||||
_, _ = git.PlainClone(localPath, false, &git.CloneOptions{
|
rTmp, err := git.PlainClone(localPath, false, &git.CloneOptions{
|
||||||
URL: pd.RpmLocation,
|
URL: pd.RpmLocation,
|
||||||
SingleBranch: true,
|
SingleBranch: true,
|
||||||
ReferenceName: plumbing.ReferenceName(branch),
|
ReferenceName: plumbing.ReferenceName(branch),
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we're dealing with a special manual commit to import ("COMMIT:<branch>:<githash>"), then we need to check out that
|
||||||
|
// specific hash from the repo we are importing from:
|
||||||
|
if strings.HasPrefix(md.TagBranch, "COMMIT:") {
|
||||||
|
commitList := strings.Split(md.TagBranch, ":")
|
||||||
|
|
||||||
|
wTmp, _ := rTmp.Worktree()
|
||||||
|
err = wTmp.Checkout(&git.CheckoutOptions{
|
||||||
|
Hash: plumbing.NewHash(commitList[2]),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("Could not find manual commit %s in the repository. Must be a valid commit hash.", commitList[2])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Now that we're cloned into localPath, we need to "covert" the import into the old format
|
// Now that we're cloned into localPath, we need to "covert" the import into the old format
|
||||||
// We want sources to become .PKGNAME.metadata, we want SOURCES and SPECS folders, etc.
|
// We want sources to become .PKGNAME.metadata, we want SOURCES and SPECS folders, etc.
|
||||||
@ -919,6 +947,12 @@ func processRPMTagless(pd *data.ProcessData) (*srpmprocpb.ProcessResponse, error
|
|||||||
Force: true,
|
Force: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// These os commands actually move the data from our cloned import repo to our cloned "push" repo (upstream -> downstream)
|
||||||
|
// First we clobber the target push repo's data, and then move the new data into it from the upstream repo we cloned earlier
|
||||||
|
os.RemoveAll(fmt.Sprintf("%s_gitpush/SPECS", localPath))
|
||||||
|
os.RemoveAll(fmt.Sprintf("%s_gitpush/SOURCES", localPath))
|
||||||
|
os.RemoveAll(fmt.Sprintf("%s_gitpush/.gitignore", localPath))
|
||||||
|
os.RemoveAll(fmt.Sprintf("%s_gitpush/%s.metadata", localPath, md.Name))
|
||||||
os.Rename(fmt.Sprintf("%s/SPECS", localPath), fmt.Sprintf("%s_gitpush/SPECS", localPath))
|
os.Rename(fmt.Sprintf("%s/SPECS", localPath), fmt.Sprintf("%s_gitpush/SPECS", localPath))
|
||||||
os.Rename(fmt.Sprintf("%s/SOURCES", localPath), fmt.Sprintf("%s_gitpush/SOURCES", localPath))
|
os.Rename(fmt.Sprintf("%s/SOURCES", localPath), fmt.Sprintf("%s_gitpush/SOURCES", localPath))
|
||||||
os.Rename(fmt.Sprintf("%s/.gitignore", localPath), fmt.Sprintf("%s_gitpush/.gitignore", localPath))
|
os.Rename(fmt.Sprintf("%s/.gitignore", localPath), fmt.Sprintf("%s_gitpush/.gitignore", localPath))
|
||||||
@ -1052,7 +1086,6 @@ func processRPMTagless(pd *data.ProcessData) (*srpmprocpb.ProcessResponse, error
|
|||||||
Version: pd.PackageVersion,
|
Version: pd.PackageVersion,
|
||||||
Release: pd.PackageRelease,
|
Release: pd.PackageRelease,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// return struct with all our branch:commit and branch:version+release mappings
|
// return struct with all our branch:commit and branch:version+release mappings
|
||||||
@ -1205,7 +1238,7 @@ func getVersionFromSpec(localRepo string, majorVersion int) (string, error) {
|
|||||||
fmt.Sprintf("%s/SPECS/%s", localRepo, specFile),
|
fmt.Sprintf("%s/SPECS/%s", localRepo, specFile),
|
||||||
}
|
}
|
||||||
cmd := exec.Command("rpmspec", cmdArgs...)
|
cmd := exec.Command("rpmspec", cmdArgs...)
|
||||||
nvrTmp, err := cmd.CombinedOutput()
|
nvrTmp, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("Error running rpmspec command to determine RPM name-version-release identifier. \nCommand attempted: %s \nCommand output: %s", cmd.String(), string(nvrTmp))
|
return "", fmt.Errorf("Error running rpmspec command to determine RPM name-version-release identifier. \nCommand attempted: %s \nCommand output: %s", cmd.String(), string(nvrTmp))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user