Run Test, then Build, then linter for now
build
Details
build
Details
This commit is contained in:
parent
b556c3c4be
commit
3b53f48024
|
@ -26,6 +26,10 @@ jobs:
|
||||||
uses: https://github.com/goreleaser/goreleaser-action@v2.7.0
|
uses: https://github.com/goreleaser/goreleaser-action@v2.7.0
|
||||||
with:
|
with:
|
||||||
install-only: true
|
install-only: true
|
||||||
|
- name: Test
|
||||||
|
run: go test -v -cover
|
||||||
|
- name: Build
|
||||||
|
run: goreleaser build --snapshot --rm-dist
|
||||||
- name: Go-linter
|
- name: Go-linter
|
||||||
# You may pin to the exact commit or the version.
|
# You may pin to the exact commit or the version.
|
||||||
# uses: Jerome1337/golint-action@c5d17206a0a436bbf1edb91e314ed084f7c57589
|
# uses: Jerome1337/golint-action@c5d17206a0a436bbf1edb91e314ed084f7c57589
|
||||||
|
@ -33,8 +37,4 @@ jobs:
|
||||||
#with:
|
#with:
|
||||||
# Path used by golint command
|
# Path used by golint command
|
||||||
# golint-path: # optional, default is ./...
|
# golint-path: # optional, default is ./...
|
||||||
- name: Build
|
|
||||||
run: goreleaser build --snapshot --rm-dist
|
|
||||||
- name: Test
|
|
||||||
run: go test -v -cover
|
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,11 @@ package protocoldb
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"os/user"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/go-git/go-git/v5"
|
"github.com/go-git/go-git/v5"
|
||||||
|
|
||||||
|
@ -26,15 +27,13 @@ type ProtocolDatabaseProvider interface {
|
||||||
// Close closes a database (only internal flag set)
|
// Close closes a database (only internal flag set)
|
||||||
Close() error
|
Close() error
|
||||||
// Protocols returns the content of the database as map, an error if the first read of the database failed
|
// Protocols returns the content of the database as map, an error if the first read of the database failed
|
||||||
Protocols() (map[string]protocol.DOPMeta, error)
|
Protocols() ([]DatabaseEntry, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProtocolDatabaseManager is a complex protocol database interface, which allows adding, updating and refreshing of the content
|
// ProtocolDatabaseManager is a complex protocol database interface, which allows adding, updating and refreshing of the content
|
||||||
type ProtocolDatabaseManager interface {
|
type ProtocolDatabaseManager interface {
|
||||||
Add(prot *protocol.ProtocolStructure) error
|
Add(prot *protocol.ProtocolStructure) error
|
||||||
AddFile(path string) error
|
|
||||||
Update(prot *protocol.ProtocolStructure) error
|
Update(prot *protocol.ProtocolStructure) error
|
||||||
UpdateFile(path string) error
|
|
||||||
// no remove.
|
// no remove.
|
||||||
UpdateDatabase() error // scans for new protocols
|
UpdateDatabase() error // scans for new protocols
|
||||||
}
|
}
|
||||||
|
@ -45,6 +44,30 @@ type DatabaseEntry struct {
|
||||||
Protocol protocol.DOPMeta
|
Protocol protocol.DOPMeta
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Init initializes the databases, opens the default one and checks for others if available
|
||||||
|
func Init() *PPFDatabases {
|
||||||
|
// initialize main list
|
||||||
|
databases := PPFDatabases{[]ProtocolDatabaseProvider{}}
|
||||||
|
// initialize default db
|
||||||
|
user, err := user.Current()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Current user not obtainable: %s", err)
|
||||||
|
log.Fatal("Impossible to open default database")
|
||||||
|
}
|
||||||
|
pathlist := []string{user.HomeDir, ".config", "ppforge"}
|
||||||
|
fdb := FileDatabase{path.Join(pathlist...), map[string]DatabaseEntry{}, false}
|
||||||
|
fdb.Open(path.Join(pathlist...))
|
||||||
|
fdb.UpdateDatabase()
|
||||||
|
databases.Databases = append(databases.Databases, fdb)
|
||||||
|
log.Printf("Amount of databases available %d", len(databases.Databases))
|
||||||
|
return &databases
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get Retrieves the full set of databases
|
||||||
|
func (ppfdb *PPFDatabases) Get() []ProtocolDatabaseProvider {
|
||||||
|
return ppfdb.Databases
|
||||||
|
}
|
||||||
|
|
||||||
// Get a full protocol from a database entry
|
// Get a full protocol from a database entry
|
||||||
func (de *DatabaseEntry) Get() (*protocol.ProtocolStructure, error) {
|
func (de *DatabaseEntry) Get() (*protocol.ProtocolStructure, error) {
|
||||||
return protocolctl.LoadNew(de.Path)
|
return protocolctl.LoadNew(de.Path)
|
||||||
|
@ -66,7 +89,7 @@ type FileDatabaseFromGitRemote struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open the database
|
// Open the database
|
||||||
func (fd *FileDatabase) Open(path string) error {
|
func (fd FileDatabase) Open(path string) error {
|
||||||
fileinfo, err := os.Stat(path)
|
fileinfo, err := os.Stat(path)
|
||||||
if err == os.ErrNotExist {
|
if err == os.ErrNotExist {
|
||||||
return err
|
return err
|
||||||
|
@ -80,7 +103,7 @@ func (fd *FileDatabase) Open(path string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the database and free the data
|
// Close the database and free the data
|
||||||
func (fd *FileDatabase) Close() error {
|
func (fd FileDatabase) Close() error {
|
||||||
for k := range fd.protocols {
|
for k := range fd.protocols {
|
||||||
delete(fd.protocols, k)
|
delete(fd.protocols, k)
|
||||||
}
|
}
|
||||||
|
@ -89,7 +112,8 @@ func (fd *FileDatabase) Close() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Protocols returns the map of protocols or an error if the first read failed
|
// Protocols returns the map of protocols or an error if the first read failed
|
||||||
func (fd *FileDatabase) Protocols() (map[string]DatabaseEntry, error) {
|
func (fd FileDatabase) Protocols() ([]DatabaseEntry, error) {
|
||||||
|
entries := []DatabaseEntry{}
|
||||||
if !fd.closed && len(fd.protocols) == 0 {
|
if !fd.closed && len(fd.protocols) == 0 {
|
||||||
fd.protocols = map[string]DatabaseEntry{}
|
fd.protocols = map[string]DatabaseEntry{}
|
||||||
// recurse recursively through the path
|
// recurse recursively through the path
|
||||||
|
@ -98,7 +122,10 @@ func (fd *FileDatabase) Protocols() (map[string]DatabaseEntry, error) {
|
||||||
prot, err := protocolctl.LoadNew(path)
|
prot, err := protocolctl.LoadNew(path)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// add to map
|
// add to map
|
||||||
fd.protocols[prot.Metadata.Name] = DatabaseEntry{path, prot.Metadata}
|
entry := DatabaseEntry{path, prot.Metadata}
|
||||||
|
|
||||||
|
fd.protocols[prot.Metadata.Name] = entry
|
||||||
|
entries = append(entries, entry)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -107,7 +134,13 @@ func (fd *FileDatabase) Protocols() (map[string]DatabaseEntry, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fd.protocols, nil
|
if entries == nil || len(entries) == 0 {
|
||||||
|
entries = make([]DatabaseEntry, len(fd.protocols))
|
||||||
|
for _, v := range fd.protocols {
|
||||||
|
entries = append(entries, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return entries, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add puts a new protocol into the path of the file database
|
// Add puts a new protocol into the path of the file database
|
||||||
|
@ -120,20 +153,6 @@ func (fd *FileDatabase) Add(prot *protocol.ProtocolStructure) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddFile copies a external protocoljson file into the database directory and updates the internal data
|
|
||||||
func (fd *FileDatabase) AddFile(p string) error {
|
|
||||||
prot, err := protocolctl.LoadNew(p)
|
|
||||||
if err == nil {
|
|
||||||
if !strings.HasPrefix(p, fd.Path) {
|
|
||||||
// add it to the database if not existing there
|
|
||||||
fd.Add(prot)
|
|
||||||
}
|
|
||||||
p = path.Join(fd.Path, prot.Metadata.Name, ".protocoljson")
|
|
||||||
fd.protocols[prot.Metadata.Name] = DatabaseEntry{p, prot.Metadata}
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update updates an existing entry through saving the contents of the protocol to the file, or just adding it anew
|
// Update updates an existing entry through saving the contents of the protocol to the file, or just adding it anew
|
||||||
func (fd *FileDatabase) Update(prot *protocol.ProtocolStructure) error {
|
func (fd *FileDatabase) Update(prot *protocol.ProtocolStructure) error {
|
||||||
if v, ok := fd.protocols[prot.Metadata.Name]; ok {
|
if v, ok := fd.protocols[prot.Metadata.Name]; ok {
|
||||||
|
@ -143,18 +162,6 @@ func (fd *FileDatabase) Update(prot *protocol.ProtocolStructure) error {
|
||||||
return fd.Add(prot)
|
return fd.Add(prot)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateFile simply adds a file if it is outside the database, or updates the internal storage with the contents of the file
|
|
||||||
func (fd *FileDatabase) UpdateFile(p string) error {
|
|
||||||
if !strings.HasPrefix(p, fd.Path) {
|
|
||||||
return fd.AddFile(p)
|
|
||||||
}
|
|
||||||
prot, err := protocolctl.LoadNew(p)
|
|
||||||
if err == nil {
|
|
||||||
fd.protocols[prot.Metadata.Name] = DatabaseEntry{p, prot.Metadata}
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateDatabase just rereads all files
|
// UpdateDatabase just rereads all files
|
||||||
func (fd *FileDatabase) UpdateDatabase() error {
|
func (fd *FileDatabase) UpdateDatabase() error {
|
||||||
// recurse recursively through the path
|
// recurse recursively through the path
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
package protocoldb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test(t *testing.T) {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
{}
|
Loading…
Reference in New Issue