Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2023-10-01 16:28:03 +03:00
parent 4e217eaa8d
commit 0844b2e32e
2 changed files with 38 additions and 2 deletions

4
.gitignore vendored
View File

@ -27,6 +27,6 @@ bin/
tmp/
cmd/pkgdash/pkgdash
cmd/pkgdashctl/pkgdashctl
cmd/pkgdashcli/pkgdashcli
*.sqlite
*.db
*.db

View File

@ -4,10 +4,12 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"os"
"os/exec"
"path/filepath"
"text/template"
@ -216,10 +218,44 @@ func giteaPullRequest(ctx context.Context, cfg *Config, mods map[string]modules.
fmt.Printf("%s from %s to %s\n", path, mod.Module.Version, mod.Version)
ref := plumbing.NewHashReference(plumbing.ReferenceName(fmt.Sprintf("refs/heads/pkgdash/go_modules/%s-%s", path, mod.Version)), headRef.Hash())
if err = repo.Storer.SetReference(ref); err != nil {
logger.Fatalf(ctx, "failed to create repo branch: %v", err)
}
wtree, err := repo.Worktree()
if err != nil {
logger.Fatalf(ctx, "failed to get worktree: %v", err)
}
epath, err := exec.LookPath("go")
if errors.Is(err, exec.ErrDot) {
err = nil
}
if err != nil {
logger.Fatalf(ctx, "failed to find go command: %v", err)
}
var cmd *exec.Cmd
var out []byte
cmd = exec.CommandContext(ctx, epath, "mod", "edit", fmt.Sprintf("-require=%s@%s", path, mod.Version))
if out, err = cmd.CombinedOutput(); err != nil {
logger.Fatalf(ctx, "failed to run go mod edit: %s err: %v", out, err)
}
cmd = exec.CommandContext(ctx, epath, "mod", "tidy")
if out, err = cmd.CombinedOutput(); err != nil {
logger.Fatalf(ctx, "failed to run go mod tidy: %s err: %v", out, err)
}
if _, err = wtree.Add("go.mod"); err != nil {
logger.Fatalf(ctx, "failed to add file: %v", err)
}
if _, err = wtree.Add("go.sum"); err != nil {
logger.Fatalf(ctx, "failed to add file: %v", err)
}
if err = repo.Push(&git.PushOptions{Auth: &httpauth.BasicAuth{Username: envTOKEN, Password: envTOKEN}}); err != nil {
logger.Fatalf(ctx, "failed to push repo branch: %v", err)
}