summaryrefslogtreecommitdiff
path: root/debian.go
blob: 9a888c2ca6f5978722acd4bf49df0ceb8d289cec (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
80
81
82
83
84
85
86
87
88
89
90
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0

package main

import (
	"fmt"
	"os"

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

func buildDeb(check *gitpb.Repo) error {
	var cmd []string

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

	if me.forge.Config.IsReadOnly(check.GetGoPath()) {
		return nil
	}

	if !check.IsBinary() {
		return nil
	}

	if check.IsGoPlugin() {
		return nil
	}

	if argv.Release {
		cmd = []string{"go-deb", "--release", "--dir", outdir}
	} else {
		cmd = []string{"go-deb", "--dir", outdir}
	}
	if me.forge.Config.IsPrivate(check.GetGoPath()) {
		cmd = []string{"go-deb", "--dir", outdir}
		return nil
	}

	if argv.Verbose || argv.Force {
		// log.Info("build cmd:", cmd)
		cmd = append(cmd, "--verbose")
	}
	if argv.DryRun {
		return nil
	}

	if argv.Force {
		// build everything no matter what
	} else {
		if state[check] != "need to build" {
			// log.Info("skipping build for", check.GetGoPath(), state[check])
			return nil
		}
	}

	var err error
	if _, err = check.RunVerboseOnError(cmd); err != nil {
		log.Info(check.FullPath, cmd)
		failed[check] = fmt.Sprint("godeb failed", cmd, "with", err)
		return err
	}

	log.Info("build worked", cmd, check.FullPath)
	return nil
}

func getOutdir(repo *gitpb.Repo) string {
	if me.forge.Config.IsPrivate(repo.GetGoPath()) {
		return "/home/jcarr/incoming-private"
	}
	if argv.Force {
		return "/home/jcarr/incoming"
	}
	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"
	}

	return "/home/jcarr/incoming"
}