summaryrefslogtreecommitdiff
path: root/goConfig.go
blob: 29dba3d17acd818ab10e8ec9f0bd40b521fe2014 (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
package repolist

// does processing on the go.mod and go.sum files

import (
	"errors"
	"strings"

	"go.wit.com/log"
)

// scans through everything in the go.sum file to make
// sure the versions are correct when attempting to do a GUI release
func (rl *RepoList) CheckValidGoSum(r *RepoRow) (bool, error) {
	log.Log(REPOWARN, "CheckValidGoSum() started")
	ok, err := r.pb.RedoGoMod()
	if !ok {
		log.Log(REPOWARN, "CheckValidGoSum() MakeRedomod() failed", err)
		return ok, err
	}

	// go through each go.sum dependancy to see if the package is released
	for depPath, version := range r.Status.GoConfig() {
		log.Log(REPO, "  ", depPath, version)

		// lookup the repo
		deprs := rl.FindRepo(depPath)
		if deprs == nil {
			// well, the go.sum dependancy hasn't been processed or doesn't exist
			// so, download it? ignore it?
			// for now, if it's not one of the GUI repos, assume it's readonly and ignore it
			if strings.HasPrefix(depPath, "go.wit.com") {
				log.Log(REPOWARN, "Run: go get -v", depPath)
				return false, errors.New("CheckValidGoSum() download repo: " + depPath)
			}
			// it's probably okay. running a compile check before this would be a good test
			continue
		}
		if deprs.ReadOnly() {
			// ignore versioning on other repos. todo: help fix this situation somehow?
			continue
		}
		if deprs.CheckDirty() {
			return false, errors.New("CheckValidGoSum() depends on dirty repo " + deprs.GoPath())
		}
		currentV := deprs.Status.GetCurrentVersion()
		targetV := deprs.Status.GetTargetVersion()
		if currentV != targetV {
			return false, errors.New("CheckValidGoSum() depends on yet unreleased repo " + deprs.GoPath())
		}
	}
	// no dependancies error'd out. It should be ok to release this package
	log.Log(REPOWARN, "Releasing this should be ok", r.GoPath())
	return true, nil
}