summaryrefslogtreecommitdiff
path: root/buildDeb.go
blob: 2f6c1c292b7208a34f2b5c9a81c47b685c818384 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main

import (
	"fmt"
	"os"
	"path/filepath"

	"go.wit.com/lib/protobuf/gitpb"
	"go.wit.com/log"
)

func buildDeb() {
	if argv.DryRun {
		return
	}
	log.DaemonMode(true)
	defer log.DaemonMode(false)

	all := me.forge.Repos.SortByFullPath()
	for all.Scan() {
		var cmd []string
		check := all.Next()

		if state[check] != "need to build" {
			// log.Info("skipping build for", check.GetGoPath(), state[check])
			continue
		}

		outdir := getOutdir(check)
		os.MkdirAll(outdir, 0755)

		_, err := os.Stat(filepath.Join(outdir, debnames[check]))
		if err == nil {
			if debnames[check] == "" {
				log.Info("something went wrong. .deb blank", check.GetGoPath())
			}
			// already built
			continue
		}

		if argv.Release {
			cmd = []string{"go-deb", "--release", "--auto", "--repo", check.GetGoPath(), "--dir", outdir}
		} else {
			cmd = []string{"go-deb", "--auto", "--no-gui", "--repo", check.GetGoPath(), "--dir", outdir}
		}
		if me.forge.Config.IsPrivate(check.GetGoPath()) {
			cmd = []string{"go-deb", "--auto", "--repo", check.GetGoPath(), "--dir", outdir}
		}
		log.Info("build cmd:", cmd)
		if r := check.RunRealtime(cmd); r.Error != nil {
			log.Info("go-deb failed error:", r.Error, check.GetGoPath())
			failed[check] = fmt.Sprint("godeb failed", cmd, "with", r.Exit, r.Error)
		} else if r.Exit != 0 {
			log.Info("go-deb failed exit =", r.Exit, check.GetGoPath())
			failed[check] = fmt.Sprint("godeb failed", cmd, "with", r.Exit, r.Error)
		} else {
			log.Info("build worked")
		}
	}
}

func getOutdir(repo *gitpb.Repo) string {
	if repo.GetLastTag() != repo.GetMasterVersion() {
		return "/home/jcarr/incoming-devel"
	}

	if repo.GetCurrentBranchVersion() != repo.GetMasterVersion() {
		return "/home/jcarr/incoming-devel"
	}

	if repo.CheckDirty() {
		return "/home/jcarr/incoming-devel"
	}

	if me.forge.Config.IsPrivate(repo.GetGoPath()) {
		return "/home/jcarr/incoming-private"
	}
	return "/home/jcarr/incoming"
}