Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2023-08-19 17:33:25 +03:00
parent 59e28e5a86
commit 16b38a5578
8 changed files with 15 additions and 170 deletions

View File

@ -3,6 +3,7 @@ package main
import (
"context"
"crypto/tls"
"embed"
"net/http"
"time"
@ -40,6 +41,10 @@ var (
AppVersion string = "latest" // filled when build
)
//go:generate cp -vr ../../ui/dist/ui assets/
//go:embed assets/*
var assets embed.FS
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

View File

@ -1,163 +0,0 @@
package main
import (
"context"
"flag"
"fmt"
"git.unistack.org/unistack-org/pkgdash/internal"
"io"
"net/url"
"os"
"sort"
"strings"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/filemode"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/go-git/go-git/v5/storage/memory"
flagconfig "go.unistack.org/micro-config-flag/v4"
"go.unistack.org/micro/v4/config"
"go.unistack.org/micro/v4/logger"
"golang.org/x/mod/modfile"
"golang.org/x/mod/module"
)
type Config struct {
Action string `flag:"name=action,desc='action to run',default='add'"`
Url string `flag:"name=url,desc='url or repo',default=''"`
CheckInterval string `default:"*/10 * * * *"`
}
func main() {
var err error
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cfg := &Config{}
if err = config.Load(ctx, []config.Config{
config.NewConfig(config.Struct(cfg)),
flagconfig.NewConfig(config.Struct(cfg)),
}); err != nil {
logger.Fatal(ctx, err)
}
flagUrl := flag.Arg(0)
u, err := url.Parse(flagUrl)
if err != nil {
logger.Fatal(ctx, err)
}
var rev string
if idx := strings.Index(u.Path, "@"); idx > 0 {
rev = u.Path[idx+1:]
}
cloneOpts := &git.CloneOptions{
URL: flagUrl,
Progress: os.Stdout,
}
if len(rev) == 0 {
cloneOpts.SingleBranch = true
cloneOpts.Depth = 1
}
if err = cloneOpts.Validate(); err != nil {
logger.Fatal(ctx, err)
}
repo, err := git.CloneContext(ctx, memory.NewStorage(), nil, cloneOpts)
if err != nil {
logger.Fatal(ctx, err)
}
ref, err := repo.Head()
if err != nil {
logger.Fatalf(ctx, "failed to get head: %v", err)
}
commit, err := repo.CommitObject(ref.Hash())
if err != nil {
logger.Fatalf(ctx, "failed to get commit: %v", err)
}
tree, err := commit.Tree()
if err != nil {
logger.Fatal(ctx, err)
}
err = tree.Files().ForEach(func(file *object.File) error {
if file == nil {
return fmt.Errorf("file pointer is nil")
}
switch file.Mode {
case filemode.Regular:
if strings.HasSuffix(file.Name, "go.mod") {
mvs, err := Direct(file)
if err != nil {
return err
}
internal.Updates(internal.UpdateOptions{
Pre: false,
Major: false,
Cached: false,
Modules: mvs,
OnUpdate: func(u internal.Update) {
if u.Err != nil {
fmt.Fprintf(os.Stderr, "%s: failed: %v\n", u.Module.Path, u.Err)
} else {
fmt.Printf("%s current:%s => latest:%v\n", u.Module.Path, u.Module.Version, u.Version)
}
},
})
}
return nil
default:
return nil
}
})
if err != nil {
logger.Fatal(ctx, "failed to exctract file: %v", err)
}
}
func Direct(file *object.File) ([]module.Version, error) {
r, err := file.Reader()
if err != nil {
return nil, err
}
defer r.Close()
data, err := io.ReadAll(r)
if err != nil {
return nil, err
}
modfile, err := modfile.ParseLax("go.mod", data, nil)
if err != nil {
return nil, err
}
var mods []module.Version
for _, req := range modfile.Require {
// if !req.Indirect {
mods = append(mods, req.Mod)
//}
}
sort.Slice(mods, func(i, j int) bool {
return mods[i].Path < mods[j].Path
})
return mods, nil
}
/*
func Periodic(ctx context.Context, db *sqlx.DB) error {
db.
return nil
}
*/

1
go.mod
View File

@ -17,7 +17,6 @@ require (
go.unistack.org/micro-codec-yaml/v4 v4.0.0
go.unistack.org/micro-config-env/v4 v4.0.1
go.unistack.org/micro-config-file/v4 v4.0.1
go.unistack.org/micro-config-flag/v4 v4.0.2
go.unistack.org/micro-config-vault/v4 v4.0.2
go.unistack.org/micro-logger-zerolog/v4 v4.0.3
go.unistack.org/micro-meter-victoriametrics/v4 v4.0.1

2
go.sum
View File

@ -1073,8 +1073,6 @@ go.unistack.org/micro-config-env/v4 v4.0.1 h1:A7W+Xm4WEsN9O6isWncfwNWEUuSuCHgt+a
go.unistack.org/micro-config-env/v4 v4.0.1/go.mod h1:kJvyLrRbVRrsM1jTdl5lHy4u88PnlK2mskOZ3T57M/0=
go.unistack.org/micro-config-file/v4 v4.0.1 h1:J8CNyOvxfL4CnoL2xocvyWHo77UWF8wvH4To23E0gOA=
go.unistack.org/micro-config-file/v4 v4.0.1/go.mod h1:OSfm+CIjAgb0HRlXCZd0DUtDwV5zJKXMHduSiGsSY0M=
go.unistack.org/micro-config-flag/v4 v4.0.2 h1:qoDpT/H8a8TYZS9ucoNC0bLhNdp+UFlhnRWOuqIKAyo=
go.unistack.org/micro-config-flag/v4 v4.0.2/go.mod h1:s0AYvz8rRtMHG2tkXoSmF8xFuHG12x3v1NERdMHDdiQ=
go.unistack.org/micro-config-vault/v4 v4.0.2 h1:QhDdtVJhQYmJZqAhsLRdnDZSZSzBunWX9a5l/WNKWNY=
go.unistack.org/micro-config-vault/v4 v4.0.2/go.mod h1:0gWQVkncMwaG0wZPqC98HhS6AYOcXR0lmPG/roR6AcM=
go.unistack.org/micro-logger-zerolog/v4 v4.0.3 h1:ao6jGMo8jJG9WcOE738eqrWeabQaqpHMrLx+IniRDpI=

View File

@ -1,3 +1,5 @@
//go:build ignore
package postgres
const (

View File

@ -1,3 +1,5 @@
//go:build ignore
package postgres
import (
@ -8,14 +10,14 @@ import (
"fmt"
"strings"
"git.unistack.org/unistack-org/pkgdash/internal/config"
"git.unistack.org/unistack-org/pkgdash/internal/models"
pb "git.unistack.org/unistack-org/pkgdash/proto"
"github.com/golang-migrate/migrate/v4"
mpgx "github.com/golang-migrate/migrate/v4/database/pgx"
"github.com/golang-migrate/migrate/v4/source/iofs"
"github.com/lib/pq"
"go.unistack.org/micro/v4/logger"
"git.unistack.org/unistack-org/pkgdash/internal/config"
"git.unistack.org/unistack-org/pkgdash/internal/models"
pb "git.unistack.org/unistack-org/pkgdash/proto"
)
const (

View File

@ -1,3 +1,5 @@
//go:build ignore
package postgres
import (

View File

@ -1,6 +1,6 @@
{
"name": "ui",
"version": "0.0.0",
"version": "0.0.1",
"scripts": {
"ng": "ng",
"start": "ng serve",