Skip to content

Commit

Permalink
fix tmpfs mode, replace stream mode with branch suffix and strict mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mstg committed Apr 21, 2022
1 parent 8f55eb3 commit 61eaa8b
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 25 deletions.
9 changes: 6 additions & 3 deletions cmd/srpmproc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ var (
noStorageUpload bool
manualCommits string
moduleFallbackStream string
allowStreamBranches bool
branchSuffix string
strictBranchMode bool
basicUsername string
basicPassword string
)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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")

Expand Down
3 changes: 2 additions & 1 deletion pkg/data/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions pkg/misc/regex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
10 changes: 5 additions & 5 deletions pkg/modes/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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]
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/srpmproc/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
19 changes: 9 additions & 10 deletions pkg/srpmproc/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand Down

0 comments on commit 61eaa8b

Please sign in to comment.