attempting complete automated testing

This commit is contained in:
Jeff Carr 2024-12-07 16:46:59 -06:00
parent a3a54501f6
commit 2b21ee65d7
3 changed files with 28 additions and 42 deletions

View File

@ -1,7 +1,7 @@
VERSION = $(shell git describe --tags)
BUILDTIME = $(shell date +%Y.%m.%d)
BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
run: build
run: goimports build
./go-clone --version
vet:
@ -11,8 +11,7 @@ vet:
no-gui: build
./go-clone --no-gui
build:
reset
build: goimports
GO111MODULE=off go build -v \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
@ -23,11 +22,12 @@ build-windows:
GOOS=windows GOARCH=amd64 GO111MODULE=off go build -v go-clone.exe \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
install:
install: goimports
GO111MODULE=off go install \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
goimports:
reset
goimports -w *.go
# // to globally reset paths:
# // gofmt -w -r "go.wit.com/gui -> go.wit.com/gui/gui" .
@ -38,15 +38,10 @@ redomod:
GO111MODULE= go mod tidy
go mod edit -go=1.20
reset:
# clear your terminal
reset
gui-gocui: build
reset
./go-clone --gui gocui >/tmp/witgui.log.stderr 2>&1
nocui: reset build
nocui: build
./go-clone --gui nocui
clean:

View File

@ -10,7 +10,7 @@ var argv args
type args struct {
Repo string `arg:"positional" help:"go import path"`
AutoWork bool `arg:"--auto-work" default:"false" help:"auto recreate the go.work file"`
AutoWork bool `arg:"--work" default:"false" help:"recreate the go.work file"`
DryRun bool `arg:"--dry-run" help:"show what would be run"`
Recursive bool `arg:"--recursive" default:"false" help:"resursively clone all dependencies"`
Pull bool `arg:"--git-pull" default:"false" help:"run 'git pull' on all your repos"`

51
main.go
View File

@ -6,8 +6,6 @@ import (
"path/filepath"
"go.wit.com/dev/alexflint/arg"
"go.wit.com/gui"
"go.wit.com/lib/gui/repolist"
"go.wit.com/lib/gui/shell"
"go.wit.com/lib/protobuf/forgepb"
"go.wit.com/lib/protobuf/gitpb"
@ -20,10 +18,10 @@ var BUILDTIME string
var pp *arg.Parser
var forge *forgepb.Forge
var rv *repolist.RepoList
var argvRepo *gitpb.Repo
func main() {
log.Info("go-clone version", VERSION, "built on", BUILDTIME)
pp = arg.MustParse(&argv)
// for very new users or users unfamilar with the command line, this may help them
@ -39,8 +37,6 @@ func main() {
// load the ~/.config/forge/ config
// this lets you configure repos you have read/write access too
forge = forgepb.Init()
// forge.ConfigPrintTable()
os.Setenv("REPO_WORK_PATH", forge.GetGoSrc())
argvRepo = forge.Repos.FindByGoPath(argv.Repo)
if argvRepo == nil {
@ -48,21 +44,18 @@ func main() {
} else {
log.Info("already have", argv.Repo)
if argv.Recursive {
clone()
recursiveClone()
}
autoWork()
build()
okExit(argv.Repo)
}
// gui is in testing
myGui := gui.New()
// myGui := gui.New()
// myGui.Default()
// find and scan all repos
rv := repolist.Init(forge, myGui)
rv.Enable()
rv.ScanRepositories()
// run 'git pull' if argv --git-pull
if argv.Pull {
gitPull()
@ -72,11 +65,12 @@ func main() {
// remake all the go.sum & go.mod in every repo
// todo: make go.sum and go.mod git commit metadata
if argv.RedoGoMod {
redoGoModAll()
// redoGoModAll()
}
// this works sometimes
if argv.Recursive {
clone()
recursiveClone()
autoWork()
build()
@ -110,7 +104,7 @@ func okExit(thing string) {
func badExit(err error) {
log.Info("Total repositories:", forge.Repos.Len())
log.Info("Finished go-clone with error", err)
log.Info("Finished go-clone with error", err, forge.GetGoSrc())
os.Exit(-1)
}
@ -119,21 +113,20 @@ func clone() {
if argv.Repo != "" {
os.Setenv("REPO_AUTO_CLONE", "true")
// pb, _ := forge.NewGoPath(argv.Repo)
check := forge.Repos.FindByGoPath(argv.Repo)
if check != nil {
return
}
pb, err := forge.Clone(argv.Repo)
if err != nil {
log.Info("could not download")
badExit(err)
}
newr, err := rv.AddRepo(pb)
if err != nil {
log.Info("repolist.AddRepo() failed")
log.Info("clone() could not download err:", err)
badExit(err)
}
// update go.sum and go.mod
// todo: only do this if they don't exist?
// todo: make these git commit metadata
newr.MakeRedoMod()
pb.RedoGoMod()
// double check it actually downloaded
fullgitdir := filepath.Join(forge.GetGoSrc(), argv.Repo, ".git")
@ -194,7 +187,7 @@ func recursiveClone() {
log.Info("download:", depRepo.GoPath)
_, err := forge.Clone(depRepo.GoPath)
if err != nil {
log.Info("could not download", depRepo.GoPath)
log.Info("recursiveClone() could not download", depRepo.GoPath)
log.Info("err:", err)
bad += 1
} else {
@ -206,15 +199,13 @@ func recursiveClone() {
log.Info("got", good, "repos", "failed on", bad, "repos")
}
func redoGoModAll() {
loop := rv.ReposSortByName()
for loop.Scan() {
repo := loop.Repo()
repo.MakeRedoMod()
}
}
func build() error {
forge.RillRedoGoMod()
repos := forge.Repos.SortByGoPath()
for repos.Scan() {
repo := repos.Next()
log.Info("go.work repo (hopefully):", repo.GoPath, repo.FullPath, repo.RepoType())
}
if argv.Install {
if err := forge.Install(argvRepo, nil); err == nil {
okExit("install worked")
@ -236,7 +227,7 @@ func autoWork() {
log.Info("Sleep 3. original go.work saved as go.work.last (hit ctrl-c to cancel)")
log.Sleep(3)
shell.PathRun(forge.GetGoSrc(), []string{"mv", "go.work", "go.work.last"})
rv.MakeGoWork()
forge.MakeGoWork()
shell.PathRun(forge.GetGoSrc(), []string{"go", "work", "use"})
log.Info("")
log.Info("original go.work file saved as go.work.last")