Stop converting v3 to v2

This commit is contained in:
Mustafa Gezen 2022-11-03 04:36:25 +01:00
parent cff0cc0fbf
commit f3ac46447d
Signed by: mustafa
GPG Key ID: DCDF010D946438C1
4 changed files with 87 additions and 36 deletions

47
go.mod
View File

@ -1,6 +1,6 @@
module github.com/rocky-linux/srpmproc module github.com/rocky-linux/srpmproc
go 1.15 go 1.18
require ( require (
cloud.google.com/go/storage v1.12.0 cloud.google.com/go/storage v1.12.0
@ -13,3 +13,48 @@ require (
google.golang.org/protobuf v1.25.0 google.golang.org/protobuf v1.25.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
) )
require (
cloud.google.com/go v0.66.0 // indirect
github.com/emirpasic/gods v1.12.0 // indirect
github.com/fsnotify/fsnotify v1.4.7 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/golang/protobuf v1.4.2 // indirect
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/imdario/mergo v0.3.9 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jstemmer/go-junit-report v0.9.1 // indirect
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd // indirect
github.com/magiconair/properties v1.8.1 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.1.2 // indirect
github.com/pelletier/go-toml v1.2.0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/spf13/afero v1.1.2 // indirect
github.com/spf13/cast v1.3.0 // indirect
github.com/spf13/jwalterweatherman v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/xanzy/ssh-agent v0.2.1 // indirect
go.opencensus.io v0.22.4 // indirect
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/mod v0.3.0 // indirect
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b // indirect
golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43 // indirect
golang.org/x/sys v0.1.0 // indirect
golang.org/x/text v0.3.3 // indirect
golang.org/x/tools v0.0.0-20200918232735-d647fc253266 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/api v0.32.0 // indirect
google.golang.org/appengine v1.6.6 // indirect
google.golang.org/genproto v0.0.0-20200921151605-7abf4a1a14d5 // indirect
google.golang.org/grpc v1.32.0 // indirect
gopkg.in/ini.v1 v1.51.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
)

4
go.sum
View File

@ -85,7 +85,6 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
@ -440,8 +439,9 @@ golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200828194041-157a740278f4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200828194041-157a740278f4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

View File

@ -160,58 +160,49 @@ type Defaults struct {
Data *DefaultsData `yaml:"data,omitempty"` Data *DefaultsData `yaml:"data,omitempty"`
} }
func Parse(input []byte) (*ModuleMd, error) { type NotBackwardsCompatibleModuleMd struct {
V2 *ModuleMd
V3 *V3
}
func Parse(input []byte) (*NotBackwardsCompatibleModuleMd, error) {
var detect DetectVersionDocument var detect DetectVersionDocument
err := yaml.Unmarshal(input, &detect) err := yaml.Unmarshal(input, &detect)
if err != nil { if err != nil {
return nil, fmt.Errorf("error detecting document version: %s", err) return nil, fmt.Errorf("error detecting document version: %s", err)
} }
var ret ModuleMd var ret NotBackwardsCompatibleModuleMd
if detect.Version == 2 { if detect.Version == 2 {
err = yaml.Unmarshal(input, &ret) var v2 ModuleMd
err = yaml.Unmarshal(input, &v2)
if err != nil { if err != nil {
return nil, fmt.Errorf("error parsing modulemd: %s", err) return nil, fmt.Errorf("error parsing modulemd: %s", err)
} }
ret.V2 = &v2
} else if detect.Version == 3 { } else if detect.Version == 3 {
var v3 V3 var v3 V3
err = yaml.Unmarshal(input, &v3) err = yaml.Unmarshal(input, &v3)
if err != nil { if err != nil {
return nil, fmt.Errorf("error parsing modulemd: %s", err) return nil, fmt.Errorf("error parsing modulemd: %s", err)
} }
ret.V3 = &v3
ret = ModuleMd{
Document: v3.Document,
Version: v3.Version,
Data: &Data{
Name: v3.Data.Name,
Stream: v3.Data.Stream,
Summary: v3.Data.Summary,
Description: v3.Data.Description,
License: &License{
Module: v3.Data.License,
},
Xmd: v3.Data.Xmd,
References: v3.Data.References,
Profiles: v3.Data.Profiles,
Profile: v3.Data.Profile,
API: v3.Data.API,
Filter: v3.Data.Filter,
BuildOpts: &BuildOpts{
Rpms: v3.Data.Configurations[0].BuildOpts.Rpms,
Arches: v3.Data.Configurations[0].BuildOpts.Arches,
},
Components: v3.Data.Components,
},
}
} }
return &ret, nil return &ret, nil
} }
func (m *ModuleMd) Marshal(fs billy.Filesystem, path string) error { func (m *NotBackwardsCompatibleModuleMd) Marshal(fs billy.Filesystem, path string) error {
bts, err := yaml.Marshal(m) var bts []byte
var err error
if m.V2 != nil {
bts, err = yaml.Marshal(m.V2)
}
if m.V3 != nil {
bts, err = yaml.Marshal(m.V3)
}
if err != nil { if err != nil {
return err return err
} }

View File

@ -329,11 +329,26 @@ func patchModuleYaml(pd *data.ProcessData, md *data.ModeData) error {
if !pd.TaglessMode { if !pd.TaglessMode {
match := misc.GetTagImportRegex(pd).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] if module.V2 != nil {
module.V2.Data.Stream = streamBranch[len(streamBranch)-1]
}
if module.V3 != nil {
module.V3.Data.Stream = streamBranch[len(streamBranch)-1]
}
} }
var components *modulemd.Components
if module.V2 != nil {
components = module.V2.Data.Components
}
if module.V3 != nil {
components = module.V3.Data.Components
}
log.Println("This module contains the following rpms:") log.Println("This module contains the following rpms:")
for name := range module.Data.Components.Rpms { for name := range components.Rpms {
pd.Log.Printf("\t- %s", name) pd.Log.Printf("\t- %s", name)
} }
@ -342,7 +357,7 @@ func patchModuleYaml(pd *data.ProcessData, md *data.ModeData) error {
defaultBranch = fmt.Sprintf("%s%d-stream-%s", pd.BranchPrefix, pd.Version, pd.ModuleFallbackStream) defaultBranch = fmt.Sprintf("%s%d-stream-%s", pd.BranchPrefix, pd.Version, pd.ModuleFallbackStream)
} }
for name, rpm := range module.Data.Components.Rpms { for name, rpm := range components.Rpms {
var tipHash string var tipHash string
var pushBranch string var pushBranch string