in cmd/publishing-bot/publisher.go [372:416]
func (p *PublisherMunger) publish(newUpstreamHeads map[string]plumbing.Hash) error {
if p.config.DryRun {
p.plog.Infof("Skipping push in dry-run mode")
return nil
}
if p.config.TokenFile == "" {
return fmt.Errorf("token cannot be empty in non-dry-run mode")
}
// NOTE: because some repos depend on each other, e.g., client-go depends on
// apimachinery, they should be published atomically, but it's not supported
// by github.
for _, repoRules := range p.reposRules.Rules {
if repoRules.Skip {
continue
}
dstDir := filepath.Join(p.baseRepoPath, repoRules.DestinationRepository, "")
if err := os.Chdir(dstDir); err != nil {
return err
}
p.plog.Infof("Pushing branches for %s", repoRules.DestinationRepository)
for _, branchRule := range repoRules.Branches {
if p.skippedBranch(branchRule.Source.Branch) {
continue
}
cmd := exec.Command(p.config.BasePublishScriptPath+"/push.sh", p.config.TokenFile, branchRule.Name)
if err := p.plog.Run(cmd); err != nil {
return err
}
upstreamBranchHead, ok := newUpstreamHeads[branchRule.Source.Branch]
if !ok {
return fmt.Errorf("no upstream branch %q found", branchRule.Source.Branch)
}
if err := ioutil.WriteFile(path.Join(path.Dir(dstDir), publishedFileName(repoRules.DestinationRepository, branchRule.Name)), []byte(upstreamBranchHead.String()), 0644); err != nil {
return err
}
}
}
return nil
}