Skip to content

Commit

Permalink
syz-ci: introduce gitCache parameters
Browse files Browse the repository at this point in the history
Some commits don't live long remotely.
It sometimes happens we need them later to:
1. Merge coverage.
2. Mention during communication.
  • Loading branch information
tarasmadan committed Oct 4, 2024
1 parent a4c7fd3 commit 036a640
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/vcs/fuchsia.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,7 @@ func (ctx *fuchsia) MergeBases(firstCommit, secondCommit string) ([]*Commit, err
func (ctx *fuchsia) CommitExists(string) (bool, error) {
return false, fmt.Errorf("not implemented for fuchsia")
}

func (ctx *fuchsia) PushCurrentCommitAsTagTo(repo string, config ...string) error {
return ctx.repo.PushCurrentCommitAsTagTo(repo, config...)
}
23 changes: 23 additions & 0 deletions pkg/vcs/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,3 +635,26 @@ func (git *git) CommitExists(commit string) (bool, error) {
}
return true, nil
}

func (git *git) PushCurrentCommitAsTagTo(repo string, gitConfig ...string) error {
if "" == repo {

Check failure on line 640 in pkg/vcs/git.go

View workflow job for this annotation

GitHub Actions / build

ST1017: don't use Yoda conditions (stylecheck)
return nil
}
if len(gitConfig) != 0 {
gitConfigParams := append([]string{"config"}, gitConfig...)
if _, err := git.git(gitConfigParams...); err != nil {
return fmt.Errorf("git %s: %w", strings.Join(gitConfigParams, " "), err)
}
}
commit, err := git.HeadCommit()
if err != nil {
return fmt.Errorf("git.HeadCommit: %w", err)
}
tagName := commit.Hash
git.git("remote", "add", "syz-gitcache", repo) // ignore errors on re-adding
git.git("tag", tagName) // ignore errors on re-tagging
if _, err := git.git("push", "syz-gitcache", tagName); err != nil {
return fmt.Errorf("git push syz-gitcache %s: %w", tagName, err)
}
return nil
}
4 changes: 4 additions & 0 deletions pkg/vcs/vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ type Repo interface {

// CommitExists check for the commit presence in local checkout.
CommitExists(commit string) (bool, error)

//PushCurrentCommitAsTagTo is used to cache commits elsewhere.

Check failure on line 76 in pkg/vcs/vcs.go

View workflow job for this annotation

GitHub Actions / build

lint: Use either //<one-or-more-spaces>comment or //<one-or-more-tabs>comment format for comments (syz-linter)
//Returns nil error is called with empty string.

Check failure on line 77 in pkg/vcs/vcs.go

View workflow job for this annotation

GitHub Actions / build

lint: Use either //<one-or-more-spaces>comment or //<one-or-more-tabs>comment format for comments (syz-linter)
PushCurrentCommitAsTagTo(string, ...string) error
}

// Bisecter may be optionally implemented by Repo.
Expand Down
4 changes: 4 additions & 0 deletions syz-ci/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ func (mgr *Manager) pollAndBuild(lastCommit string, latestInfo *BuildInfo) (
mgr.buildFailed = needsUpdate
if commit.Hash != lastCommit && needsUpdate {
lastCommit = commit.Hash
if err := mgr.repo.PushCurrentCommitAsTagTo(mgr.cfg.GitCache); err != nil {
log.Logf(0, "%v: failed to cache commit %s from repo %s: %s",
mgr.name, lastCommit, mgr.mgrcfg.Repo, err.Error())
}
select {
case <-buildSem.WaitC():
log.Logf(0, "%v: building kernel...", mgr.name)
Expand Down
6 changes: 6 additions & 0 deletions syz-ci/syz-ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ type Config struct {
// Per-vm type JSON diffs that will be applied to every instace of the
// corresponding VM type.
PatchVMConfigs map[string]json.RawMessage `json:"patch_vm_configs"`
// Some commits don't live long. Cache them somewhere to increase lifetime.
// The cache is used by coverage merger.
GitCache string
// "git config" params you want to be called to configure git cache.
// Only one git config command will be called.
GitCacheConfig []string
}

type ManagerConfig struct {
Expand Down

0 comments on commit 036a640

Please sign in to comment.