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 noStorageUpload bool
manualCommits string manualCommits string
moduleFallbackStream string moduleFallbackStream string
allowStreamBranches bool branchSuffix string
strictBranchMode bool
basicUsername string basicUsername string
basicPassword string basicPassword string
) )
@ -78,7 +79,8 @@ func mn(_ *cobra.Command, _ []string) {
ImportBranchPrefix: importBranchPrefix, ImportBranchPrefix: importBranchPrefix,
BranchPrefix: branchPrefix, BranchPrefix: branchPrefix,
NoDupMode: noDupMode, NoDupMode: noDupMode,
AllowStreamBranches: allowStreamBranches, BranchSuffix: branchSuffix,
StrictBranchMode: strictBranchMode,
ModuleFallbackStream: moduleFallbackStream, ModuleFallbackStream: moduleFallbackStream,
NoStorageUpload: noStorageUpload, NoStorageUpload: noStorageUpload,
NoStorageDownload: noStorageDownload, 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().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(&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().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(&basicUsername, "basic-username", "", "Basic auth username")
root.Flags().StringVar(&basicPassword, "basic-password", "", "Basic auth password") root.Flags().StringVar(&basicPassword, "basic-password", "", "Basic auth password")

View File

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

View File

@ -2,13 +2,16 @@ package misc
import ( import (
"fmt" "fmt"
"github.com/rocky-linux/srpmproc/pkg/data"
"regexp" "regexp"
) )
func GetTagImportRegex(importBranchPrefix string, allowStreamBranches bool) *regexp.Regexp { func GetTagImportRegex(pd *data.ProcessData) *regexp.Regexp {
if allowStreamBranches { branchRegex := fmt.Sprintf("%s%d%s", pd.ImportBranchPrefix, pd.Version, pd.BranchSuffix)
return regexp.MustCompile(fmt.Sprintf("refs/tags/(imports/(%s(?:.s|.)|%s(?:|s).+)/(.*))", importBranchPrefix, importBranchPrefix)) if pd.StrictBranchMode {
} else { branchRegex += ".+"
return regexp.MustCompile(fmt.Sprintf("refs/tags/(imports/(%s.|%s.-.+)/(.*))", importBranchPrefix, importBranchPrefix))
} }
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 { tagAdd := func(tag *object.Tag) error {
if strings.HasPrefix(tag.Name, fmt.Sprintf("imports/%s%d", pd.ImportBranchPrefix, pd.Version)) { if strings.HasPrefix(tag.Name, fmt.Sprintf("imports/%s%d", pd.ImportBranchPrefix, pd.Version)) {
refSpec := fmt.Sprintf("refs/tags/%s", tag.Name) refSpec := fmt.Sprintf("refs/tags/%s", tag.Name)
if misc.GetTagImportRegex(pd.ImportBranchPrefix, pd.AllowStreamBranches).MatchString(refSpec) { if misc.GetTagImportRegex(pd).MatchString(refSpec) {
match := misc.GetTagImportRegex(pd.ImportBranchPrefix, pd.AllowStreamBranches).FindStringSubmatch(refSpec) match := misc.GetTagImportRegex(pd).FindStringSubmatch(refSpec)
exists := latestTags[match[2]] exists := latestTags[match[2]]
if exists != nil && exists.when.After(tag.Tagger.When) { 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)) refspec = config.RefSpec(fmt.Sprintf("+%s:%s", md.TagBranch, md.TagBranch))
branchName = strings.TrimPrefix(md.TagBranch, "refs/heads/") branchName = strings.TrimPrefix(md.TagBranch, "refs/heads/")
} else { } else {
match := misc.GetTagImportRegex(pd.ImportBranchPrefix, pd.AllowStreamBranches).FindStringSubmatch(md.TagBranch) match := misc.GetTagImportRegex(pd).FindStringSubmatch(md.TagBranch)
branchName = match[2] branchName = match[2]
refspec = config.RefSpec(fmt.Sprintf("+refs/heads/%s:%s", branchName, md.TagBranch)) 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 { func (g *GitMode) ImportName(pd *data.ProcessData, md *data.ModeData) string {
if misc.GetTagImportRegex(pd.ImportBranchPrefix, pd.AllowStreamBranches).MatchString(md.TagBranch) { if misc.GetTagImportRegex(pd).MatchString(md.TagBranch) {
match := misc.GetTagImportRegex(pd.ImportBranchPrefix, pd.AllowStreamBranches).FindStringSubmatch(md.TagBranch) match := misc.GetTagImportRegex(pd).FindStringSubmatch(md.TagBranch)
return match[3] return match[3]
} }

View File

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

View File

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