github.com/0xPolygon/supernets2-node@v0.0.0-20230711153321-2fe574524eaa/test/scripts/cmd/dependencies/protobuffers.go (about)

     1  package dependencies
     2  
     3  import (
     4  	"os"
     5  	"os/exec"
     6  
     7  	"github.com/0xPolygon/supernets2-node/log"
     8  	"github.com/spf13/afero"
     9  )
    10  
    11  // PBConfig is the configuration for the protobuffers updater.
    12  type PBConfig struct {
    13  	SourceRepo    string
    14  	TargetDirPath string
    15  }
    16  
    17  type pbUpdater struct {
    18  	fs afero.Fs
    19  
    20  	gm *githubManager
    21  
    22  	sourceRepo    string
    23  	targetDirPath string
    24  }
    25  
    26  func newPBUpdater(sourceRepo, targetDirPath string) *pbUpdater {
    27  	aferoFs := afero.NewOsFs()
    28  
    29  	gm := newGithubManager(aferoFs, os.Getenv("UPDATE_DEPS_SSH_PK"), os.Getenv("GITHUB_TOKEN"))
    30  
    31  	return &pbUpdater{
    32  		fs: aferoFs,
    33  
    34  		gm: gm,
    35  
    36  		sourceRepo:    sourceRepo,
    37  		targetDirPath: targetDirPath,
    38  	}
    39  }
    40  
    41  func (pb *pbUpdater) update() error {
    42  	log.Infof("Cloning %q...", pb.sourceRepo)
    43  	tmpdir, err := pb.gm.cloneTargetRepo(pb.sourceRepo)
    44  	if err != nil {
    45  		return err
    46  	}
    47  
    48  	targetDirPath := getTargetPath(pb.targetDirPath)
    49  
    50  	log.Infof("Updating files %q...", pb.sourceRepo)
    51  	err = updateFiles(pb.fs, tmpdir, targetDirPath)
    52  	if err != nil {
    53  		return err
    54  	}
    55  
    56  	log.Infof("Generating stubs from proto files...")
    57  
    58  	c := exec.Command("make", "generate-code-from-proto")
    59  	c.Dir = "."
    60  	c.Stdout = os.Stdout
    61  	c.Stderr = os.Stderr
    62  	return c.Run()
    63  }