mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-27 20:31:10 +00:00
Merge pull request #1532 from frapposelli/tuneable-build-file
Add tuneable build file parameter
This commit is contained in:
commit
1d17c276fd
8 changed files with 89 additions and 94 deletions
|
@ -180,13 +180,19 @@ func PostBuild(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetch the .drone.yml file from the database
|
// fetch the .drone.yml file from the database
|
||||||
raw, sec, err := remote_.Script(user, repo, build)
|
raw, err := remote_.File(user, repo, build, droneYml)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("failure to get .drone.yml for %s. %s", repo.FullName, err)
|
log.Errorf("failure to get build config for %s. %s", repo.FullName, err)
|
||||||
c.AbortWithError(404, err)
|
c.AbortWithError(404, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fetch secrets file but don't exit on error as it's optional
|
||||||
|
sec, err := remote_.File(user, repo, build, droneSec)
|
||||||
|
if err != nil {
|
||||||
|
log.Debugf("cannot find build secrets for %s. %s", repo.FullName, err)
|
||||||
|
}
|
||||||
|
|
||||||
key, _ := store.GetKey(c, repo)
|
key, _ := store.GetKey(c, repo)
|
||||||
netrc, err := remote_.Netrc(user, repo)
|
netrc, err := remote_.Netrc(user, repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -21,6 +21,18 @@ import (
|
||||||
"github.com/drone/drone/yaml/matrix"
|
"github.com/drone/drone/yaml/matrix"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
droneYml = os.Getenv("BUILD_CONFIG_FILE")
|
||||||
|
droneSec string
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
if droneYml == "" {
|
||||||
|
droneYml = ".drone.yml"
|
||||||
|
}
|
||||||
|
droneSec = fmt.Sprintf("%s.sec", strings.TrimSuffix(droneYml, filepath.Ext(droneYml)))
|
||||||
|
}
|
||||||
|
|
||||||
var skipRe = regexp.MustCompile(`\[(?i:ci *skip|skip *ci)\]`)
|
var skipRe = regexp.MustCompile(`\[(?i:ci *skip|skip *ci)\]`)
|
||||||
|
|
||||||
func PostHook(c *gin.Context) {
|
func PostHook(c *gin.Context) {
|
||||||
|
@ -124,13 +136,18 @@ func PostHook(c *gin.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetch the .drone.yml file from the database
|
// fetch the build file from the database
|
||||||
raw, sec, err := remote_.Script(user, repo, build)
|
raw, err := remote_.File(user, repo, build, droneYml)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("failure to get .drone.yml for %s. %s", repo.FullName, err)
|
log.Errorf("failure to get build config for %s. %s", repo.FullName, err)
|
||||||
c.AbortWithError(404, err)
|
c.AbortWithError(404, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
sec, err := remote_.File(user, repo, build, droneSec)
|
||||||
|
if err != nil {
|
||||||
|
log.Debugf("cannot find build secrets for %s. %s", repo.FullName, err)
|
||||||
|
// NOTE we don't exit on failure. The sec file is optional
|
||||||
|
}
|
||||||
|
|
||||||
axes, err := matrix.Parse(string(raw))
|
axes, err := matrix.Parse(string(raw))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -237,9 +237,8 @@ func (bb *Bitbucket) Perm(u *model.User, owner, name string) (*model.Perm, error
|
||||||
return perms, nil
|
return perms, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Script fetches the build script (.drone.yml) from the remote
|
// File fetches a file from the remote repository and returns in string format.
|
||||||
// repository and returns in string format.
|
func (bb *Bitbucket) File(u *model.User, r *model.Repo, b *model.Build, f string) ([]byte, error) {
|
||||||
func (bb *Bitbucket) Script(u *model.User, r *model.Repo, b *model.Build) ([]byte, []byte, error) {
|
|
||||||
client := NewClientToken(
|
client := NewClientToken(
|
||||||
bb.Client,
|
bb.Client,
|
||||||
bb.Secret,
|
bb.Secret,
|
||||||
|
@ -249,19 +248,12 @@ func (bb *Bitbucket) Script(u *model.User, r *model.Repo, b *model.Build) ([]byt
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
// fetches the .drone.yml for the specified revision. This file
|
config, err := client.FindSource(r.Owner, r.Name, b.Commit, f)
|
||||||
// is required, and will error if not found
|
|
||||||
config, err := client.FindSource(r.Owner, r.Name, b.Commit, ".drone.yml")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetches the .drone.sec for the specified revision. This file
|
return []byte(config.Data), err
|
||||||
// is completely optional, therefore we will not return a not
|
|
||||||
// found error
|
|
||||||
sec, _ := client.FindSource(r.Owner, r.Name, b.Commit, ".drone.sec")
|
|
||||||
|
|
||||||
return []byte(config.Data), []byte(sec.Data), err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Status sends the commit status to the remote system.
|
// Status sends the commit status to the remote system.
|
||||||
|
@ -280,10 +272,10 @@ func (bb *Bitbucket) Status(u *model.User, r *model.Repo, b *model.Build, link s
|
||||||
desc := getDesc(b.Status)
|
desc := getDesc(b.Status)
|
||||||
|
|
||||||
data := BuildStatus{
|
data := BuildStatus{
|
||||||
State: status,
|
State: status,
|
||||||
Key: "Drone",
|
Key: "Drone",
|
||||||
Url: link,
|
Url: link,
|
||||||
Desc: desc,
|
Desc: desc,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := client.CreateStatus(r.Owner, r.Name, b.Commit, &data)
|
err := client.CreateStatus(r.Owner, r.Name, b.Commit, &data)
|
||||||
|
|
|
@ -225,14 +225,11 @@ func (g *Github) Perm(u *model.User, owner, name string) (*model.Perm, error) {
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Script fetches the build script (.drone.yml) from the remote
|
// File fetches a file from the remote repository and returns in string format.
|
||||||
// repository and returns in string format.
|
func (g *Github) File(u *model.User, r *model.Repo, b *model.Build, f string) ([]byte, error) {
|
||||||
func (g *Github) Script(u *model.User, r *model.Repo, b *model.Build) ([]byte, []byte, error) {
|
|
||||||
client := NewClient(g.API, u.Token, g.SkipVerify)
|
client := NewClient(g.API, u.Token, g.SkipVerify)
|
||||||
|
cfg, err := GetFile(client, r.Owner, r.Name, f, b.Commit)
|
||||||
cfg, err := GetFile(client, r.Owner, r.Name, ".drone.yml", b.Commit)
|
return cfg, err
|
||||||
sec, _ := GetFile(client, r.Owner, r.Name, ".drone.sec", b.Commit)
|
|
||||||
return cfg, sec, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Status sends the commit status to the remote system.
|
// Status sends the commit status to the remote system.
|
||||||
|
|
|
@ -23,16 +23,16 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Gitlab struct {
|
type Gitlab struct {
|
||||||
URL string
|
URL string
|
||||||
Client string
|
Client string
|
||||||
Secret string
|
Secret string
|
||||||
AllowedOrgs []string
|
AllowedOrgs []string
|
||||||
CloneMode string
|
CloneMode string
|
||||||
Open bool
|
Open bool
|
||||||
PrivateMode bool
|
PrivateMode bool
|
||||||
SkipVerify bool
|
SkipVerify bool
|
||||||
HideArchives bool
|
HideArchives bool
|
||||||
Search bool
|
Search bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func Load(env envconfig.Env) *Gitlab {
|
func Load(env envconfig.Env) *Gitlab {
|
||||||
|
@ -247,24 +247,19 @@ func (g *Gitlab) Perm(u *model.User, owner, name string) (*model.Perm, error) {
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetScript fetches the build script (.drone.yml) from the remote
|
// File fetches a file from the remote repository and returns in string format.
|
||||||
// repository and returns in string format.
|
func (g *Gitlab) File(user *model.User, repo *model.Repo, build *model.Build, f string) ([]byte, error) {
|
||||||
func (g *Gitlab) Script(user *model.User, repo *model.Repo, build *model.Build) ([]byte, []byte, error) {
|
|
||||||
var client = NewClient(g.URL, user.Token, g.SkipVerify)
|
var client = NewClient(g.URL, user.Token, g.SkipVerify)
|
||||||
id, err := GetProjectId(g, client, repo.Owner, repo.Name)
|
id, err := GetProjectId(g, client, repo.Owner, repo.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
out1, err := client.RepoRawFile(id, build.Commit, ".drone.yml")
|
out, err := client.RepoRawFile(id, build.Commit, f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
out2, err := client.RepoRawFile(id, build.Commit, ".drone.sec")
|
return out, err
|
||||||
if err != nil {
|
|
||||||
return out1, nil, nil
|
|
||||||
}
|
|
||||||
return out1, out2, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE Currently gitlab doesn't support status for commits and events,
|
// NOTE Currently gitlab doesn't support status for commits and events,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package gogs
|
package gogs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -59,7 +59,7 @@ func (g *Gogs) Login(res http.ResponseWriter, req *http.Request) (*model.User, b
|
||||||
return nil, false, nil
|
return nil, false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
client := NewGogsClient(g.URL, "", g.SkipVerify)
|
client := NewGogsClient(g.URL, "", g.SkipVerify)
|
||||||
|
|
||||||
// try to fetch drone token if it exists
|
// try to fetch drone token if it exists
|
||||||
var accessToken string
|
var accessToken string
|
||||||
|
@ -83,7 +83,7 @@ func (g *Gogs) Login(res http.ResponseWriter, req *http.Request) (*model.User, b
|
||||||
accessToken = token.Sha1
|
accessToken = token.Sha1
|
||||||
}
|
}
|
||||||
|
|
||||||
client = NewGogsClient(g.URL, accessToken, g.SkipVerify)
|
client = NewGogsClient(g.URL, accessToken, g.SkipVerify)
|
||||||
userInfo, err := client.GetUserInfo(username)
|
userInfo, err := client.GetUserInfo(username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
|
@ -158,13 +158,11 @@ func (g *Gogs) Perm(u *model.User, owner, name string) (*model.Perm, error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Script fetches the build script (.drone.yml) from the remote
|
// File fetches a file from the remote repository and returns in string format.
|
||||||
// repository and returns in string format.
|
func (g *Gogs) File(u *model.User, r *model.Repo, b *model.Build, f string) ([]byte, error) {
|
||||||
func (g *Gogs) Script(u *model.User, r *model.Repo, b *model.Build) ([]byte, []byte, error) {
|
|
||||||
client := NewGogsClient(g.URL, u.Token, g.SkipVerify)
|
client := NewGogsClient(g.URL, u.Token, g.SkipVerify)
|
||||||
cfg, err := client.GetFile(r.Owner, r.Name, b.Commit, ".drone.yml")
|
cfg, err := client.GetFile(r.Owner, r.Name, b.Commit, f)
|
||||||
sec, _ := client.GetFile(r.Owner, r.Name, b.Commit, ".drone.sec")
|
return cfg, err
|
||||||
return cfg, sec, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Status sends the commit status to the remote system.
|
// Status sends the commit status to the remote system.
|
||||||
|
@ -182,7 +180,7 @@ func (g *Gogs) Netrc(u *model.User, r *model.Repo) (*model.Netrc, error) {
|
||||||
}
|
}
|
||||||
host, _, err := net.SplitHostPort(url_.Host)
|
host, _, err := net.SplitHostPort(url_.Host)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
url_.Host=host
|
url_.Host = host
|
||||||
}
|
}
|
||||||
return &model.Netrc{
|
return &model.Netrc{
|
||||||
Login: u.Token,
|
Login: u.Token,
|
||||||
|
@ -239,16 +237,16 @@ func (g *Gogs) Hook(r *http.Request) (*model.Repo, *model.Build, error) {
|
||||||
|
|
||||||
// NewClient initializes and returns a API client.
|
// NewClient initializes and returns a API client.
|
||||||
func NewGogsClient(url, token string, skipVerify bool) *gogs.Client {
|
func NewGogsClient(url, token string, skipVerify bool) *gogs.Client {
|
||||||
sslClient := &http.Client{}
|
sslClient := &http.Client{}
|
||||||
c := gogs.NewClient(url, token)
|
c := gogs.NewClient(url, token)
|
||||||
|
|
||||||
if skipVerify {
|
if skipVerify {
|
||||||
sslClient.Transport = &http.Transport{
|
sslClient.Transport = &http.Transport{
|
||||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||||
}
|
}
|
||||||
c.SetHTTPClient(sslClient)
|
c.SetHTTPClient(sslClient)
|
||||||
}
|
}
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Gogs) String() string {
|
func (g *Gogs) String() string {
|
||||||
|
|
|
@ -119,35 +119,26 @@ func (_m *Remote) Perm(u *model.User, owner string, repo string) (*model.Perm, e
|
||||||
|
|
||||||
return r0, r1
|
return r0, r1
|
||||||
}
|
}
|
||||||
func (_m *Remote) Script(u *model.User, r *model.Repo, b *model.Build) ([]byte, []byte, error) {
|
func (_m *Remote) File(u *model.User, r *model.Repo, b *model.Build, f string) ([]byte, error) {
|
||||||
ret := _m.Called(u, r, b)
|
ret := _m.Called(u, r, b, f)
|
||||||
|
|
||||||
var r0 []byte
|
var r0 []byte
|
||||||
if rf, ok := ret.Get(0).(func(*model.User, *model.Repo, *model.Build) []byte); ok {
|
if rf, ok := ret.Get(0).(func(*model.User, *model.Repo, *model.Build, string) []byte); ok {
|
||||||
r0 = rf(u, r, b)
|
r0 = rf(u, r, b, f)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).([]byte)
|
r0 = ret.Get(0).([]byte)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var r1 []byte
|
var r1 error
|
||||||
if rf, ok := ret.Get(1).(func(*model.User, *model.Repo, *model.Build) []byte); ok {
|
if rf, ok := ret.Get(1).(func(*model.User, *model.Repo, *model.Build, string) error); ok {
|
||||||
r1 = rf(u, r, b)
|
r1 = rf(u, r, b, f)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(1) != nil {
|
r1 = ret.Error(1)
|
||||||
r1 = ret.Get(1).([]byte)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var r2 error
|
return r0, r1
|
||||||
if rf, ok := ret.Get(2).(func(*model.User, *model.Repo, *model.Build) error); ok {
|
|
||||||
r2 = rf(u, r, b)
|
|
||||||
} else {
|
|
||||||
r2 = ret.Error(2)
|
|
||||||
}
|
|
||||||
|
|
||||||
return r0, r1, r2
|
|
||||||
}
|
}
|
||||||
func (_m *Remote) Status(u *model.User, r *model.Repo, b *model.Build, link string) error {
|
func (_m *Remote) Status(u *model.User, r *model.Repo, b *model.Build, link string) error {
|
||||||
ret := _m.Called(u, r, b, link)
|
ret := _m.Called(u, r, b, link)
|
||||||
|
|
|
@ -55,9 +55,9 @@ type Remote interface {
|
||||||
// the remote system for the specified user.
|
// the remote system for the specified user.
|
||||||
Perm(u *model.User, owner, repo string) (*model.Perm, error)
|
Perm(u *model.User, owner, repo string) (*model.Perm, error)
|
||||||
|
|
||||||
// Script fetches the build script (.drone.yml) from the remote
|
// File fetches a file from the remote repository and returns in string
|
||||||
// repository and returns in string format.
|
// format.
|
||||||
Script(u *model.User, r *model.Repo, b *model.Build) ([]byte, []byte, error)
|
File(u *model.User, r *model.Repo, b *model.Build, f string) ([]byte, error)
|
||||||
|
|
||||||
// Status sends the commit status to the remote system.
|
// Status sends the commit status to the remote system.
|
||||||
// An example would be the GitHub pull request status.
|
// An example would be the GitHub pull request status.
|
||||||
|
@ -115,10 +115,9 @@ func Perm(c context.Context, u *model.User, owner, repo string) (*model.Perm, er
|
||||||
return FromContext(c).Perm(u, owner, repo)
|
return FromContext(c).Perm(u, owner, repo)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Script fetches the build script (.drone.yml) from the remote
|
// File fetches a file from the remote repository and returns in string format.
|
||||||
// repository and returns in string format.
|
func File(c context.Context, u *model.User, r *model.Repo, b *model.Build, f string) ([]byte, error) {
|
||||||
func Script(c context.Context, u *model.User, r *model.Repo, b *model.Build) ([]byte, []byte, error) {
|
return FromContext(c).File(u, r, b, f)
|
||||||
return FromContext(c).Script(u, r, b)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Status sends the commit status to the remote system.
|
// Status sends the commit status to the remote system.
|
||||||
|
|
Loading…
Reference in a new issue