mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-26 20:01:02 +00:00
Merge pull request #1179 from tboerger/feature/make
Make.go improvements
This commit is contained in:
commit
f5da9f64d5
3 changed files with 249 additions and 103 deletions
24
.drone.yml
24
.drone.yml
|
@ -1,18 +1,18 @@
|
||||||
image: bradrydzewski/go:1.5
|
image: bradrydzewski/go:1.5
|
||||||
|
|
||||||
git:
|
git:
|
||||||
path: github.com/drone/drone
|
path: github.com/drone/drone
|
||||||
|
|
||||||
env:
|
env:
|
||||||
- GOROOT=/usr/local/go
|
- GOROOT=/usr/local/go
|
||||||
- PATH=$PATH:$GOROOT/bin:$GOPATH/bin
|
- PATH=$PATH:$GOROOT/bin:$GOPATH/bin
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- go get golang.org/x/tools/cmd/cover
|
- go run make.go deps
|
||||||
- go get golang.org/x/tools/cmd/vet
|
|
||||||
- go get -u github.com/jteeuwen/go-bindata/...
|
|
||||||
|
|
||||||
- go run make.go bindata
|
- go run make.go bindata
|
||||||
- go run make.go build
|
|
||||||
- go run make.go vet
|
- go run make.go vet
|
||||||
|
- go run make.go fmt
|
||||||
|
- go run make.go build
|
||||||
- go run make.go test
|
- go run make.go test
|
||||||
|
|
||||||
- make dist
|
- make dist
|
||||||
|
@ -34,7 +34,7 @@ publish:
|
||||||
when:
|
when:
|
||||||
owner: drone
|
owner: drone
|
||||||
|
|
||||||
# new .drone.yml syntax
|
|
||||||
|
|
||||||
clone:
|
clone:
|
||||||
path: github.com/drone/drone
|
path: github.com/drone/drone
|
||||||
|
@ -44,10 +44,14 @@ build:
|
||||||
commands:
|
commands:
|
||||||
- export GOPATH=/drone
|
- export GOPATH=/drone
|
||||||
- export PATH=$PATH:$GOPATH/bin
|
- export PATH=$PATH:$GOPATH/bin
|
||||||
- go get -u github.com/jteeuwen/go-bindata/...
|
|
||||||
- make deps
|
- go run make.go deps
|
||||||
- make
|
- go run make.go bindata
|
||||||
- make test
|
- go run make.go vet
|
||||||
|
- go run make.go fmt
|
||||||
|
- go run make.go build
|
||||||
|
- go run make.go test
|
||||||
|
|
||||||
- make dist
|
- make dist
|
||||||
|
|
||||||
compose:
|
compose:
|
||||||
|
|
20
README.md
20
README.md
|
@ -31,16 +31,28 @@ cd $GOPATH/src/github.com/drone/drone
|
||||||
Commands to build from source:
|
Commands to build from source:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
make deps # download dependencies
|
go run make.go deps # Download required dependencies
|
||||||
make # create binary files in ./bin
|
go run make.go bindata # Generate required bindata
|
||||||
make test # execute unit tests
|
go run make.go build # Build the binaries
|
||||||
|
go run make.go image # Build docker images
|
||||||
|
go run make.go test # Run the test suite
|
||||||
|
go run make.go clean # Clean up environment
|
||||||
|
```
|
||||||
|
|
||||||
|
Commands for development:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
go run make.go scripts # Concat all javascripts
|
||||||
|
go run make.go styles # Concat all stylesheets
|
||||||
|
go run make.go vet # Execute vet command
|
||||||
|
go run make.go fmt # Execute fmt command
|
||||||
```
|
```
|
||||||
|
|
||||||
Commands to start drone:
|
Commands to start drone:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
bin/drone
|
bin/drone
|
||||||
bin/drone --debug # debug mode loads static content from filesystem
|
bin/drone --debug # Debug mode loads static content from filesystem
|
||||||
```
|
```
|
||||||
|
|
||||||
If you are seeing slow compile times please install the following:
|
If you are seeing slow compile times please install the following:
|
||||||
|
|
324
make.go
324
make.go
|
@ -1,10 +1,8 @@
|
||||||
// +build ignore
|
// +build ignore
|
||||||
|
|
||||||
// This program builds Drone.
|
// This program builds Drone.
|
||||||
// $ go run make.go build test
|
// $ go run make.go deps bindata build test
|
||||||
//
|
|
||||||
// The output binaries go into the ./bin/ directory (under the
|
|
||||||
// project root, where make.go is)
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -14,8 +12,6 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/jteeuwen/go-bindata"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -26,28 +22,34 @@ var (
|
||||||
// list of all posible steps that can be executed
|
// list of all posible steps that can be executed
|
||||||
// as part of the build process.
|
// as part of the build process.
|
||||||
var steps = map[string]step{
|
var steps = map[string]step{
|
||||||
"scripts": scripts,
|
"deps": executeDeps,
|
||||||
"styles": styles,
|
"json": executeJson,
|
||||||
"json": json,
|
"embed": executeEmbed,
|
||||||
"embed": embed,
|
"scripts": executeScripts,
|
||||||
"vet": vet,
|
"styles": executeStyles,
|
||||||
"bindata": bindat,
|
"vet": executeVet,
|
||||||
"build": build,
|
"fmt": executeFmt,
|
||||||
"test": test,
|
"test": executeTest,
|
||||||
"image": image,
|
"build": executeBuild,
|
||||||
"clean": clean,
|
"install": executeInstall,
|
||||||
|
"image": executeImage,
|
||||||
|
"bindata": executeBindata,
|
||||||
|
"clean": executeClean,
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
for _, arg := range os.Args[1:] {
|
for _, arg := range os.Args[1:] {
|
||||||
step, ok := steps[arg]
|
step, ok := steps[arg]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
fmt.Println("error: invalid step", arg)
|
fmt.Println("Error: Invalid step", arg)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := step()
|
err := step()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("error: failed step", arg)
|
fmt.Println("Error: Failed step", arg)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,15 +57,43 @@ func main() {
|
||||||
|
|
||||||
type step func() error
|
type step func() error
|
||||||
|
|
||||||
|
func executeDeps() error {
|
||||||
|
deps := []string{
|
||||||
|
"github.com/jteeuwen/go-bindata/...",
|
||||||
|
"golang.org/x/tools/cmd/cover",
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, dep := range deps {
|
||||||
|
err := run(
|
||||||
|
"go",
|
||||||
|
"get",
|
||||||
|
"-u",
|
||||||
|
dep)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// json step generates optimized json marshal and
|
||||||
|
// unmarshal functions to override defaults.
|
||||||
|
func executeJson() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// embed step embeds static files in .go files.
|
// embed step embeds static files in .go files.
|
||||||
func embed() error {
|
func executeEmbed() error {
|
||||||
// embed drone.{revision}.css
|
// embed drone.{revision}.css
|
||||||
// embed drone.{revision}.js
|
// embed drone.{revision}.js
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// scripts step concatinates all javascript files.
|
// scripts step concatinates all javascript files.
|
||||||
func scripts() error {
|
func executeScripts() error {
|
||||||
files := []string{
|
files := []string{
|
||||||
"cmd/drone-server/static/scripts/term.js",
|
"cmd/drone-server/static/scripts/term.js",
|
||||||
"cmd/drone-server/static/scripts/drone.js",
|
"cmd/drone-server/static/scripts/drone.js",
|
||||||
|
@ -107,7 +137,7 @@ func scripts() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// styles step concatinates the stylesheet files.
|
// styles step concatinates the stylesheet files.
|
||||||
func styles() error {
|
func executeStyles() error {
|
||||||
files := []string{
|
files := []string{
|
||||||
"cmd/drone-server/static/styles/reset.css",
|
"cmd/drone-server/static/styles/reset.css",
|
||||||
"cmd/drone-server/static/styles/fonts.css",
|
"cmd/drone-server/static/styles/fonts.css",
|
||||||
|
@ -145,101 +175,182 @@ func styles() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// json step generates optimized json marshal and
|
// vet step executes the `go vet` command
|
||||||
// unmarshal functions to override defaults.
|
func executeVet() error {
|
||||||
func json() error {
|
return run(
|
||||||
|
"go",
|
||||||
|
"vet",
|
||||||
|
"github.com/drone/drone/pkg/...",
|
||||||
|
"github.com/drone/drone/cmd/...")
|
||||||
|
}
|
||||||
|
|
||||||
|
// fmt step executes the `go fmt` command
|
||||||
|
func executeFmt() error {
|
||||||
|
return run(
|
||||||
|
"go",
|
||||||
|
"fmt",
|
||||||
|
"github.com/drone/drone/pkg/...",
|
||||||
|
"github.com/drone/drone/cmd/...")
|
||||||
|
}
|
||||||
|
|
||||||
|
// test step executes unit tests and coverage.
|
||||||
|
func executeTest() error {
|
||||||
|
ldf := fmt.Sprintf(
|
||||||
|
"-X main.revision=%s -X main.version=%s",
|
||||||
|
sha,
|
||||||
|
version)
|
||||||
|
|
||||||
|
return run(
|
||||||
|
"go",
|
||||||
|
"test",
|
||||||
|
"-cover",
|
||||||
|
"-ldflags",
|
||||||
|
ldf,
|
||||||
|
"github.com/drone/drone/pkg/...",
|
||||||
|
"github.com/drone/drone/cmd/...")
|
||||||
|
}
|
||||||
|
|
||||||
|
// install step installs the application binaries.
|
||||||
|
func executeInstall() error {
|
||||||
|
var bins = []struct {
|
||||||
|
input string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"github.com/drone/drone/cmd/drone-server",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, bin := range bins {
|
||||||
|
ldf := fmt.Sprintf(
|
||||||
|
"-X main.revision=%s -X main.version=%s",
|
||||||
|
sha,
|
||||||
|
version)
|
||||||
|
|
||||||
|
err := run(
|
||||||
|
"go",
|
||||||
|
"install",
|
||||||
|
"-ldflags",
|
||||||
|
ldf,
|
||||||
|
bin.input)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// bindata step generates go-bindata package.
|
|
||||||
func bindat() error {
|
|
||||||
var paths = []struct {
|
|
||||||
input string
|
|
||||||
recursive bool
|
|
||||||
}{
|
|
||||||
{"cmd/drone-server/static", true},
|
|
||||||
}
|
|
||||||
|
|
||||||
c := bindata.NewConfig()
|
|
||||||
c.Output = "cmd/drone-server/drone_bindata.go"
|
|
||||||
c.Input = make([]bindata.InputConfig, len(paths))
|
|
||||||
|
|
||||||
for i, path := range paths {
|
|
||||||
c.Input[i] = bindata.InputConfig{
|
|
||||||
Path: path.input,
|
|
||||||
Recursive: path.recursive,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return bindata.Translate(c)
|
|
||||||
}
|
|
||||||
|
|
||||||
// build step creates the application binaries.
|
// build step creates the application binaries.
|
||||||
func build() error {
|
func executeBuild() error {
|
||||||
var bins = []struct {
|
var bins = []struct {
|
||||||
input string
|
input string
|
||||||
output string
|
output string
|
||||||
}{
|
}{
|
||||||
{"github.com/drone/drone/cmd/drone-server", "bin/drone"},
|
{
|
||||||
|
"github.com/drone/drone/cmd/drone-server",
|
||||||
|
"bin/drone",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, bin := range bins {
|
for _, bin := range bins {
|
||||||
ldf := fmt.Sprintf("-X main.revision=%s -X main.version=%s", sha, version)
|
ldf := fmt.Sprintf(
|
||||||
cmd := exec.Command("go", "build", "-o", bin.output, "-ldflags", ldf, bin.input)
|
"-X main.revision=%s -X main.version=%s",
|
||||||
cmd.Stdout = os.Stdout
|
sha,
|
||||||
cmd.Stderr = os.Stderr
|
version)
|
||||||
trace(cmd.Args)
|
|
||||||
err := cmd.Run()
|
err := run(
|
||||||
|
"go",
|
||||||
|
"build",
|
||||||
|
"-o",
|
||||||
|
bin.output,
|
||||||
|
"-ldflags",
|
||||||
|
ldf,
|
||||||
|
bin.input)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// vet step executes the `go vet` command
|
// image step builds docker images.
|
||||||
func vet() error {
|
func executeImage() error {
|
||||||
cmd := exec.Command("go", "vet",
|
|
||||||
"github.com/drone/drone/pkg/...",
|
|
||||||
"github.com/drone/drone/cmd/...")
|
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
trace(cmd.Args)
|
|
||||||
return cmd.Run()
|
|
||||||
}
|
|
||||||
|
|
||||||
// test step executes unit tests and coverage.
|
|
||||||
func test() error {
|
|
||||||
cmd := exec.Command("go", "test", "-cover", "./pkg/...")
|
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
trace(cmd.Args)
|
|
||||||
return cmd.Run()
|
|
||||||
}
|
|
||||||
|
|
||||||
// image step builds Docker images.
|
|
||||||
func image() error {
|
|
||||||
var images = []struct {
|
var images = []struct {
|
||||||
dir string
|
dir string
|
||||||
name string
|
name string
|
||||||
}{
|
}{
|
||||||
{"./bin/drone-server", "drone/drone"},
|
{
|
||||||
|
"bin/drone-server",
|
||||||
|
"drone/drone",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, image := range images {
|
for _, image := range images {
|
||||||
path := filepath.Join(image.dir, "Dockerfile")
|
path := filepath.Join(
|
||||||
name := image.name + ":" + version
|
image.dir,
|
||||||
cmd := exec.Command("docker", "build", "-rm", path, name)
|
"Dockerfile")
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
cmd.Stderr = os.Stderr
|
name := fmt.Sprintf("%s:%s",
|
||||||
trace(cmd.Args)
|
image.name,
|
||||||
err := cmd.Run()
|
version)
|
||||||
|
|
||||||
|
err := run(
|
||||||
|
"docker",
|
||||||
|
"build",
|
||||||
|
"-rm",
|
||||||
|
path,
|
||||||
|
name)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func clean() error {
|
// bindata step generates go-bindata package.
|
||||||
|
func executeBindata() error {
|
||||||
|
var paths = []struct {
|
||||||
|
input string
|
||||||
|
output string
|
||||||
|
pkg string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"cmd/drone-server/static/...",
|
||||||
|
"cmd/drone-server/drone_bindata.go",
|
||||||
|
"main",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, path := range paths {
|
||||||
|
binErr := run(
|
||||||
|
"go-bindata",
|
||||||
|
fmt.Sprintf("-o=%s", path.output),
|
||||||
|
fmt.Sprintf("-pkg=%s", path.pkg),
|
||||||
|
path.input)
|
||||||
|
|
||||||
|
if binErr != nil {
|
||||||
|
return binErr
|
||||||
|
}
|
||||||
|
|
||||||
|
fmtErr := run(
|
||||||
|
"go",
|
||||||
|
"fmt",
|
||||||
|
path.output)
|
||||||
|
|
||||||
|
if fmtErr != nil {
|
||||||
|
return fmtErr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// clean step removes all generated files.
|
||||||
|
func executeClean() error {
|
||||||
err := filepath.Walk(".", func(path string, f os.FileInfo, err error) error {
|
err := filepath.Walk(".", func(path string, f os.FileInfo, err error) error {
|
||||||
suffixes := []string{
|
suffixes := []string{
|
||||||
".out",
|
".out",
|
||||||
|
@ -278,19 +389,38 @@ func clean() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// trace is a helper fucntion that writes a command
|
// run is a helper function that executes commands
|
||||||
|
// and assigns stdout and stderr targets
|
||||||
|
func run(command string, args ...string) error {
|
||||||
|
cmd := exec.Command(command, args...)
|
||||||
|
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
|
trace(cmd.Args)
|
||||||
|
return cmd.Run()
|
||||||
|
}
|
||||||
|
|
||||||
|
// helper function to parse the git revision
|
||||||
|
func rev() string {
|
||||||
|
cmd := exec.Command(
|
||||||
|
"git",
|
||||||
|
"rev-parse",
|
||||||
|
"--short",
|
||||||
|
"HEAD")
|
||||||
|
|
||||||
|
raw, err := cmd.CombinedOutput()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return "HEAD"
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.Trim(string(raw), "\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
// trace is a helper function that writes a command
|
||||||
// to stdout similar to bash +x
|
// to stdout similar to bash +x
|
||||||
func trace(args []string) {
|
func trace(args []string) {
|
||||||
print("+ ")
|
print("+ ")
|
||||||
println(strings.Join(args, " "))
|
println(strings.Join(args, " "))
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to parse the git revision
|
|
||||||
func rev() string {
|
|
||||||
cmd := exec.Command("git", "rev-parse", "--short", "HEAD")
|
|
||||||
raw, err := cmd.CombinedOutput()
|
|
||||||
if err != nil {
|
|
||||||
return "HEAD"
|
|
||||||
}
|
|
||||||
return strings.Trim(string(raw), "\n")
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue