mirror of
https://github.com/peridotbuild/peridot.git
synced 2024-12-07 20:06:26 +00:00
Add support for different branch namings (rolling vs X.Y)
This commit is contained in:
parent
1d55fd78fb
commit
653d0736ed
@ -89,7 +89,13 @@ func run(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
w := worker.New(temporalClient, ctx.String("temporal-task-queue"), worker.Options{})
|
||||
workerServer := mothership_worker_server.New(db, storage, gpgKeys, remoteForge)
|
||||
workerServer := mothership_worker_server.New(
|
||||
db,
|
||||
storage,
|
||||
gpgKeys,
|
||||
remoteForge,
|
||||
ctx.Bool("import-rolling-release"),
|
||||
)
|
||||
|
||||
// Register workflows
|
||||
w.RegisterWorkflow(mothership_worker_server.ProcessRPMWorkflow)
|
||||
@ -106,12 +112,18 @@ func main() {
|
||||
base.ChangeDefaultForEnvVar(base.EnvVarTemporalTaskQueue, "mship_worker_server")
|
||||
|
||||
flags := base.WithDefaultCliFlagsTemporal(base.WithStorageFlags()...)
|
||||
flags = append(flags, &cli.StringSliceFlag{
|
||||
Name: "allowed-gpg-keys",
|
||||
Usage: "Armored GPG keys that we verify SRPMs with. Must be base64 encoded",
|
||||
EnvVars: []string{"ALLOWED_GPG_KEYS"},
|
||||
})
|
||||
flags = append(flags, []cli.Flag{
|
||||
&cli.StringSliceFlag{
|
||||
Name: "allowed-gpg-keys",
|
||||
Usage: "Armored GPG keys that we verify SRPMs with. Must be base64 encoded",
|
||||
EnvVars: []string{"ALLOWED_GPG_KEYS"},
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "import-rolling-release",
|
||||
Usage: "Whether to import packages in rolling release mode",
|
||||
EnvVars: []string{"IMPORT_ROLLING_RELEASE"},
|
||||
Value: false,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "git-provider",
|
||||
Action: func(ctx *cli.Context, s string) error {
|
||||
|
@ -88,7 +88,7 @@ func (w *Worker) VerifyResourceExists(uri string) error {
|
||||
|
||||
// ImportRPM imports an RPM into the database.
|
||||
// This is a Temporal activity.
|
||||
func (w *Worker) ImportRPM(uri string, checksumSha256 string) (*mothershippb.ImportRPMResponse, error) {
|
||||
func (w *Worker) ImportRPM(uri string, checksumSha256 string, osRelease string) (*mothershippb.ImportRPMResponse, error) {
|
||||
tempDir, err := os.MkdirTemp("", "mothership-worker-server-import-rpm-*")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to create temporary directory")
|
||||
@ -151,7 +151,7 @@ func (w *Worker) ImportRPM(uri string, checksumSha256 string) (*mothershippb.Imp
|
||||
}
|
||||
|
||||
// Then do an import
|
||||
srpmState, err := srpm_import.FromFile(filepath.Join(tempDir, "resource.rpm"), w.gpgKeys...)
|
||||
srpmState, err := srpm_import.FromFile(filepath.Join(tempDir, "resource.rpm"), w.rolling, w.gpgKeys...)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "failed to verify RPM") {
|
||||
return nil, temporal.NewNonRetryableApplicationError(
|
||||
@ -170,7 +170,7 @@ func (w *Worker) ImportRPM(uri string, checksumSha256 string) (*mothershippb.Imp
|
||||
}
|
||||
storer := memory.NewStorage()
|
||||
fs := memfs.New()
|
||||
commit, err := srpmState.Import(cloneOpts, storer, fs, w.storage)
|
||||
commit, err := srpmState.Import(cloneOpts, storer, fs, w.storage, osRelease)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to import SRPM")
|
||||
}
|
||||
|
@ -36,7 +36,10 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var elDistRegex = regexp.MustCompile(`el\d+`)
|
||||
var (
|
||||
elDistRegex = regexp.MustCompile(`el\d+`)
|
||||
releaseRegex = regexp.MustCompile(`.*release (\d+\.\d+).*`)
|
||||
)
|
||||
|
||||
type State struct {
|
||||
// tempDir is the temporary directory where the SRPM is extracted to.
|
||||
@ -53,6 +56,11 @@ type State struct {
|
||||
|
||||
// lookasideBlobs is a map of blob names to their SHA256 hashes.
|
||||
lookasideBlobs map[string]string
|
||||
|
||||
// rolling determines how the branch is named.
|
||||
// if true, the branch is named "elX" where X is the major release
|
||||
// if false, the branch is named "el-X.Y" where X.Y is the full release
|
||||
rolling bool
|
||||
}
|
||||
|
||||
// copyFromOS copies specified file from OS filesystem to target filesystem.
|
||||
@ -82,7 +90,7 @@ func copyFromOS(targetFS billy.Filesystem, path string, targetPath string) error
|
||||
|
||||
// FromFile creates a new State from an SRPM file.
|
||||
// The SRPM file is extracted to a temporary directory.
|
||||
func FromFile(path string, keys ...*openpgp.Entity) (*State, error) {
|
||||
func FromFile(path string, rolling bool, keys ...*openpgp.Entity) (*State, error) {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to open file")
|
||||
@ -113,6 +121,7 @@ func FromFile(path string, keys ...*openpgp.Entity) (*State, error) {
|
||||
authorName: "Mship Bot",
|
||||
authorEmail: "no-reply+mshipbot@resf.org",
|
||||
lookasideBlobs: make(map[string]string),
|
||||
rolling: rolling,
|
||||
}
|
||||
// Create a temporary directory.
|
||||
state.tempDir, err = os.MkdirTemp("", "srpm_import-*")
|
||||
@ -317,21 +326,48 @@ func (s *State) expandLayout(targetFS billy.Filesystem) error {
|
||||
|
||||
// getRepo returns the target repository for the SRPM.
|
||||
// This is where the payload is uploaded to.
|
||||
func (s *State) getRepo(opts *git.CloneOptions, storer storage2.Storer, targetFS billy.Filesystem) (*git.Repository, error) {
|
||||
// Determine dist tag
|
||||
nevra, err := s.rpm.Header.GetNEVRA()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get NEVRA")
|
||||
}
|
||||
func (s *State) getRepo(opts *git.CloneOptions, storer storage2.Storer, targetFS billy.Filesystem, osRelease string) (*git.Repository, string, error) {
|
||||
// Determine branch
|
||||
// If the OS release is not specified, then we use the dist tag
|
||||
var branch string
|
||||
if osRelease == "" {
|
||||
// Determine dist tag
|
||||
nevra, err := s.rpm.Header.GetNEVRA()
|
||||
if err != nil {
|
||||
return nil, "", errors.Wrap(err, "failed to get NEVRA")
|
||||
}
|
||||
|
||||
// The dist tag will be used as the branch
|
||||
dist := elDistRegex.FindString(nevra.Release)
|
||||
if dist == "" {
|
||||
return nil, errors.Wrap(err, "failed to determine dist tag")
|
||||
// The dist tag will be used as the branch
|
||||
dist := elDistRegex.FindString(nevra.Release)
|
||||
if dist == "" {
|
||||
return nil, "", errors.Wrap(err, "failed to determine dist tag")
|
||||
}
|
||||
|
||||
if s.rolling {
|
||||
branch = dist
|
||||
} else {
|
||||
branch = "el-" + dist[2:]
|
||||
}
|
||||
} else {
|
||||
// Determine branch from OS release
|
||||
if !releaseRegex.MatchString(osRelease) {
|
||||
return nil, "", fmt.Errorf("invalid OS release %s", osRelease)
|
||||
}
|
||||
ver := releaseRegex.FindStringSubmatch(osRelease)[1]
|
||||
|
||||
if s.rolling {
|
||||
dist := elDistRegex.FindString("el" + ver)
|
||||
if dist == "" {
|
||||
return nil, "", errors.New("failed to determine dist tag")
|
||||
}
|
||||
branch = dist
|
||||
} else {
|
||||
branch = "el-" + ver
|
||||
}
|
||||
}
|
||||
|
||||
// Set branch to dist tag
|
||||
opts.ReferenceName = plumbing.NewBranchReferenceName(dist)
|
||||
opts.ReferenceName = plumbing.NewBranchReferenceName(branch)
|
||||
opts.SingleBranch = true
|
||||
|
||||
// Clone the repository, to the target filesystem.
|
||||
@ -339,11 +375,11 @@ func (s *State) getRepo(opts *git.CloneOptions, storer storage2.Storer, targetFS
|
||||
// If the repo doesn't exist, then we init only
|
||||
repo, err := git.Init(storer, targetFS)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to init repo")
|
||||
return nil, "", errors.Wrap(err, "failed to init repo")
|
||||
}
|
||||
wt, err := repo.Worktree()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get worktree")
|
||||
return nil, "", errors.Wrap(err, "failed to get worktree")
|
||||
}
|
||||
|
||||
// Create a new remote
|
||||
@ -351,11 +387,11 @@ func (s *State) getRepo(opts *git.CloneOptions, storer storage2.Storer, targetFS
|
||||
Name: "origin",
|
||||
URLs: []string{opts.URL},
|
||||
Fetch: []config.RefSpec{
|
||||
config.RefSpec(fmt.Sprintf("refs/heads/%s:refs/heads/%[1]s", dist)),
|
||||
config.RefSpec(fmt.Sprintf("refs/heads/%s:refs/heads/%[1]s", branch)),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to create remote")
|
||||
return nil, "", errors.Wrap(err, "failed to create remote")
|
||||
}
|
||||
|
||||
// Fetch the remote
|
||||
@ -363,26 +399,26 @@ func (s *State) getRepo(opts *git.CloneOptions, storer storage2.Storer, targetFS
|
||||
Auth: opts.Auth,
|
||||
RemoteName: "origin",
|
||||
RefSpecs: []config.RefSpec{
|
||||
config.RefSpec(fmt.Sprintf("refs/heads/%s:refs/heads/%[1]s", dist)),
|
||||
config.RefSpec(fmt.Sprintf("refs/heads/%s:refs/heads/%[1]s", branch)),
|
||||
},
|
||||
})
|
||||
|
||||
// Checkout the branch
|
||||
refName := plumbing.NewBranchReferenceName(dist)
|
||||
refName := plumbing.NewBranchReferenceName(branch)
|
||||
|
||||
if err != nil {
|
||||
h := plumbing.NewSymbolicReference(plumbing.HEAD, refName)
|
||||
if err := repo.Storer.CheckAndSetReference(h, nil); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to checkout branch")
|
||||
return nil, "", errors.Wrap(err, "failed to checkout branch")
|
||||
}
|
||||
} else {
|
||||
err = wt.Checkout(&git.CheckoutOptions{
|
||||
Branch: plumbing.NewBranchReferenceName(dist),
|
||||
Branch: plumbing.NewBranchReferenceName(branch),
|
||||
Force: true,
|
||||
})
|
||||
}
|
||||
|
||||
return repo, nil
|
||||
return repo, branch, nil
|
||||
}
|
||||
|
||||
// cleanTargetRepo deletes all files in the target repository.
|
||||
@ -419,7 +455,7 @@ func (s *State) cleanTargetRepo(wt *git.Worktree, root string) error {
|
||||
// 4. Write the metadata file.
|
||||
// 5. Expand the layout of the SRPM.
|
||||
// 6. Commit the changes to the target repository.
|
||||
func (s *State) populateTargetRepo(repo *git.Repository, targetFS billy.Filesystem, lookaside storage.Storage) error {
|
||||
func (s *State) populateTargetRepo(repo *git.Repository, targetFS billy.Filesystem, lookaside storage.Storage, branch string) error {
|
||||
// Clean the target repository.
|
||||
wt, err := repo.Worktree()
|
||||
if err != nil {
|
||||
@ -481,11 +517,7 @@ func (s *State) populateTargetRepo(repo *git.Repository, targetFS billy.Filesyst
|
||||
// Create a tag
|
||||
// The tag should follow the following format:
|
||||
// imports/<branch>/<nvra>
|
||||
dist := elDistRegex.FindString(nevra.Release)
|
||||
if dist == "" {
|
||||
return errors.Wrap(err, "failed to determine dist tag")
|
||||
}
|
||||
tag := fmt.Sprintf("imports/%s/%s-%s-%s", dist, nevra.Name, nevra.Version, nevra.Release)
|
||||
tag := fmt.Sprintf("imports/%s/%s-%s-%s", branch, nevra.Name, nevra.Version, nevra.Release)
|
||||
_, err = repo.CreateTag(tag, hash, &git.CreateTagOptions{
|
||||
Tagger: &object.Signature{
|
||||
Name: s.authorName,
|
||||
@ -513,31 +545,26 @@ func (s *State) pushTargetRepo(repo *git.Repository, opts *git.PushOptions) erro
|
||||
}
|
||||
|
||||
// Import imports the SRPM into the target repository.
|
||||
func (s *State) Import(opts *git.CloneOptions, storer storage2.Storer, targetFS billy.Filesystem, lookaside storage.Storage) (*object.Commit, error) {
|
||||
func (s *State) Import(opts *git.CloneOptions, storer storage2.Storer, targetFS billy.Filesystem, lookaside storage.Storage, osRelease string) (*object.Commit, error) {
|
||||
// Get the target repository.
|
||||
repo, err := s.getRepo(opts, storer, targetFS)
|
||||
repo, branch, err := s.getRepo(opts, storer, targetFS, osRelease)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get repo")
|
||||
}
|
||||
|
||||
// Populate the target repository.
|
||||
err = s.populateTargetRepo(repo, targetFS, lookaside)
|
||||
err = s.populateTargetRepo(repo, targetFS, lookaside, branch)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to populate target repo")
|
||||
}
|
||||
|
||||
// Push the target repository.
|
||||
nevra, err := s.rpm.Header.GetNEVRA()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get NEVRA")
|
||||
}
|
||||
dist := elDistRegex.FindString(nevra.Release)
|
||||
err = s.pushTargetRepo(repo, &git.PushOptions{
|
||||
Force: true,
|
||||
Auth: opts.Auth,
|
||||
RefSpecs: []config.RefSpec{
|
||||
config.RefSpec(fmt.Sprintf("refs/heads/%s:refs/heads/%[1]s", dist)),
|
||||
config.RefSpec(fmt.Sprintf("refs/tags/imports/%s/*:refs/tags/imports/%[1]s/*", dist)),
|
||||
config.RefSpec(fmt.Sprintf("refs/heads/%s:refs/heads/%[1]s", branch)),
|
||||
config.RefSpec(fmt.Sprintf("refs/tags/imports/%s/*:refs/tags/imports/%[1]s/*", branch)),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -34,7 +34,7 @@ import (
|
||||
)
|
||||
|
||||
func TestFromFile(t *testing.T) {
|
||||
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm")
|
||||
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm", false)
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, s)
|
||||
require.Nil(t, s.Close())
|
||||
@ -47,7 +47,7 @@ func TestFromFile_SignatureOK(t *testing.T) {
|
||||
testKey, err := openpgp.ReadArmoredKeyRing(keyF)
|
||||
require.Nil(t, err)
|
||||
|
||||
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm", testKey...)
|
||||
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm", false, testKey...)
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, s)
|
||||
require.Nil(t, s.Close())
|
||||
@ -60,14 +60,14 @@ func TestFromFile_SignatureFail(t *testing.T) {
|
||||
testKey, err := openpgp.ReadArmoredKeyRing(keyF)
|
||||
require.Nil(t, err)
|
||||
|
||||
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm", testKey...)
|
||||
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm", false, testKey...)
|
||||
require.NotNil(t, err)
|
||||
require.Nil(t, s)
|
||||
require.Equal(t, "failed to verify RPM: keyid 15af5dac6d745a60 not found", err.Error())
|
||||
}
|
||||
|
||||
func TestDetermineLookasideBlobs_Empty(t *testing.T) {
|
||||
s, err := FromFile("testdata/basesystem-11-5.el8.src.rpm")
|
||||
s, err := FromFile("testdata/basesystem-11-5.el8.src.rpm", false)
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, s)
|
||||
defer func() {
|
||||
@ -78,7 +78,7 @@ func TestDetermineLookasideBlobs_Empty(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDetermineLookasideBlobs_NotEmpty_Tarball(t *testing.T) {
|
||||
s, err := FromFile("testdata/bash-4.4.20-4.el8_6.src.rpm")
|
||||
s, err := FromFile("testdata/bash-4.4.20-4.el8_6.src.rpm", false)
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, s)
|
||||
defer func() {
|
||||
@ -89,7 +89,7 @@ func TestDetermineLookasideBlobs_NotEmpty_Tarball(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUploadLookaside_Empty(t *testing.T) {
|
||||
s, err := FromFile("testdata/basesystem-11-5.el8.src.rpm")
|
||||
s, err := FromFile("testdata/basesystem-11-5.el8.src.rpm", false)
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, s)
|
||||
defer func() {
|
||||
@ -108,7 +108,7 @@ func TestUploadLookaside_Empty(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUploadLookaside_NotEmpty(t *testing.T) {
|
||||
s, err := FromFile("testdata/bash-4.4.20-4.el8_6.src.rpm")
|
||||
s, err := FromFile("testdata/bash-4.4.20-4.el8_6.src.rpm", false)
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, s)
|
||||
defer func() {
|
||||
@ -126,7 +126,7 @@ func TestUploadLookaside_NotEmpty(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUploadLookaside_NotEmpty_OnlyOnceForHash(t *testing.T) {
|
||||
s, err := FromFile("testdata/bash-4.4.20-4.el8_6.src.rpm")
|
||||
s, err := FromFile("testdata/bash-4.4.20-4.el8_6.src.rpm", false)
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, s)
|
||||
defer func() {
|
||||
@ -155,7 +155,7 @@ func TestUploadLookaside_NotEmpty_OnlyOnceForHash(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWriteMetadataFile(t *testing.T) {
|
||||
s, err := FromFile("testdata/bash-4.4.20-4.el8_6.src.rpm")
|
||||
s, err := FromFile("testdata/bash-4.4.20-4.el8_6.src.rpm", false)
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, s)
|
||||
defer func() {
|
||||
@ -192,7 +192,7 @@ func TestWriteMetadataFile(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExpandLayout(t *testing.T) {
|
||||
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm")
|
||||
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm", false)
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, s)
|
||||
defer func() {
|
||||
@ -223,7 +223,7 @@ func TestExpandLayout(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWriteMetadataExpandLayout(t *testing.T) {
|
||||
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm")
|
||||
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm", false)
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, s)
|
||||
defer func() {
|
||||
@ -265,7 +265,7 @@ func TestWriteMetadataExpandLayout(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetRepo_New(t *testing.T) {
|
||||
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm")
|
||||
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm", false)
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, s)
|
||||
defer func() {
|
||||
@ -281,9 +281,121 @@ func TestGetRepo_New(t *testing.T) {
|
||||
opts := &git.CloneOptions{
|
||||
URL: "file://" + tempDir,
|
||||
}
|
||||
repo, err := s.getRepo(opts, storer, fs)
|
||||
repo, branch, err := s.getRepo(opts, storer, fs, "")
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, repo)
|
||||
require.Equal(t, "el-8", branch)
|
||||
|
||||
// Verify empty
|
||||
objIter, err := repo.CommitObjects()
|
||||
require.Nil(t, err)
|
||||
_, err = objIter.Next()
|
||||
require.Equal(t, io.EOF, err)
|
||||
}
|
||||
|
||||
func TestGetRepo_OSRelease(t *testing.T) {
|
||||
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm", false)
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, s)
|
||||
defer func() {
|
||||
require.Nil(t, s.Close())
|
||||
}()
|
||||
|
||||
tempDir, err := os.MkdirTemp("", "peridot-srpm-import-test-*")
|
||||
require.Nil(t, err)
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
storer := memory.NewStorage()
|
||||
fs := memfs.New()
|
||||
opts := &git.CloneOptions{
|
||||
URL: "file://" + tempDir,
|
||||
}
|
||||
repo, branch, err := s.getRepo(opts, storer, fs, "Rocky Linux release 8.8 (Green Obsidian)")
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, repo)
|
||||
require.Equal(t, "el-8.8", branch)
|
||||
|
||||
// Verify empty
|
||||
objIter, err := repo.CommitObjects()
|
||||
require.Nil(t, err)
|
||||
_, err = objIter.Next()
|
||||
require.Equal(t, io.EOF, err)
|
||||
}
|
||||
|
||||
func TestGetRepo_OSRelease_Error(t *testing.T) {
|
||||
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm", false)
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, s)
|
||||
defer func() {
|
||||
require.Nil(t, s.Close())
|
||||
}()
|
||||
|
||||
tempDir, err := os.MkdirTemp("", "peridot-srpm-import-test-*")
|
||||
require.Nil(t, err)
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
storer := memory.NewStorage()
|
||||
fs := memfs.New()
|
||||
opts := &git.CloneOptions{
|
||||
URL: "file://" + tempDir,
|
||||
}
|
||||
repo, branch, err := s.getRepo(opts, storer, fs, "X invalid 1.1")
|
||||
require.NotNil(t, err)
|
||||
require.Nil(t, repo)
|
||||
require.Equal(t, "", branch)
|
||||
require.Equal(t, "invalid OS release X invalid 1.1", err.Error())
|
||||
}
|
||||
|
||||
func TestGetRepo_New_Rolling(t *testing.T) {
|
||||
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm", true)
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, s)
|
||||
defer func() {
|
||||
require.Nil(t, s.Close())
|
||||
}()
|
||||
|
||||
tempDir, err := os.MkdirTemp("", "peridot-srpm-import-test-*")
|
||||
require.Nil(t, err)
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
storer := memory.NewStorage()
|
||||
fs := memfs.New()
|
||||
opts := &git.CloneOptions{
|
||||
URL: "file://" + tempDir,
|
||||
}
|
||||
repo, branch, err := s.getRepo(opts, storer, fs, "")
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, repo)
|
||||
require.Equal(t, "el8", branch)
|
||||
|
||||
// Verify empty
|
||||
objIter, err := repo.CommitObjects()
|
||||
require.Nil(t, err)
|
||||
_, err = objIter.Next()
|
||||
require.Equal(t, io.EOF, err)
|
||||
}
|
||||
|
||||
func TestGetRepo_OSRelease_Rolling(t *testing.T) {
|
||||
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm", true)
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, s)
|
||||
defer func() {
|
||||
require.Nil(t, s.Close())
|
||||
}()
|
||||
|
||||
tempDir, err := os.MkdirTemp("", "peridot-srpm-import-test-*")
|
||||
require.Nil(t, err)
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
storer := memory.NewStorage()
|
||||
fs := memfs.New()
|
||||
opts := &git.CloneOptions{
|
||||
URL: "file://" + tempDir,
|
||||
}
|
||||
repo, branch, err := s.getRepo(opts, storer, fs, "Rocky Linux release 8.8 (Green Obsidian)")
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, repo)
|
||||
require.Equal(t, "el8", branch)
|
||||
|
||||
// Verify empty
|
||||
objIter, err := repo.CommitObjects()
|
||||
@ -293,7 +405,7 @@ func TestGetRepo_New(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetRepo_Existing(t *testing.T) {
|
||||
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm")
|
||||
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm", false)
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, s)
|
||||
defer func() {
|
||||
@ -324,7 +436,7 @@ func TestGetRepo_Existing(t *testing.T) {
|
||||
filesystemTemp2 := filesystem.NewStorage(dot2, cache.NewObjectLRUDefault())
|
||||
|
||||
repo, err := git.InitWithOptions(filesystemTemp2, osfs2, git.InitOptions{
|
||||
DefaultBranch: "refs/heads/el8",
|
||||
DefaultBranch: "refs/heads/el-8",
|
||||
})
|
||||
require.Nil(t, err)
|
||||
_, err = repo.CreateRemote(&config.RemoteConfig{
|
||||
@ -351,7 +463,7 @@ func TestGetRepo_Existing(t *testing.T) {
|
||||
})
|
||||
require.Nil(t, err)
|
||||
err = repo.Push(&git.PushOptions{
|
||||
RefSpecs: []config.RefSpec{"refs/heads/el8:refs/heads/el8"},
|
||||
RefSpecs: []config.RefSpec{"refs/heads/el-8:refs/heads/el-8"},
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
@ -360,9 +472,10 @@ func TestGetRepo_Existing(t *testing.T) {
|
||||
opts := &git.CloneOptions{
|
||||
URL: "file://" + tempDir,
|
||||
}
|
||||
repo, err = s.getRepo(opts, storer, fs)
|
||||
repo, branch, err := s.getRepo(opts, storer, fs, "")
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, repo)
|
||||
require.Equal(t, "el-8", branch)
|
||||
|
||||
// Verify commit
|
||||
objIter, err := repo.CommitObjects()
|
||||
@ -373,7 +486,7 @@ func TestGetRepo_Existing(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCleanTargetRepo_Existing(t *testing.T) {
|
||||
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm")
|
||||
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm", false)
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, s)
|
||||
defer func() {
|
||||
@ -404,7 +517,7 @@ func TestCleanTargetRepo_Existing(t *testing.T) {
|
||||
filesystemTemp2 := filesystem.NewStorage(dot2, cache.NewObjectLRUDefault())
|
||||
|
||||
repo, err := git.InitWithOptions(filesystemTemp2, osfs2, git.InitOptions{
|
||||
DefaultBranch: "refs/heads/el8",
|
||||
DefaultBranch: "refs/heads/el-8",
|
||||
})
|
||||
require.Nil(t, err)
|
||||
_, err = repo.CreateRemote(&config.RemoteConfig{
|
||||
@ -431,7 +544,7 @@ func TestCleanTargetRepo_Existing(t *testing.T) {
|
||||
})
|
||||
require.Nil(t, err)
|
||||
err = repo.Push(&git.PushOptions{
|
||||
RefSpecs: []config.RefSpec{"refs/heads/el8:refs/heads/el8"},
|
||||
RefSpecs: []config.RefSpec{"refs/heads/el-8:refs/heads/el-8"},
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
@ -440,9 +553,10 @@ func TestCleanTargetRepo_Existing(t *testing.T) {
|
||||
opts := &git.CloneOptions{
|
||||
URL: "file://" + tempDir,
|
||||
}
|
||||
repo, err = s.getRepo(opts, storer, fs)
|
||||
repo, branch, err := s.getRepo(opts, storer, fs, "")
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, repo)
|
||||
require.Equal(t, "el-8", branch)
|
||||
|
||||
wt, err := repo.Worktree()
|
||||
require.Nil(t, err)
|
||||
@ -464,7 +578,7 @@ func TestCleanTargetRepo_Existing(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPopulateTargetRepo_New(t *testing.T) {
|
||||
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm")
|
||||
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm", false)
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, s)
|
||||
defer func() {
|
||||
@ -480,9 +594,10 @@ func TestPopulateTargetRepo_New(t *testing.T) {
|
||||
opts := &git.CloneOptions{
|
||||
URL: "file://" + tempDir,
|
||||
}
|
||||
repo, err := s.getRepo(opts, storer, fs)
|
||||
repo, branch, err := s.getRepo(opts, storer, fs, "")
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, repo)
|
||||
require.Equal(t, "el-8", branch)
|
||||
|
||||
// Verify empty
|
||||
objIter, err := repo.CommitObjects()
|
||||
@ -492,7 +607,7 @@ func TestPopulateTargetRepo_New(t *testing.T) {
|
||||
|
||||
// Populate repo
|
||||
inMemory := storage_memory.New(osfs.New("/"))
|
||||
require.Nil(t, s.populateTargetRepo(repo, fs, inMemory))
|
||||
require.Nil(t, s.populateTargetRepo(repo, fs, inMemory, branch))
|
||||
|
||||
// Verify commit
|
||||
objIter, err = repo.CommitObjects()
|
||||
@ -506,7 +621,7 @@ func TestPopulateTargetRepo_New(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
tag, err := tagIter.Next()
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, "imports/el8/efi-rpm-macros-3-3.el8", tag.Name().Short())
|
||||
require.Equal(t, "imports/el-8/efi-rpm-macros-3-3.el8", tag.Name().Short())
|
||||
|
||||
// Verify metadata
|
||||
f, err := fs.Open(".efi-rpm-macros.metadata")
|
||||
@ -536,7 +651,7 @@ func TestPopulateTargetRepo_New(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPopulateTargetRepo_Existing(t *testing.T) {
|
||||
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm")
|
||||
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm", false)
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, s)
|
||||
defer func() {
|
||||
@ -567,7 +682,7 @@ func TestPopulateTargetRepo_Existing(t *testing.T) {
|
||||
filesystemTemp2 := filesystem.NewStorage(dot2, cache.NewObjectLRUDefault())
|
||||
|
||||
repo, err := git.InitWithOptions(filesystemTemp2, osfs2, git.InitOptions{
|
||||
DefaultBranch: "refs/heads/el8",
|
||||
DefaultBranch: "refs/heads/el-8",
|
||||
})
|
||||
require.Nil(t, err)
|
||||
_, err = repo.CreateRemote(&config.RemoteConfig{
|
||||
@ -598,7 +713,7 @@ func TestPopulateTargetRepo_Existing(t *testing.T) {
|
||||
})
|
||||
require.Nil(t, err)
|
||||
err = repo.Push(&git.PushOptions{
|
||||
RefSpecs: []config.RefSpec{"refs/heads/el8:refs/heads/el8"},
|
||||
RefSpecs: []config.RefSpec{"refs/heads/el-8:refs/heads/el-8"},
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
@ -607,7 +722,7 @@ func TestPopulateTargetRepo_Existing(t *testing.T) {
|
||||
opts := &git.CloneOptions{
|
||||
URL: tempDir,
|
||||
}
|
||||
repo, err = s.getRepo(opts, storer, fs)
|
||||
repo, branch, err := s.getRepo(opts, storer, fs, "")
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, repo)
|
||||
|
||||
@ -620,7 +735,7 @@ func TestPopulateTargetRepo_Existing(t *testing.T) {
|
||||
|
||||
// Populate repo
|
||||
inMemory := storage_memory.New(osfs.New("/"))
|
||||
require.Nil(t, s.populateTargetRepo(repo, fs, inMemory))
|
||||
require.Nil(t, s.populateTargetRepo(repo, fs, inMemory, branch))
|
||||
|
||||
// Verify commit (second one)
|
||||
var sortedCommits []*object.Commit
|
||||
@ -643,7 +758,7 @@ func TestPopulateTargetRepo_Existing(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
tag, err := tagIter.Next()
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, "imports/el8/efi-rpm-macros-3-3.el8", tag.Name().Short())
|
||||
require.Equal(t, "imports/el-8/efi-rpm-macros-3-3.el8", tag.Name().Short())
|
||||
|
||||
// Verify metadata
|
||||
f, err = fs.Open(".efi-rpm-macros.metadata")
|
||||
@ -673,7 +788,7 @@ func TestPopulateTargetRepo_Existing(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPushTargetRepo(t *testing.T) {
|
||||
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm")
|
||||
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm", false)
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, s)
|
||||
defer func() {
|
||||
@ -743,7 +858,7 @@ func TestPushTargetRepo(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestImport1_New(t *testing.T) {
|
||||
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm")
|
||||
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm", false)
|
||||
require.Nil(t, err)
|
||||
|
||||
tempDir, err := os.MkdirTemp("", "peridot-srpm-import-test-*")
|
||||
@ -765,7 +880,90 @@ func TestImport1_New(t *testing.T) {
|
||||
storer := memory.NewStorage()
|
||||
fs := memfs.New()
|
||||
lookaside := storage_memory.New(osfs.New("/"))
|
||||
_, err = s.Import(opts, storer, fs, lookaside)
|
||||
_, err = s.Import(opts, storer, fs, lookaside, "")
|
||||
require.Nil(t, err)
|
||||
|
||||
// Open repo
|
||||
repo, err := git.PlainOpen(tempDir)
|
||||
require.Nil(t, err)
|
||||
// Switch to el8 branch
|
||||
w, err := repo.Worktree()
|
||||
require.Nil(t, err)
|
||||
err = w.Checkout(&git.CheckoutOptions{
|
||||
Branch: "refs/heads/el-8",
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
// Verify commit
|
||||
objIter, err := repo.CommitObjects()
|
||||
require.Nil(t, err)
|
||||
obj, err := objIter.Next()
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, "import efi-rpm-macros-3-3.el8", obj.Message)
|
||||
|
||||
// Verify tag
|
||||
tagIter, err := repo.Tags()
|
||||
require.Nil(t, err)
|
||||
tag, err := tagIter.Next()
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, "imports/el-8/efi-rpm-macros-3-3.el8", tag.Name().Short())
|
||||
|
||||
// Verify metadata
|
||||
f, err := fs.Open(".efi-rpm-macros.metadata")
|
||||
require.Nil(t, err)
|
||||
buf, err := io.ReadAll(f)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, "f002f60baed7a47ca3e98b8dd7ece2f7352dac9ffab7ae3557eb56b481ce2f86 SOURCES/efi-rpm-macros-3.tar.bz2\n", string(buf))
|
||||
|
||||
// Verify layout
|
||||
ls, err := fs.ReadDir(".")
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, 4, len(ls))
|
||||
require.Equal(t, ".efi-rpm-macros.metadata", ls[0].Name())
|
||||
require.Equal(t, ".gitignore", ls[1].Name())
|
||||
require.Equal(t, "SOURCES", ls[2].Name())
|
||||
require.Equal(t, "SPECS", ls[3].Name())
|
||||
|
||||
ls, err = fs.ReadDir("SOURCES")
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, 1, len(ls))
|
||||
require.Equal(t, "0001-macros.efi-srpm-make-all-of-our-macros-always-expand.patch", ls[0].Name())
|
||||
|
||||
ls, err = fs.ReadDir("SPECS")
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, 1, len(ls))
|
||||
require.Equal(t, "efi-rpm-macros.spec", ls[0].Name())
|
||||
|
||||
// Verify lookaside
|
||||
ok, err := lookaside.Exists("f002f60baed7a47ca3e98b8dd7ece2f7352dac9ffab7ae3557eb56b481ce2f86")
|
||||
require.Nil(t, err)
|
||||
require.True(t, ok)
|
||||
}
|
||||
|
||||
func TestImport1_New_Rolling(t *testing.T) {
|
||||
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm", true)
|
||||
require.Nil(t, err)
|
||||
|
||||
tempDir, err := os.MkdirTemp("", "peridot-srpm-import-test-*")
|
||||
require.Nil(t, err)
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
// Create a bare repo in tempDir
|
||||
osfsTemp := osfs.New(tempDir)
|
||||
dot, err := osfsTemp.Chroot(".git")
|
||||
require.Nil(t, err)
|
||||
filesystemTemp := filesystem.NewStorage(dot, cache.NewObjectLRUDefault())
|
||||
require.Nil(t, filesystemTemp.Init())
|
||||
_, err = git.Init(filesystemTemp, nil)
|
||||
require.Nil(t, err)
|
||||
|
||||
opts := &git.CloneOptions{
|
||||
URL: tempDir,
|
||||
}
|
||||
storer := memory.NewStorage()
|
||||
fs := memfs.New()
|
||||
lookaside := storage_memory.New(osfs.New("/"))
|
||||
_, err = s.Import(opts, storer, fs, lookaside, "")
|
||||
require.Nil(t, err)
|
||||
|
||||
// Open repo
|
||||
@ -826,7 +1024,7 @@ func TestImport1_New(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestImport2_New(t *testing.T) {
|
||||
s, err := FromFile("testdata/bash-4.4.20-4.el8_6.src.rpm")
|
||||
s, err := FromFile("testdata/bash-4.4.20-4.el8_6.src.rpm", true)
|
||||
require.Nil(t, err)
|
||||
|
||||
tempDir, err := os.MkdirTemp("", "peridot-srpm-import-test-*")
|
||||
@ -847,7 +1045,7 @@ func TestImport2_New(t *testing.T) {
|
||||
storer := memory.NewStorage()
|
||||
fs := memfs.New()
|
||||
lookaside := storage_memory.New(osfs.New("/"))
|
||||
_, err = s.Import(opts, storer, fs, lookaside)
|
||||
_, err = s.Import(opts, storer, fs, lookaside, "")
|
||||
require.Nil(t, err)
|
||||
|
||||
// Open repo
|
||||
|
@ -26,9 +26,10 @@ type Worker struct {
|
||||
storage storage.Storage
|
||||
gpgKeys openpgp.EntityList
|
||||
forge forge.Forge
|
||||
rolling bool
|
||||
}
|
||||
|
||||
func New(db *base.DB, storage storage.Storage, gpgKeys openpgp.EntityList, forge forge.Forge) *Worker {
|
||||
func New(db *base.DB, storage storage.Storage, gpgKeys openpgp.EntityList, forge forge.Forge, rolling bool) *Worker {
|
||||
return &Worker{
|
||||
db: db,
|
||||
storage: storage,
|
||||
|
@ -57,7 +57,7 @@ func ProcessRPMWorkflow(ctx workflow.Context, args *mothershippb.ProcessRPMArgs)
|
||||
},
|
||||
})
|
||||
var importRpmRes mothershippb.ImportRPMResponse
|
||||
err = workflow.ExecuteActivity(ctx, w.ImportRPM, args.Request.RpmUri, args.Request.Checksum).Get(ctx, &importRpmRes)
|
||||
err = workflow.ExecuteActivity(ctx, w.ImportRPM, args.Request.RpmUri, args.Request.Checksum, args.Request.OsRelease).Get(ctx, &importRpmRes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user