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