mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-26 20:01:02 +00:00
Adding test for get build number. Moved build number env build injection
This commit is contained in:
parent
5f8b026d14
commit
717bef75dd
5 changed files with 30 additions and 21 deletions
|
@ -69,6 +69,21 @@ func TestCommitstore(t *testing.T) {
|
|||
g.Assert(commit.Updated).Equal(getcommit.Updated)
|
||||
})
|
||||
|
||||
g.It("Should Get the build number", func() {
|
||||
commit := model.Commit{
|
||||
RepoID: 1,
|
||||
Branch: "foo",
|
||||
Sha: "85f8c029b902ed9400bc600bac301a0aadb144ac",
|
||||
Status: model.StatusSuccess,
|
||||
Created: 1398065343,
|
||||
Updated: 1398065344,
|
||||
}
|
||||
cs.PostCommit(&commit)
|
||||
bn, err := cs.GetBuildNumber(&commit)
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(bn).Equal(int64(1))
|
||||
})
|
||||
|
||||
g.It("Should Delete a Commit", func() {
|
||||
commit := model.Commit{
|
||||
RepoID: 1,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package docker
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"runtime/debug"
|
||||
|
@ -115,17 +116,18 @@ func (d *Docker) Do(c context.Context, r *worker.Work) {
|
|||
if err != nil {
|
||||
log.Printf("Unable to fetch build number, Err: %s", err.Error())
|
||||
}
|
||||
script.Env = append(script.Env, fmt.Sprintf("DRONE_BUILD_NUMBER=%d", buildNumber))
|
||||
script.Env = append(script.Env, fmt.Sprintf("CI_BUILD_NUMBER=%d", buildNumber))
|
||||
|
||||
path := r.Repo.Host + "/" + r.Repo.Owner + "/" + r.Repo.Name
|
||||
repo := &repo.Repo{
|
||||
Name: path,
|
||||
Path: r.Repo.CloneURL,
|
||||
Branch: r.Commit.Branch,
|
||||
Commit: r.Commit.Sha,
|
||||
PR: r.Commit.PullRequest,
|
||||
Dir: filepath.Join("/var/cache/drone/src", git.GitPath(script.Git, path)),
|
||||
Depth: git.GitDepth(script.Git),
|
||||
BuildNumber: buildNumber,
|
||||
Name: path,
|
||||
Path: r.Repo.CloneURL,
|
||||
Branch: r.Commit.Branch,
|
||||
Commit: r.Commit.Sha,
|
||||
PR: r.Commit.PullRequest,
|
||||
Dir: filepath.Join("/var/cache/drone/src", git.GitPath(script.Git, path)),
|
||||
Depth: git.GitDepth(script.Git),
|
||||
}
|
||||
|
||||
priorCommit, _ := datastore.GetCommitPrior(c, r.Commit)
|
||||
|
|
|
@ -488,12 +488,10 @@ func (b *Builder) writeBuildScript(dir string) error {
|
|||
f.WriteEnv("DRONE_COMMIT", b.Repo.Commit)
|
||||
f.WriteEnv("DRONE_PR", b.Repo.PR)
|
||||
f.WriteEnv("DRONE_BUILD_DIR", b.Repo.Dir)
|
||||
f.WriteEnv("DRONE_BUILD_NUMBER", fmt.Sprintf("%d", b.Repo.BuildNumber))
|
||||
|
||||
// add environment variables for code coverage
|
||||
// systems, like coveralls.
|
||||
f.WriteEnv("CI_NAME", "DRONE")
|
||||
f.WriteEnv("CI_BUILD_NUMBER", fmt.Sprintf("%d", b.Repo.BuildNumber))
|
||||
f.WriteEnv("CI_BUILD_URL", "")
|
||||
f.WriteEnv("CI_REMOTE", b.Repo.Path)
|
||||
f.WriteEnv("CI_BRANCH", b.Repo.Branch)
|
||||
|
|
|
@ -522,12 +522,11 @@ func TestWriteBuildScript(t *testing.T) {
|
|||
Hosts: []string{"127.0.0.1"}}
|
||||
b.Key = []byte("ssh-rsa AAA...")
|
||||
b.Repo = &repo.Repo{
|
||||
Path: "git://github.com/drone/drone.git",
|
||||
Branch: "master",
|
||||
Commit: "e7e046b35",
|
||||
BuildNumber: 0,
|
||||
PR: "123",
|
||||
Dir: "/var/cache/drone/github.com/drone/drone"}
|
||||
Path: "git://github.com/drone/drone.git",
|
||||
Branch: "master",
|
||||
Commit: "e7e046b35",
|
||||
PR: "123",
|
||||
Dir: "/var/cache/drone/github.com/drone/drone"}
|
||||
b.writeBuildScript(dir)
|
||||
|
||||
// persist a dummy build script to disk
|
||||
|
@ -549,9 +548,7 @@ func TestWriteBuildScript(t *testing.T) {
|
|||
f.WriteEnv("DRONE_COMMIT", "e7e046b35")
|
||||
f.WriteEnv("DRONE_PR", "123")
|
||||
f.WriteEnv("DRONE_BUILD_DIR", "/var/cache/drone/github.com/drone/drone")
|
||||
f.WriteEnv("DRONE_BUILD_NUMBER", "0")
|
||||
f.WriteEnv("CI_NAME", "DRONE")
|
||||
f.WriteEnv("CI_BUILD_NUMBER", "0")
|
||||
f.WriteEnv("CI_BUILD_URL", "")
|
||||
f.WriteEnv("CI_REMOTE", "git://github.com/drone/drone.git")
|
||||
f.WriteEnv("CI_BRANCH", "master")
|
||||
|
|
|
@ -40,9 +40,6 @@ type Repo struct {
|
|||
|
||||
// (optional) The depth of the `git clone` command.
|
||||
Depth int
|
||||
|
||||
// The monotonically increasing build number for this repo
|
||||
BuildNumber int64
|
||||
}
|
||||
|
||||
// IsRemote returns true if the Repository is located
|
||||
|
|
Loading…
Reference in a new issue