fix tmpfs mode, replace stream mode with branch suffix and strict mode

This commit is contained in:
Mustafa Gezen 2022-04-21 06:30:33 +02:00
parent 8f55eb397f
commit 61eaa8b8f8
6 changed files with 31 additions and 25 deletions

View File

@ -50,7 +50,8 @@ var (
noStorageUpload bool
manualCommits string
moduleFallbackStream string
allowStreamBranches bool
branchSuffix string
strictBranchMode bool
basicUsername string
basicPassword string
)
@ -78,7 +79,8 @@ func mn(_ *cobra.Command, _ []string) {
ImportBranchPrefix: importBranchPrefix,
BranchPrefix: branchPrefix,
NoDupMode: noDupMode,
AllowStreamBranches: allowStreamBranches,
BranchSuffix: branchSuffix,
StrictBranchMode: strictBranchMode,
ModuleFallbackStream: moduleFallbackStream,
NoStorageUpload: noStorageUpload,
NoStorageDownload: noStorageDownload,
@ -130,7 +132,8 @@ func main() {
root.Flags().BoolVar(&noStorageUpload, "no-storage-upload", false, "If enabled, blobs are not uploaded to blob storage")
root.Flags().StringVar(&manualCommits, "manual-commits", "", "Comma separated branch and commit list for packages with broken release tags (Format: BRANCH:HASH)")
root.Flags().StringVar(&moduleFallbackStream, "module-fallback-stream", "", "Override fallback stream. Some module packages are published as collections and mostly use the same stream name, some of them deviate from the main stream")
root.Flags().BoolVar(&allowStreamBranches, "allow-stream-branches", false, "Allow import from stream branches")
root.Flags().StringVar(&branchSuffix, "branch-suffix", "", "Branch suffix to use for imported branches")
root.Flags().BoolVar(&strictBranchMode, "strict-branch-mode", false, "If enabled, only branches with the calculated name are imported and not prefix only")
root.Flags().StringVar(&basicUsername, "basic-username", "", "Basic auth username")
root.Flags().StringVar(&basicPassword, "basic-password", "", "Basic auth password")

View File

@ -50,7 +50,8 @@ type ProcessData struct {
NoStorageUpload bool
ManualCommits []string
ModuleFallbackStream string
AllowStreamBranches bool
BranchSuffix string
StrictBranchMode bool
FsCreator FsCreatorFunc
CdnUrl string
Log *log.Logger

View File

@ -2,13 +2,16 @@ package misc
import (
"fmt"
"github.com/rocky-linux/srpmproc/pkg/data"
"regexp"
)
func GetTagImportRegex(importBranchPrefix string, allowStreamBranches bool) *regexp.Regexp {
if allowStreamBranches {
return regexp.MustCompile(fmt.Sprintf("refs/tags/(imports/(%s(?:.s|.)|%s(?:|s).+)/(.*))", importBranchPrefix, importBranchPrefix))
} else {
return regexp.MustCompile(fmt.Sprintf("refs/tags/(imports/(%s.|%s.-.+)/(.*))", importBranchPrefix, importBranchPrefix))
func GetTagImportRegex(pd *data.ProcessData) *regexp.Regexp {
branchRegex := fmt.Sprintf("%s%d%s", pd.ImportBranchPrefix, pd.Version, pd.BranchSuffix)
if pd.StrictBranchMode {
branchRegex += ".+"
}
regex := fmt.Sprintf("refs/tags/(imports/(%s)/(.*))", branchRegex)
return regexp.MustCompile(regex)
}

View File

@ -109,8 +109,8 @@ func (g *GitMode) RetrieveSource(pd *data.ProcessData) (*data.ModeData, error) {
tagAdd := func(tag *object.Tag) error {
if strings.HasPrefix(tag.Name, fmt.Sprintf("imports/%s%d", pd.ImportBranchPrefix, pd.Version)) {
refSpec := fmt.Sprintf("refs/tags/%s", tag.Name)
if misc.GetTagImportRegex(pd.ImportBranchPrefix, pd.AllowStreamBranches).MatchString(refSpec) {
match := misc.GetTagImportRegex(pd.ImportBranchPrefix, pd.AllowStreamBranches).FindStringSubmatch(refSpec)
if misc.GetTagImportRegex(pd).MatchString(refSpec) {
match := misc.GetTagImportRegex(pd).FindStringSubmatch(refSpec)
exists := latestTags[match[2]]
if exists != nil && exists.when.After(tag.Tagger.When) {
@ -197,7 +197,7 @@ func (g *GitMode) WriteSource(pd *data.ProcessData, md *data.ModeData) error {
refspec = config.RefSpec(fmt.Sprintf("+%s:%s", md.TagBranch, md.TagBranch))
branchName = strings.TrimPrefix(md.TagBranch, "refs/heads/")
} else {
match := misc.GetTagImportRegex(pd.ImportBranchPrefix, pd.AllowStreamBranches).FindStringSubmatch(md.TagBranch)
match := misc.GetTagImportRegex(pd).FindStringSubmatch(md.TagBranch)
branchName = match[2]
refspec = config.RefSpec(fmt.Sprintf("+refs/heads/%s:%s", branchName, md.TagBranch))
}
@ -362,8 +362,8 @@ func (g *GitMode) PostProcess(md *data.ModeData) error {
}
func (g *GitMode) ImportName(pd *data.ProcessData, md *data.ModeData) string {
if misc.GetTagImportRegex(pd.ImportBranchPrefix, pd.AllowStreamBranches).MatchString(md.TagBranch) {
match := misc.GetTagImportRegex(pd.ImportBranchPrefix, pd.AllowStreamBranches).FindStringSubmatch(md.TagBranch)
if misc.GetTagImportRegex(pd).MatchString(md.TagBranch) {
match := misc.GetTagImportRegex(pd).FindStringSubmatch(md.TagBranch)
return match[3]
}

View File

@ -296,7 +296,7 @@ func patchModuleYaml(pd *data.ProcessData, md *data.ModeData) error {
}
// Get stream branch from tag
match := misc.GetTagImportRegex(pd.ImportBranchPrefix, pd.AllowStreamBranches).FindStringSubmatch(md.TagBranch)
match := misc.GetTagImportRegex(pd).FindStringSubmatch(md.TagBranch)
streamBranch := strings.Split(match[2], "-")
// Force stream to be the same as stream name in branch
module.Data.Stream = streamBranch[len(streamBranch)-1]

View File

@ -24,6 +24,7 @@ import (
"encoding/hex"
"fmt"
"github.com/go-git/go-billy/v5"
"github.com/go-git/go-billy/v5/osfs"
"github.com/go-git/go-git/v5/plumbing/transport"
"github.com/go-git/go-git/v5/plumbing/transport/http"
"github.com/go-git/go-git/v5/plumbing/transport/ssh"
@ -84,7 +85,8 @@ type ProcessDataRequest struct {
BranchPrefix string
FsCreator data.FsCreatorFunc
NoDupMode bool
AllowStreamBranches bool
BranchSuffix string
StrictBranchMode bool
ModuleFallbackStream string
NoStorageUpload bool
NoStorageDownload bool
@ -187,7 +189,7 @@ func NewProcessData(req *ProcessDataRequest) (*data.ProcessData, error) {
}
fsCreator := func(branch string) (billy.Filesystem, error) {
return memfs.New(), nil
return osfs.New("."), nil
}
reqFsCreator := fsCreator
if req.FsCreator != nil {
@ -248,7 +250,8 @@ func NewProcessData(req *ProcessDataRequest) (*data.ProcessData, error) {
NoStorageUpload: req.NoStorageUpload,
ManualCommits: manualCs,
ModuleFallbackStream: req.ModuleFallbackStream,
AllowStreamBranches: req.AllowStreamBranches,
BranchSuffix: req.BranchSuffix,
StrictBranchMode: req.StrictBranchMode,
FsCreator: fsCreator,
CdnUrl: req.CdnUrl,
Log: logger,
@ -343,12 +346,8 @@ func ProcessRPM(pd *data.ProcessData) (*srpmprocpb.ProcessResponse, error) {
source.Expired = true
}
if strings.Contains(md.TagBranch, "-beta") {
continue
}
var matchString string
if !misc.GetTagImportRegex(pd.ImportBranchPrefix, pd.AllowStreamBranches).MatchString(md.TagBranch) {
if !misc.GetTagImportRegex(pd).MatchString(md.TagBranch) {
if pd.ModuleMode {
prefix := fmt.Sprintf("refs/heads/%s%d", pd.ImportBranchPrefix, pd.Version)
if strings.HasPrefix(md.TagBranch, prefix) {
@ -357,14 +356,14 @@ func ProcessRPM(pd *data.ProcessData) (*srpmprocpb.ProcessResponse, error) {
pd.Log.Printf("using match string: %s", matchString)
}
}
if !misc.GetTagImportRegex(pd.ImportBranchPrefix, pd.AllowStreamBranches).MatchString(matchString) {
if !misc.GetTagImportRegex(pd).MatchString(matchString) {
continue
}
} else {
matchString = md.TagBranch
}
match := misc.GetTagImportRegex(pd.ImportBranchPrefix, pd.AllowStreamBranches).FindStringSubmatch(matchString)
match := misc.GetTagImportRegex(pd).FindStringSubmatch(matchString)
md.PushBranch = pd.BranchPrefix + strings.TrimPrefix(match[2], pd.ImportBranchPrefix)
newTag := "imports/" + pd.BranchPrefix + strings.TrimPrefix(match[1], "imports/"+pd.ImportBranchPrefix)
newTag = strings.Replace(newTag, "%", "_", -1)