feat(ci): check if running on a ci, else skip release

This commit is contained in:
Nightapes
2019-07-15 21:20:44 +02:00
parent e3b54c63b0
commit 13afcea8a0
5 changed files with 169 additions and 35 deletions

44
internal/ci/ci.go Normal file
View File

@@ -0,0 +1,44 @@
package ci
import (
"fmt"
"github.com/Nightapes/go-semantic-release/internal/gitutil"
log "github.com/sirupsen/logrus"
)
//ProviderConfig struct
type ProviderConfig struct {
IsPR bool
PR string
PRBranch string
Branch string
Tag string
Commit string
BuildURL string
Service string
Name string
}
//Service interface
type Service interface {
Detect() (*ProviderConfig, error)
}
//GetCIProvider get provider
func GetCIProvider(gitUtil *gitutil.GitUtil) (*ProviderConfig, error) {
services := []Service{
Travis{},
Git{gitUtil: gitUtil}, // GIt must be the last option to check
}
for _, service := range services {
config, err := service.Detect()
if err == nil {
log.Infof("Found CI: %s", config.Name)
return config, nil
}
log.Debugf("%s", err.Error())
}
return nil, fmt.Errorf("could not find any CI, if running locally set env CI=true")
}