save drone.yml on the build
This commit is contained in:
parent
5886e0fec1
commit
913332d965
10 changed files with 67 additions and 95 deletions
|
@ -10,7 +10,7 @@ const buildTable = "builds"
|
||||||
|
|
||||||
// SQL Queries to retrieve a list of all Commits belonging to a Repo.
|
// SQL Queries to retrieve a list of all Commits belonging to a Repo.
|
||||||
const buildStmt = `
|
const buildStmt = `
|
||||||
SELECT id, commit_id, slug, status, started, finished, duration, created, updated, stdout
|
SELECT id, commit_id, slug, status, started, finished, duration, created, updated, stdout, buildscript
|
||||||
FROM builds
|
FROM builds
|
||||||
WHERE commit_id = ?
|
WHERE commit_id = ?
|
||||||
ORDER BY slug ASC
|
ORDER BY slug ASC
|
||||||
|
@ -18,7 +18,7 @@ ORDER BY slug ASC
|
||||||
|
|
||||||
// SQL Queries to retrieve a Build by id.
|
// SQL Queries to retrieve a Build by id.
|
||||||
const buildFindStmt = `
|
const buildFindStmt = `
|
||||||
SELECT id, commit_id, slug, status, started, finished, duration, created, updated, stdout
|
SELECT id, commit_id, slug, status, started, finished, duration, created, updated, stdout, buildscript
|
||||||
FROM builds
|
FROM builds
|
||||||
WHERE id = ?
|
WHERE id = ?
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
|
@ -26,7 +26,7 @@ LIMIT 1
|
||||||
|
|
||||||
// SQL Queries to retrieve a Commit by name and repo id.
|
// SQL Queries to retrieve a Commit by name and repo id.
|
||||||
const buildFindSlugStmt = `
|
const buildFindSlugStmt = `
|
||||||
SELECT id, commit_id, slug, status, started, finished, duration, created, updated, stdout
|
SELECT id, commit_id, slug, status, started, finished, duration, created, updated, stdout, buildscript
|
||||||
FROM builds
|
FROM builds
|
||||||
WHERE slug = ? AND commit_id = ?
|
WHERE slug = ? AND commit_id = ?
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
|
|
19
pkg/database/migrate/20140522205400_save_drone_yml.go
Normal file
19
pkg/database/migrate/20140522205400_save_drone_yml.go
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
package migrate
|
||||||
|
|
||||||
|
type rev20140522205400 struct{}
|
||||||
|
|
||||||
|
var SaveDroneYml = &rev20140522205400{}
|
||||||
|
|
||||||
|
func (r *rev20140522205400) Revision() int64 {
|
||||||
|
return 20140522205400
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *rev20140522205400) Up(mg *MigrationDriver) error {
|
||||||
|
_, err := mg.AddColumn("builds", "buildscript TEXT")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *rev20140522205400) Down(mg *MigrationDriver) error {
|
||||||
|
_, err := mg.DropColumns("builds", "buildscript")
|
||||||
|
return err
|
||||||
|
}
|
|
@ -13,6 +13,7 @@ func (m *Migration) All() *Migration {
|
||||||
m.Add(GitHubEnterpriseSupport)
|
m.Add(GitHubEnterpriseSupport)
|
||||||
m.Add(AddOpenInvitationColumn)
|
m.Add(AddOpenInvitationColumn)
|
||||||
m.Add(AddGitlabColumns)
|
m.Add(AddGitlabColumns)
|
||||||
|
m.Add(SaveDroneYml)
|
||||||
|
|
||||||
// m.Add(...)
|
// m.Add(...)
|
||||||
// ...
|
// ...
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/drone/drone/pkg/build/script"
|
|
||||||
"github.com/drone/drone/pkg/database"
|
"github.com/drone/drone/pkg/database"
|
||||||
. "github.com/drone/drone/pkg/model"
|
. "github.com/drone/drone/pkg/model"
|
||||||
"github.com/drone/drone/pkg/queue"
|
"github.com/drone/drone/pkg/queue"
|
||||||
|
@ -83,16 +82,6 @@ func (h *BitbucketHandler) Hook(w http.ResponseWriter, r *http.Request) error {
|
||||||
return RenderText(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
return RenderText(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse the build script
|
|
||||||
buildscript, err := script.ParseBuild([]byte(raw.Data), repo.Params)
|
|
||||||
if err != nil {
|
|
||||||
msg := "Could not parse your .drone.yml file. It needs to be a valid drone yaml file.\n\n" + err.Error() + "\n"
|
|
||||||
if err := saveFailedBuild(commit, msg); err != nil {
|
|
||||||
return RenderText(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
return RenderText(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
|
||||||
}
|
|
||||||
|
|
||||||
// save the commit to the database
|
// save the commit to the database
|
||||||
if err := database.SaveCommit(commit); err != nil {
|
if err := database.SaveCommit(commit); err != nil {
|
||||||
return RenderText(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
return RenderText(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
|
@ -104,12 +93,13 @@ func (h *BitbucketHandler) Hook(w http.ResponseWriter, r *http.Request) error {
|
||||||
build.CommitID = commit.ID
|
build.CommitID = commit.ID
|
||||||
build.Created = time.Now().UTC()
|
build.Created = time.Now().UTC()
|
||||||
build.Status = "Pending"
|
build.Status = "Pending"
|
||||||
|
build.BuildScript = raw.Data
|
||||||
if err := database.SaveBuild(build); err != nil {
|
if err := database.SaveBuild(build); err != nil {
|
||||||
return RenderText(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
return RenderText(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
// send the build to the queue
|
// send the build to the queue
|
||||||
h.queue.Add(&queue.BuildTask{Repo: repo, Commit: commit, Build: build, Script: buildscript})
|
h.queue.Add(&queue.BuildTask{Repo: repo, Commit: commit, Build: build})
|
||||||
|
|
||||||
// OK!
|
// OK!
|
||||||
return RenderText(w, http.StatusText(http.StatusOK), http.StatusOK)
|
return RenderText(w, http.StatusText(http.StatusOK), http.StatusOK)
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/drone/drone/pkg/build/script"
|
|
||||||
"github.com/drone/drone/pkg/database"
|
"github.com/drone/drone/pkg/database"
|
||||||
. "github.com/drone/drone/pkg/model"
|
. "github.com/drone/drone/pkg/model"
|
||||||
"github.com/drone/drone/pkg/queue"
|
"github.com/drone/drone/pkg/queue"
|
||||||
|
@ -131,22 +130,8 @@ func (h *GithubHandler) Hook(w http.ResponseWriter, r *http.Request) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// decode the content. Note: Not sure this will ever happen...it basically means a GitHub API issue
|
// decode the content. Note: Not sure this will ever happen...it basically means a GitHub API issue
|
||||||
raw, err := content.DecodeContent()
|
buildscript, err := content.DecodeContent()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := "Could not decode the yaml from GitHub. Check that your .drone.yml is a valid yaml file.\n"
|
|
||||||
if err := saveFailedBuild(commit, msg); err != nil {
|
|
||||||
return RenderText(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
return RenderText(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse the build script
|
|
||||||
buildscript, err := script.ParseBuild(raw, repo.Params)
|
|
||||||
if err != nil {
|
|
||||||
msg := "Could not parse your .drone.yml file. It needs to be a valid drone yaml file.\n\n" + err.Error() + "\n"
|
|
||||||
if err := saveFailedBuild(commit, msg); err != nil {
|
|
||||||
return RenderText(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
return RenderText(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
return RenderText(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,6 +146,7 @@ func (h *GithubHandler) Hook(w http.ResponseWriter, r *http.Request) error {
|
||||||
build.CommitID = commit.ID
|
build.CommitID = commit.ID
|
||||||
build.Created = time.Now().UTC()
|
build.Created = time.Now().UTC()
|
||||||
build.Status = "Pending"
|
build.Status = "Pending"
|
||||||
|
build.BuildScript = string(buildscript)
|
||||||
if err := database.SaveBuild(build); err != nil {
|
if err := database.SaveBuild(build); err != nil {
|
||||||
return RenderText(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
return RenderText(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
@ -169,7 +155,7 @@ func (h *GithubHandler) Hook(w http.ResponseWriter, r *http.Request) error {
|
||||||
//realtime.CommitPending(repo.UserID, repo.TeamID, repo.ID, commit.ID, repo.Private)
|
//realtime.CommitPending(repo.UserID, repo.TeamID, repo.ID, commit.ID, repo.Private)
|
||||||
//realtime.BuildPending(repo.UserID, repo.TeamID, repo.ID, commit.ID, build.ID, repo.Private)
|
//realtime.BuildPending(repo.UserID, repo.TeamID, repo.ID, commit.ID, build.ID, repo.Private)
|
||||||
|
|
||||||
h.queue.Add(&queue.BuildTask{Repo: repo, Commit: commit, Build: build, Script: buildscript}) //Push(repo, commit, build, buildscript)
|
h.queue.Add(&queue.BuildTask{Repo: repo, Commit: commit, Build: build}) //Push(repo, commit, build)
|
||||||
|
|
||||||
// OK!
|
// OK!
|
||||||
return RenderText(w, http.StatusText(http.StatusOK), http.StatusOK)
|
return RenderText(w, http.StatusText(http.StatusOK), http.StatusOK)
|
||||||
|
@ -250,22 +236,12 @@ func (h *GithubHandler) PullRequestHook(w http.ResponseWriter, r *http.Request)
|
||||||
}
|
}
|
||||||
|
|
||||||
// decode the content
|
// decode the content
|
||||||
raw, err := content.DecodeContent()
|
buildscript, err := content.DecodeContent()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
RenderText(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
RenderText(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse the build script
|
|
||||||
buildscript, err := script.ParseBuild(raw, repo.Params)
|
|
||||||
if err != nil {
|
|
||||||
// TODO if the YAML is invalid we should create a commit record
|
|
||||||
// with an ERROR status so that the user knows why a build wasn't
|
|
||||||
// triggered in the system
|
|
||||||
RenderText(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// save the commit to the database
|
// save the commit to the database
|
||||||
if err := database.SaveCommit(commit); err != nil {
|
if err := database.SaveCommit(commit); err != nil {
|
||||||
RenderText(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
RenderText(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
|
@ -278,6 +254,7 @@ func (h *GithubHandler) PullRequestHook(w http.ResponseWriter, r *http.Request)
|
||||||
build.CommitID = commit.ID
|
build.CommitID = commit.ID
|
||||||
build.Created = time.Now().UTC()
|
build.Created = time.Now().UTC()
|
||||||
build.Status = "Pending"
|
build.Status = "Pending"
|
||||||
|
build.BuildScript = string(buildscript)
|
||||||
if err := database.SaveBuild(build); err != nil {
|
if err := database.SaveBuild(build); err != nil {
|
||||||
RenderText(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
RenderText(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
@ -285,7 +262,7 @@ func (h *GithubHandler) PullRequestHook(w http.ResponseWriter, r *http.Request)
|
||||||
|
|
||||||
// notify websocket that a new build is pending
|
// notify websocket that a new build is pending
|
||||||
// TODO we should, for consistency, just put this inside Queue.Add()
|
// TODO we should, for consistency, just put this inside Queue.Add()
|
||||||
h.queue.Add(&queue.BuildTask{Repo: repo, Commit: commit, Build: build, Script: buildscript})
|
h.queue.Add(&queue.BuildTask{Repo: repo, Commit: commit, Build: build})
|
||||||
|
|
||||||
// OK!
|
// OK!
|
||||||
RenderText(w, http.StatusText(http.StatusOK), http.StatusOK)
|
RenderText(w, http.StatusText(http.StatusOK), http.StatusOK)
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/drone/drone/pkg/build/script"
|
|
||||||
"github.com/drone/drone/pkg/database"
|
"github.com/drone/drone/pkg/database"
|
||||||
. "github.com/drone/drone/pkg/model"
|
. "github.com/drone/drone/pkg/model"
|
||||||
"github.com/drone/drone/pkg/queue"
|
"github.com/drone/drone/pkg/queue"
|
||||||
|
@ -207,7 +206,7 @@ func (g *GitlabHandler) Hook(w http.ResponseWriter, r *http.Request) error {
|
||||||
// get the drone.yml file from GitHub
|
// get the drone.yml file from GitHub
|
||||||
client := gogitlab.NewGitlab(settings.GitlabApiUrl, g.apiPath, user.GitlabToken)
|
client := gogitlab.NewGitlab(settings.GitlabApiUrl, g.apiPath, user.GitlabToken)
|
||||||
|
|
||||||
content, err := client.RepoRawFile(ns(repo.Owner, repo.Name), commit.Hash, ".drone.yml")
|
buildscript, err := client.RepoRawFile(ns(repo.Owner, repo.Name), commit.Hash, ".drone.yml")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := "No .drone.yml was found in this repository. You need to add one.\n"
|
msg := "No .drone.yml was found in this repository. You need to add one.\n"
|
||||||
if err := saveFailedBuild(commit, msg); err != nil {
|
if err := saveFailedBuild(commit, msg); err != nil {
|
||||||
|
@ -216,16 +215,6 @@ func (g *GitlabHandler) Hook(w http.ResponseWriter, r *http.Request) error {
|
||||||
return RenderText(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
return RenderText(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse the build script
|
|
||||||
buildscript, err := script.ParseBuild(content, repo.Params)
|
|
||||||
if err != nil {
|
|
||||||
msg := "Could not parse your .drone.yml file. It needs to be a valid drone yaml file.\n\n" + err.Error() + "\n"
|
|
||||||
if err := saveFailedBuild(commit, msg); err != nil {
|
|
||||||
return RenderText(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
return RenderText(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
|
||||||
}
|
|
||||||
|
|
||||||
// save the commit to the database
|
// save the commit to the database
|
||||||
if err := database.SaveCommit(commit); err != nil {
|
if err := database.SaveCommit(commit); err != nil {
|
||||||
return RenderText(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
return RenderText(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
|
@ -237,11 +226,12 @@ func (g *GitlabHandler) Hook(w http.ResponseWriter, r *http.Request) error {
|
||||||
build.CommitID = commit.ID
|
build.CommitID = commit.ID
|
||||||
build.Created = time.Now().UTC()
|
build.Created = time.Now().UTC()
|
||||||
build.Status = "Pending"
|
build.Status = "Pending"
|
||||||
|
build.BuildScript = string(buildscript)
|
||||||
if err := database.SaveBuild(build); err != nil {
|
if err := database.SaveBuild(build); err != nil {
|
||||||
return RenderText(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
return RenderText(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
g.queue.Add(&queue.BuildTask{Repo: repo, Commit: commit, Build: build, Script: buildscript})
|
g.queue.Add(&queue.BuildTask{Repo: repo, Commit: commit, Build: build})
|
||||||
|
|
||||||
// OK!
|
// OK!
|
||||||
return RenderText(w, http.StatusText(http.StatusOK), http.StatusOK)
|
return RenderText(w, http.StatusText(http.StatusOK), http.StatusOK)
|
||||||
|
@ -287,7 +277,7 @@ func (g *GitlabHandler) PullRequestHook(p *gogitlab.HookPayload, repo *Repo, use
|
||||||
commit.Timestamp = src.Commit.AuthoredDateRaw
|
commit.Timestamp = src.Commit.AuthoredDateRaw
|
||||||
commit.SetAuthor(src.Commit.Author.Email)
|
commit.SetAuthor(src.Commit.Author.Email)
|
||||||
|
|
||||||
content, err := client.RepoRawFile(strconv.Itoa(obj.SourceProjectId), commit.Hash, ".drone.yml")
|
buildscript, err := client.RepoRawFile(strconv.Itoa(obj.SourceProjectId), commit.Hash, ".drone.yml")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := "No .drone.yml was found in this repository. You need to add one.\n"
|
msg := "No .drone.yml was found in this repository. You need to add one.\n"
|
||||||
if err := saveFailedBuild(commit, msg); err != nil {
|
if err := saveFailedBuild(commit, msg); err != nil {
|
||||||
|
@ -296,16 +286,6 @@ func (g *GitlabHandler) PullRequestHook(p *gogitlab.HookPayload, repo *Repo, use
|
||||||
return fmt.Errorf("Error to fetch build script: %q", err)
|
return fmt.Errorf("Error to fetch build script: %q", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse the build script
|
|
||||||
buildscript, err := script.ParseBuild(content, repo.Params)
|
|
||||||
if err != nil {
|
|
||||||
msg := "Could not parse your .drone.yml file. It needs to be a valid drone yaml file.\n\n" + err.Error() + "\n"
|
|
||||||
if err := saveFailedBuild(commit, msg); err != nil {
|
|
||||||
return fmt.Errorf("Failed to save build: %q", err)
|
|
||||||
}
|
|
||||||
return fmt.Errorf("Failed to parse build script: %q", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// save the commit to the database
|
// save the commit to the database
|
||||||
if err := database.SaveCommit(commit); err != nil {
|
if err := database.SaveCommit(commit); err != nil {
|
||||||
return fmt.Errorf("Failed to save commit: %q", err)
|
return fmt.Errorf("Failed to save commit: %q", err)
|
||||||
|
@ -317,11 +297,12 @@ func (g *GitlabHandler) PullRequestHook(p *gogitlab.HookPayload, repo *Repo, use
|
||||||
build.CommitID = commit.ID
|
build.CommitID = commit.ID
|
||||||
build.Created = time.Now().UTC()
|
build.Created = time.Now().UTC()
|
||||||
build.Status = "Pending"
|
build.Status = "Pending"
|
||||||
|
build.BuildScript = string(buildscript)
|
||||||
if err := database.SaveBuild(build); err != nil {
|
if err := database.SaveBuild(build); err != nil {
|
||||||
return fmt.Errorf("Failed to save build: %q", err)
|
return fmt.Errorf("Failed to save build: %q", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
g.queue.Add(&queue.BuildTask{Repo: repo, Commit: commit, Build: build, Script: buildscript})
|
g.queue.Add(&queue.BuildTask{Repo: repo, Commit: commit, Build: build})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ func TestRepoHandler(t *testing.T) {
|
||||||
So(rec.Code, ShouldEqual, 303)
|
So(rec.Code, ShouldEqual, 303)
|
||||||
})
|
})
|
||||||
Convey("Private repo can not be viewed by a non team member", func() {
|
Convey("Private repo can not be viewed by a non team member", func() {
|
||||||
req, err := http.NewRequest("GET", "/github.com/drone/drone", nil)
|
req, err := http.NewRequest("GET", "/github.com/drone/drone", nil)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
setUserSession(rec, req, "rick@el.to.ro")
|
setUserSession(rec, req, "rick@el.to.ro")
|
||||||
|
@ -61,7 +61,7 @@ func dummyUserRepo(w http.ResponseWriter, r *http.Request, u *User, repo *Repo)
|
||||||
|
|
||||||
func setUserSession(w http.ResponseWriter, r *http.Request, username string) {
|
func setUserSession(w http.ResponseWriter, r *http.Request, username string) {
|
||||||
handler.SetCookie(w, r, "_sess", username)
|
handler.SetCookie(w, r, "_sess", username)
|
||||||
resp := http.Response{Header: w.Header()}
|
resp := http.Response{Header: w.Header()}
|
||||||
for _, v := range resp.Cookies() {
|
for _, v := range resp.Cookies() {
|
||||||
r.AddCookie(v)
|
r.AddCookie(v)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,16 +15,17 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Build struct {
|
type Build struct {
|
||||||
ID int64 `meddler:"id,pk" json:"id"`
|
ID int64 `meddler:"id,pk" json:"id"`
|
||||||
CommitID int64 `meddler:"commit_id" json:"-"`
|
CommitID int64 `meddler:"commit_id" json:"-"`
|
||||||
Slug string `meddler:"slug" json:"slug"`
|
Slug string `meddler:"slug" json:"slug"`
|
||||||
Status string `meddler:"status" json:"status"`
|
Status string `meddler:"status" json:"status"`
|
||||||
Started time.Time `meddler:"started,utctime" json:"started"`
|
Started time.Time `meddler:"started,utctime" json:"started"`
|
||||||
Finished time.Time `meddler:"finished,utctime" json:"finished"`
|
Finished time.Time `meddler:"finished,utctime" json:"finished"`
|
||||||
Duration int64 `meddler:"duration" json:"duration"`
|
Duration int64 `meddler:"duration" json:"duration"`
|
||||||
Created time.Time `meddler:"created,utctime" json:"created"`
|
Created time.Time `meddler:"created,utctime" json:"created"`
|
||||||
Updated time.Time `meddler:"updated,utctime" json:"updated"`
|
Updated time.Time `meddler:"updated,utctime" json:"updated"`
|
||||||
Stdout string `meddler:"stdout" json:"-"`
|
Stdout string `meddler:"stdout" json:"-"`
|
||||||
|
BuildScript string `meddler:"buildscript" json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// HumanDuration returns a human-readable approximation of a duration
|
// HumanDuration returns a human-readable approximation of a duration
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package queue
|
package queue
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/drone/drone/pkg/build/script"
|
|
||||||
. "github.com/drone/drone/pkg/model"
|
. "github.com/drone/drone/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -16,10 +15,6 @@ type BuildTask struct {
|
||||||
Repo *Repo
|
Repo *Repo
|
||||||
Commit *Commit
|
Commit *Commit
|
||||||
Build *Build
|
Build *Build
|
||||||
|
|
||||||
// Build instructions from the .drone.yml
|
|
||||||
// file, unmarshalled.
|
|
||||||
Script *script.Build
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start N workers with the given build runner.
|
// Start N workers with the given build runner.
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/drone/drone/pkg/build/git"
|
"github.com/drone/drone/pkg/build/git"
|
||||||
r "github.com/drone/drone/pkg/build/repo"
|
r "github.com/drone/drone/pkg/build/repo"
|
||||||
|
"github.com/drone/drone/pkg/build/script"
|
||||||
"github.com/drone/drone/pkg/channel"
|
"github.com/drone/drone/pkg/channel"
|
||||||
"github.com/drone/drone/pkg/database"
|
"github.com/drone/drone/pkg/database"
|
||||||
. "github.com/drone/drone/pkg/model"
|
. "github.com/drone/drone/pkg/model"
|
||||||
|
@ -83,9 +84,16 @@ func (w *worker) execute(task *BuildTask) error {
|
||||||
Host: settings.URL().String(),
|
Host: settings.URL().String(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// parse the build script
|
||||||
|
buildscript, err := script.ParseBuild([]byte(task.Build.BuildScript), task.Repo.Params)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Could not parse your .drone.yml file. It needs to be a valid drone yaml file.\n\n" + err.Error() + "\n")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// send all "started" notifications
|
// send all "started" notifications
|
||||||
if task.Script.Notifications != nil {
|
if buildscript.Notifications != nil {
|
||||||
task.Script.Notifications.Send(context)
|
buildscript.Notifications.Send(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send "started" notification to Github
|
// Send "started" notification to Github
|
||||||
|
@ -113,7 +121,7 @@ func (w *worker) execute(task *BuildTask) error {
|
||||||
// this is not a pull request (for security purposes)
|
// this is not a pull request (for security purposes)
|
||||||
if task.Repo.Params != nil && len(task.Commit.PullRequest) == 0 {
|
if task.Repo.Params != nil && len(task.Commit.PullRequest) == 0 {
|
||||||
for k, v := range task.Repo.Params {
|
for k, v := range task.Repo.Params {
|
||||||
task.Script.Env = append(task.Script.Env, k+"="+v)
|
buildscript.Env = append(buildscript.Env, k+"="+v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +134,7 @@ func (w *worker) execute(task *BuildTask) error {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// execute the build
|
// execute the build
|
||||||
passed, buildErr := w.runBuild(task, buf)
|
passed, buildErr := w.runBuild(task, buildscript, buf)
|
||||||
|
|
||||||
task.Build.Finished = time.Now().UTC()
|
task.Build.Finished = time.Now().UTC()
|
||||||
task.Commit.Finished = time.Now().UTC()
|
task.Commit.Finished = time.Now().UTC()
|
||||||
|
@ -162,14 +170,14 @@ func (w *worker) execute(task *BuildTask) error {
|
||||||
channel.Close(consoleslug)
|
channel.Close(consoleslug)
|
||||||
|
|
||||||
// send all "finished" notifications
|
// send all "finished" notifications
|
||||||
if task.Script.Notifications != nil {
|
if buildscript.Notifications != nil {
|
||||||
task.Script.Notifications.Send(context)
|
buildscript.Notifications.Send(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *worker) runBuild(task *BuildTask, buf io.Writer) (bool, error) {
|
func (w *worker) runBuild(task *BuildTask, buildscript *script.Build, buf io.Writer) (bool, error) {
|
||||||
repo := &r.Repo{
|
repo := &r.Repo{
|
||||||
Name: task.Repo.Slug,
|
Name: task.Repo.Slug,
|
||||||
Path: task.Repo.URL,
|
Path: task.Repo.URL,
|
||||||
|
@ -177,11 +185,11 @@ func (w *worker) runBuild(task *BuildTask, buf io.Writer) (bool, error) {
|
||||||
Commit: task.Commit.Hash,
|
Commit: task.Commit.Hash,
|
||||||
PR: task.Commit.PullRequest,
|
PR: task.Commit.PullRequest,
|
||||||
Dir: filepath.Join("/var/cache/drone/src", task.Repo.Slug),
|
Dir: filepath.Join("/var/cache/drone/src", task.Repo.Slug),
|
||||||
Depth: git.GitDepth(task.Script.Git),
|
Depth: git.GitDepth(buildscript.Git),
|
||||||
}
|
}
|
||||||
|
|
||||||
return w.runner.Run(
|
return w.runner.Run(
|
||||||
task.Script,
|
buildscript,
|
||||||
repo,
|
repo,
|
||||||
[]byte(task.Repo.PrivateKey),
|
[]byte(task.Repo.PrivateKey),
|
||||||
task.Repo.Privileged,
|
task.Repo.Privileged,
|
||||||
|
|
Loading…
Reference in a new issue