39 lines
763 B
Go
39 lines
763 B
Go
package git
|
|
|
|
import (
|
|
"path"
|
|
|
|
configPkg "coopcloud.tech/abra/pkg/config"
|
|
"github.com/go-git/go-git/v5"
|
|
"github.com/go-git/go-git/v5/config"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// Push pushes the latest changes
|
|
func Push(recipeName string, tags bool) error {
|
|
recipeDir := path.Join(configPkg.RECIPES_DIR, recipeName)
|
|
commitRepo, err := git.PlainOpen(recipeDir)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := commitRepo.Push(&git.PushOptions{}); err != nil {
|
|
return err
|
|
}
|
|
logrus.Info("git changes pushed")
|
|
|
|
if tags {
|
|
pushOpts := &git.PushOptions{
|
|
RefSpecs: []config.RefSpec{
|
|
config.RefSpec("+refs/tags/*:refs/tags/*"),
|
|
},
|
|
}
|
|
if err := commitRepo.Push(pushOpts); err != nil {
|
|
return err
|
|
}
|
|
logrus.Info("git tags pushed")
|
|
}
|
|
|
|
return nil
|
|
}
|