blob: 51e4d0335910a185632d899578fb79cf8c773d54 [file] [log] [blame]
package repo_manager
import (
"context"
"net/http"
"go.skia.org/infra/autoroll/go/codereview"
"go.skia.org/infra/autoroll/go/config_vars"
"go.skia.org/infra/autoroll/go/repo_manager/child"
"go.skia.org/infra/autoroll/go/repo_manager/common/git_common"
"go.skia.org/infra/autoroll/go/repo_manager/common/version_file_common"
"go.skia.org/infra/autoroll/go/repo_manager/parent"
"go.skia.org/infra/autoroll/go/strategy"
"go.skia.org/infra/go/depot_tools/deps_parser"
"go.skia.org/infra/go/github"
"go.skia.org/infra/go/skerr"
)
const (
TMPL_COMMIT_MSG_GITHUB_CIPD_DEPS = `Roll {{.ChildPath}} from {{.RollingFrom.String}} to {{.RollingTo.String}}
If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
{{.ServerURL}}
Please CC {{stringsJoin .Reviewers ","}} on the revert to ensure that a human
is aware of the problem.
To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug
Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/master/autoroll/README.md
`
)
// GithubCipdDEPSRepoManagerConfig provides configuration for the Github RepoManager.
type GithubCipdDEPSRepoManagerConfig struct {
GithubDEPSRepoManagerConfig
CipdAssetName string `json:"cipdAssetName"`
CipdAssetTag string `json:"cipdAssetTag"`
}
// See documentation for RepoManagerConfig interface.
func (c *GithubCipdDEPSRepoManagerConfig) ValidStrategies() []string {
return []string{
strategy.ROLL_STRATEGY_BATCH,
}
}
// See documentation for util.Validator interface.
func (c *GithubCipdDEPSRepoManagerConfig) Validate() error {
_, _, err := c.splitParentChild()
return skerr.Wrap(err)
}
// splitParentChild splits the GithubCipdDEPSRepoManagerConfig into a
// parent.DEPSLocalConfig and a child.GitCheckoutConfig.
// TODO(borenet): Update the config format to directly define the parent
// and child. We shouldn't need most of the New.*RepoManager functions.
func (c GithubCipdDEPSRepoManagerConfig) splitParentChild() (parent.DEPSLocalConfig, child.CIPDConfig, error) {
parentCfg := parent.DEPSLocalConfig{
GitCheckoutConfig: parent.GitCheckoutConfig{
BaseConfig: parent.BaseConfig{
ChildPath: c.DepotToolsRepoManagerConfig.CommonRepoManagerConfig.ChildPath,
ChildRepo: c.CipdAssetName,
IncludeBugs: c.DepotToolsRepoManagerConfig.CommonRepoManagerConfig.IncludeBugs,
IncludeLog: c.DepotToolsRepoManagerConfig.CommonRepoManagerConfig.IncludeLog,
CommitMsgTmpl: c.DepotToolsRepoManagerConfig.CommonRepoManagerConfig.CommitMsgTmpl,
MonorailProject: c.DepotToolsRepoManagerConfig.CommonRepoManagerConfig.BugProject,
},
GitCheckoutConfig: git_common.GitCheckoutConfig{
Branch: c.DepotToolsRepoManagerConfig.CommonRepoManagerConfig.ParentBranch,
RepoURL: c.DepotToolsRepoManagerConfig.CommonRepoManagerConfig.ParentRepo,
},
DependencyConfig: version_file_common.DependencyConfig{
VersionFileConfig: version_file_common.VersionFileConfig{
ID: c.CipdAssetName,
Path: deps_parser.DepsFileName,
},
},
},
CheckoutPath: c.GithubParentPath,
GClientSpec: c.GClientSpec,
PreUploadSteps: c.DepotToolsRepoManagerConfig.CommonRepoManagerConfig.PreUploadSteps,
RunHooks: c.RunHooks,
}
if err := parentCfg.Validate(); err != nil {
return parent.DEPSLocalConfig{}, child.CIPDConfig{}, skerr.Wrapf(err, "generated parent config is invalid")
}
childCfg := child.CIPDConfig{
Name: c.CipdAssetName,
Tag: c.CipdAssetTag,
}
if err := childCfg.Validate(); err != nil {
return parent.DEPSLocalConfig{}, child.CIPDConfig{}, skerr.Wrapf(err, "generated child.CIPDConfig is invalid")
}
return parentCfg, childCfg, nil
}
// NewGithubCipdDEPSRepoManager returns a RepoManager instance which operates in the given
// working directory and updates at the given frequency.
func NewGithubCipdDEPSRepoManager(ctx context.Context, c *GithubCipdDEPSRepoManagerConfig, reg *config_vars.Registry, workdir, rollerName string, githubClient *github.GitHub, recipeCfgFile, serverURL string, httpClient *http.Client, cr codereview.CodeReview, local bool) (*parentChildRepoManager, error) {
if err := c.Validate(); err != nil {
return nil, skerr.Wrap(err)
}
parentCfg, childCfg, err := c.splitParentChild()
if err != nil {
return nil, skerr.Wrap(err)
}
if parentCfg.CommitMsgTmpl == "" {
parentCfg.CommitMsgTmpl = TMPL_COMMIT_MSG_GITHUB_CIPD_DEPS
}
uploadRoll := parent.GitCheckoutUploadGithubRollFunc(githubClient, cr.UserName(), rollerName)
parentRM, err := parent.NewDEPSLocal(ctx, parentCfg, reg, httpClient, serverURL, workdir, cr.UserName(), cr.UserEmail(), recipeCfgFile, uploadRoll)
if err != nil {
return nil, skerr.Wrap(err)
}
if err := parent.SetupGithub(ctx, parentRM, c.ForkRepoURL); err != nil {
return nil, skerr.Wrap(err)
}
childRM, err := child.NewCIPD(ctx, childCfg, httpClient, workdir)
if err != nil {
return nil, skerr.Wrap(err)
}
return newParentChildRepoManager(ctx, parentRM, childRM)
}