summaryrefslogtreecommitdiff
path: root/doDebian.go
blob: f97eaf208aa1065cb4be64f2e7c6affb812b1a7d (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// 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() {
	log.DaemonMode(true)
	defer log.DaemonMode(false)

	if argv.Test != nil {
		if err := doInstall(); err != nil {
			log.Info("doInstall() failed", err)
			badExit(err)
		}
	}

	var counter int

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

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

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

		if !check.IsBinary() {
			continue
		}

		if check.IsGoPlugin() {
			continue
		}

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

		if argv.Verbose {
			log.Info("build cmd:", cmd)
			cmd = append(cmd, "--verbose")
		}
		if argv.DryRun {
			continue
		}

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

		counter += 1

		if int(argv.Max) == 0 {
			argv.Max = 10
		}

		if counter > int(argv.Max) {
			log.Info("did --max builds", argv.Max)
			okExit("")
		}

		/*
			build-darwin:
				GOOS=darwin GOARCH=amd64 GO111MODULE=off go build -v -o go-clone-darwin.x86 \
					-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"

			build-darwin-arm64:
				GOOS=darwin GOARCH=arm64 GO111MODULE=off go build -v -o go-clone-darwin.arm \
					-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
		*/
		if argv.MacBuild != nil {
			log.Info("todo: add mac builds")
			continue
		}

		/*
			_, 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 err := check.RunVerbose(cmd); err != nil {
			failed[check] = fmt.Sprint("godeb failed", cmd, "with", err)
			badExit(err)
		} 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"
}