Skip to content

Commit

Permalink
Merge pull request #15 from nazunalika/main
Browse files Browse the repository at this point in the history
  • Loading branch information
mstg authored Oct 6, 2023
2 parents 40180a3 + 162e7ce commit f237484
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cmd/srpmproc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var (
packageRelease string
taglessMode bool
cdn string
moduleBranchNames bool
)

var root = &cobra.Command{
Expand Down Expand Up @@ -97,6 +98,7 @@ func mn(_ *cobra.Command, _ []string) {
PackageRelease: packageRelease,
TaglessMode: taglessMode,
Cdn: cdn,
ModuleBranchNames: moduleBranchNames,
})
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -148,6 +150,7 @@ func main() {
root.Flags().StringVar(&packageRelease, "package-release", "", "Package release to fetch")
root.Flags().BoolVar(&taglessMode, "taglessmode", false, "Tagless mode: If set, pull the latest commit from the branch and determine version numbers from spec file. This is auto-tried if tags aren't found.")
root.Flags().StringVar(&cdn, "cdn", "", "CDN URL shortcuts for well-known distros, auto-assigns --cdn-url. Valid values: rocky8, rocky, fedora, centos, centos-stream. Setting this overrides --cdn-url")
root.Flags().BoolVar(&moduleBranchNames, "module-branch-names-only", false, "If enabled, module imports will use the branch name that is being imported, rather than use the commit hash.")

if err := root.Execute(); err != nil {
log.Fatal(err)
Expand Down
1 change: 1 addition & 0 deletions pkg/data/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ type ProcessData struct {
PackageRelease string
TaglessMode bool
Cdn string
ModuleBranchNames bool
}
6 changes: 6 additions & 0 deletions pkg/srpmproc/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,12 @@ func patchModuleYaml(pd *data.ProcessData, md *data.ModeData) error {
}
}

// If we got this far, we're good. This means the repos, branches, and commits exist.
// If this option is on, just use the branch name.
if pd.ModuleBranchNames {
tipHash = md.PushBranch
}

rpm.Ref = tipHash
}

Expand Down
18 changes: 17 additions & 1 deletion pkg/srpmproc/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ type ProcessDataRequest struct {

TaglessMode bool
Cdn string

ModuleBranchNames bool
}

type LookasidePath struct {
Expand Down Expand Up @@ -335,6 +337,7 @@ func NewProcessData(req *ProcessDataRequest) (*data.ProcessData, error) {
PackageRelease: req.PackageRelease,
TaglessMode: req.TaglessMode,
Cdn: req.Cdn,
ModuleBranchNames: req.ModuleBranchNames,
}, nil
}

Expand Down Expand Up @@ -655,6 +658,12 @@ func ProcessRPM(pd *data.ProcessData) (*srpmprocpb.ProcessResponse, error) {

// show status
status, _ := w.Status()
if !pd.ModuleMode {
if status.IsClean() {
pd.Log.Printf("No changes detected. Our downstream is up to date.")
continue
}
}
pd.Log.Printf("successfully processed:\n%s", status)

statusLines := strings.Split(status.String(), "\n")
Expand Down Expand Up @@ -740,7 +749,6 @@ func ProcessRPM(pd *data.ProcessData) (*srpmprocpb.ProcessResponse, error) {
}

// Process for when we want to import a tagless repo (like from CentOS Stream)
//
func processRPMTagless(pd *data.ProcessData) (*srpmprocpb.ProcessResponse, error) {
pd.Log.Println("Tagless mode detected, attempting import of latest commit")

Expand Down Expand Up @@ -993,6 +1001,12 @@ func processRPMTagless(pd *data.ProcessData) (*srpmprocpb.ProcessResponse, error
}

status, err := w.Status()
if !pd.ModuleMode {
if status.IsClean() {
pd.Log.Printf("No changes detected. Our downstream is up to date.")
continue
}
}
pd.Log.Printf("successfully processed:\n%s", status)

// assign tag for our new remote we're about to push (derived from the SRPM version)
Expand Down Expand Up @@ -1208,6 +1222,7 @@ func convertMetaData(pkgName string, localRepo string) bool {
// Given a local checked out folder and package name, including SPECS/ , SOURCES/ , and .package.metadata, this will:
// - create a "dummy" SRPM (using dummy sources files we use to populate tarballs from lookaside)
// - extract RPM version info from that SRPM, and return it
//
// If we are in tagless mode, we need to get a package version somehow!
func getVersionFromSpec(localRepo string, majorVersion int) (string, error) {
// Make sure we have "rpm" and "rpmbuild" and "cp" available in our PATH. Otherwise, this won't work:
Expand All @@ -1232,6 +1247,7 @@ func getVersionFromSpec(localRepo string, majorVersion int) (string, error) {
cmdArgs := []string{
"--srpm",
fmt.Sprintf(`--define=dist .el%d`, majorVersion),
fmt.Sprintf(`--define=_topdir %s`, localRepo),
"-q",
"--queryformat",
`%{NAME}|%{VERSION}|%{RELEASE}\n`,
Expand Down

0 comments on commit f237484

Please sign in to comment.