mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-22 18:01:02 +00:00
Refactoring of the make file
This commit is contained in:
parent
7df78a2864
commit
17740d0026
2 changed files with 177 additions and 90 deletions
20
README.md
20
README.md
|
@ -31,16 +31,28 @@ cd $GOPATH/src/github.com/drone/drone
|
|||
Commands to build from source:
|
||||
|
||||
```sh
|
||||
make deps # download dependencies
|
||||
make # create binary files in ./bin
|
||||
make test # execute unit tests
|
||||
go run make.go deps # Download required dependencies
|
||||
go run make.go bindata # Generate required bindata
|
||||
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:
|
||||
|
||||
```sh
|
||||
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:
|
||||
|
|
247
make.go
247
make.go
|
@ -12,8 +12,6 @@ import (
|
|||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/jteeuwen/go-bindata"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -24,28 +22,33 @@ var (
|
|||
// list of all posible steps that can be executed
|
||||
// as part of the build process.
|
||||
var steps = map[string]step{
|
||||
"scripts": scripts,
|
||||
"styles": styles,
|
||||
"json": json,
|
||||
"embed": embed,
|
||||
"vet": vet,
|
||||
"bindata": bindat,
|
||||
"build": build,
|
||||
"test": test,
|
||||
"image": image,
|
||||
"clean": clean,
|
||||
"deps": executeDeps,
|
||||
"json": executeJson,
|
||||
"embed": executeEmbed,
|
||||
"scripts": executeScripts,
|
||||
"styles": executeStyles,
|
||||
"vet": executeVet,
|
||||
"fmt": executeFmt,
|
||||
"test": executeTest,
|
||||
"build": executeBuild,
|
||||
"image": executeImage,
|
||||
"bindata": executeBindata,
|
||||
"clean": executeClean,
|
||||
}
|
||||
|
||||
func main() {
|
||||
for _, arg := range os.Args[1:] {
|
||||
step, ok := steps[arg]
|
||||
|
||||
if !ok {
|
||||
fmt.Println("error: invalid step", arg)
|
||||
fmt.Println("Error: Invalid step", arg)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
err := step()
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("error: failed step", arg)
|
||||
fmt.Println("Error: Failed step", arg)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
@ -53,15 +56,43 @@ func main() {
|
|||
|
||||
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.
|
||||
func embed() error {
|
||||
func executeEmbed() error {
|
||||
// embed drone.{revision}.css
|
||||
// embed drone.{revision}.js
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// scripts step concatinates all javascript files.
|
||||
func scripts() error {
|
||||
func executeScripts() error {
|
||||
files := []string{
|
||||
"cmd/drone-server/static/scripts/term.js",
|
||||
"cmd/drone-server/static/scripts/drone.js",
|
||||
|
@ -105,7 +136,7 @@ func scripts() error {
|
|||
}
|
||||
|
||||
// styles step concatinates the stylesheet files.
|
||||
func styles() error {
|
||||
func executeStyles() error {
|
||||
files := []string{
|
||||
"cmd/drone-server/static/styles/reset.css",
|
||||
"cmd/drone-server/static/styles/fonts.css",
|
||||
|
@ -143,101 +174,151 @@ func styles() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// json step generates optimized json marshal and
|
||||
// unmarshal functions to override defaults.
|
||||
func json() error {
|
||||
return nil
|
||||
// vet step executes the `go vet` command
|
||||
func executeVet() error {
|
||||
return run(
|
||||
"go",
|
||||
"vet",
|
||||
"github.com/drone/drone/pkg/...",
|
||||
"github.com/drone/drone/cmd/...")
|
||||
}
|
||||
|
||||
// bindata step generates go-bindata package.
|
||||
func bindat() error {
|
||||
var paths = []struct {
|
||||
input string
|
||||
recursive bool
|
||||
}{
|
||||
{"cmd/drone-server/static", true},
|
||||
}
|
||||
// fmt step executes the `go fmt` command
|
||||
func executeFmt() error {
|
||||
return run(
|
||||
"go",
|
||||
"fmt",
|
||||
"github.com/drone/drone/pkg/...",
|
||||
"github.com/drone/drone/cmd/...")
|
||||
}
|
||||
|
||||
c := bindata.NewConfig()
|
||||
c.Output = "cmd/drone-server/drone_bindata.go"
|
||||
c.Input = make([]bindata.InputConfig, len(paths))
|
||||
// test step executes unit tests and coverage.
|
||||
func executeTest() error {
|
||||
ldf := fmt.Sprintf(
|
||||
"-X main.revision=%s -X main.version=%s",
|
||||
sha,
|
||||
version)
|
||||
|
||||
for i, path := range paths {
|
||||
c.Input[i] = bindata.InputConfig{
|
||||
Path: path.input,
|
||||
Recursive: path.recursive,
|
||||
}
|
||||
}
|
||||
|
||||
return bindata.Translate(c)
|
||||
return run(
|
||||
"go",
|
||||
"test",
|
||||
"-cover",
|
||||
"-ldflags",
|
||||
ldf,
|
||||
"github.com/drone/drone/pkg/...",
|
||||
"github.com/drone/drone/cmd/...")
|
||||
}
|
||||
|
||||
// build step creates the application binaries.
|
||||
func build() error {
|
||||
func executeBuild() error {
|
||||
var bins = []struct {
|
||||
input 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 {
|
||||
ldf := fmt.Sprintf("-X main.revision=%s -X main.version=%s", sha, version)
|
||||
cmd := exec.Command("go", "build", "-o", bin.output, "-ldflags", ldf, bin.input)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
trace(cmd.Args)
|
||||
err := cmd.Run()
|
||||
ldf := fmt.Sprintf(
|
||||
"-X main.revision=%s -X main.version=%s",
|
||||
sha,
|
||||
version)
|
||||
|
||||
err := run(
|
||||
"go",
|
||||
"build",
|
||||
"-o",
|
||||
bin.output,
|
||||
"-ldflags",
|
||||
ldf,
|
||||
bin.input)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// vet step executes the `go vet` command
|
||||
func vet() 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 {
|
||||
// image step builds docker images.
|
||||
func executeImage() error {
|
||||
var images = []struct {
|
||||
dir string
|
||||
name string
|
||||
}{
|
||||
{"./bin/drone-server", "drone/drone"},
|
||||
{
|
||||
"bin/drone-server",
|
||||
"drone/drone",
|
||||
},
|
||||
}
|
||||
for _, image := range images {
|
||||
path := filepath.Join(image.dir, "Dockerfile")
|
||||
name := image.name + ":" + version
|
||||
cmd := exec.Command("docker", "build", "-rm", path, name)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
trace(cmd.Args)
|
||||
err := cmd.Run()
|
||||
path := filepath.Join(
|
||||
image.dir,
|
||||
"Dockerfile")
|
||||
|
||||
name := fmt.Sprintf("%s:%s",
|
||||
image.name,
|
||||
version)
|
||||
|
||||
err := run(
|
||||
"docker",
|
||||
"build",
|
||||
"-rm",
|
||||
path,
|
||||
name)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
suffixes := []string{
|
||||
".out",
|
||||
|
@ -285,13 +366,7 @@ func run(command string, args ...string) error {
|
|||
cmd.Stderr = os.Stderr
|
||||
|
||||
trace(cmd.Args)
|
||||
err := cmd.Run()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
// helper function to parse the git revision
|
||||
|
|
Loading…
Reference in a new issue