-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
230 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,5 +16,5 @@ func TestLoadConfig(t *testing.T) { | |
} | ||
|
||
func TestConfigCanBeMarchaled(t *testing.T) { | ||
|
||
// t.Fail() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ services: | |
echo 2 | ||
test: | | ||
echo "also testing" | ||
false | ||
another_command: | | ||
echo "Just some other command" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package dirhash | ||
|
||
import ( | ||
"bufio" | ||
"crypto" | ||
"crypto/md5" | ||
"io" | ||
"io/fs" | ||
"log" | ||
"os" | ||
"sort" | ||
) | ||
|
||
func HashDir(path string, ignore []string) (string, error) { | ||
files, err := os.ReadDir(path) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
if _, err := os.Stat(path + "/.gitignore"); !os.IsNotExist(err) { | ||
ReadIgnore(path+"/.gitignore", &ignore) | ||
} | ||
|
||
filtered := make([]fs.DirEntry, 0) | ||
for _, de := range files { | ||
deName := de.Name() | ||
isIgnored := false | ||
for _, v := range ignore { | ||
if deName == v { | ||
isIgnored = true | ||
} | ||
} | ||
|
||
if !isIgnored { | ||
filtered = append(filtered, de) | ||
} | ||
} | ||
files = filtered | ||
|
||
sort.SliceStable(files, func(i, j int) bool { | ||
return files[i].Name() > files[j].Name() | ||
}) | ||
|
||
hashArray := make([]string, 0) | ||
|
||
for _, de := range files { | ||
p := path + string(os.PathSeparator) + de.Name() | ||
if de.IsDir() { | ||
newIgnore := make([]string, 0) | ||
copy(newIgnore, ignore) | ||
hash, err := HashDir(p, newIgnore) | ||
if err != nil { | ||
panic(err) | ||
} | ||
hashArray = append(hashArray, hash) | ||
} else { | ||
hash, err := HashFile(p) | ||
if err != nil { | ||
panic(err) | ||
} | ||
hashArray = append(hashArray, hash) | ||
} | ||
} | ||
|
||
hash := crypto.SHA256.New() | ||
hash.Write([]byte(path)) | ||
for _, v := range hashArray { | ||
_, err := hash.Write([]byte(v)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
res := string(hash.Sum(nil)) | ||
|
||
// return it | ||
|
||
return res, nil | ||
} | ||
|
||
func HashFile(path string) (string, error) { | ||
file, err := os.Open(path) | ||
if err != nil { | ||
return "", err | ||
} | ||
defer file.Close() | ||
|
||
hash := md5.New() | ||
_, err = io.Copy(hash, file) | ||
if err != nil { | ||
return "", err | ||
} | ||
sum := string(hash.Sum(nil)) | ||
|
||
return sum, nil | ||
} | ||
|
||
func ReadIgnore(path string, ignore *[]string) error { | ||
if ignore == nil { | ||
panic("ignore slice is empty") | ||
} | ||
file, err := os.Open(path) | ||
if err != nil { | ||
return err | ||
} | ||
defer file.Close() | ||
|
||
scanner := bufio.NewScanner(file) | ||
for scanner.Scan() { | ||
*ignore = append(*ignore, scanner.Text()) | ||
} | ||
|
||
if err := scanner.Err(); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package dirhash | ||
|
||
import ( | ||
"fmt" | ||
"optimus/utils" | ||
"testing" | ||
) | ||
|
||
func TestDirHash(t *testing.T) { | ||
s, err := HashDir(utils.ProjectRoot(), make([]string, 0)) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
fmt.Println(s) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package dirhash | ||
|
||
import ( | ||
"fmt" | ||
"optimus/utils" | ||
"testing" | ||
) | ||
|
||
func TestReadIgnore(t *testing.T) { | ||
ignores := make([]string, 0) | ||
err := ReadIgnore(utils.ProjectRoot()+"/.gitignore", &ignores) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
fmt.Println(ignores) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package lockfile | ||
|
||
import "optimus/utils" | ||
|
||
type Lockfile struct { | ||
ProjectHash string | ||
Services []ServiceTestLock | ||
} | ||
|
||
type ServiceTestLock struct { | ||
Name string | ||
TestResult bool | ||
Hash string | ||
DependsOn []struct { | ||
Name string | ||
Hash string | ||
} | ||
} | ||
|
||
func LoadLockfile() Lockfile { | ||
_ = utils.ProjectRoot() | ||
|
||
return Lockfile{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters