-
Notifications
You must be signed in to change notification settings - Fork 1
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
13 changed files
with
176 additions
and
95 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM golang:1.20.5 as builder | ||
FROM golang:1.20.7 as builder | ||
|
||
|
||
WORKDIR /multiversx | ||
|
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
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,44 @@ | ||
package configs | ||
|
||
import ( | ||
"io" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
func copyFolderWithAllFiles(src, dst string) error { | ||
return filepath.Walk(src, func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
relPath, err := filepath.Rel(src, path) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if info.IsDir() { | ||
return os.MkdirAll(filepath.Join(dst, relPath), info.Mode()) | ||
} | ||
|
||
in, err := os.Open(path) | ||
if err != nil { | ||
return err | ||
} | ||
defer func() { | ||
_ = in.Close() | ||
}() | ||
|
||
out, err := os.Create(filepath.Join(dst, relPath)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = io.Copy(out, in) | ||
if err != nil { | ||
_ = out.Close() | ||
return err | ||
} | ||
|
||
return out.Close() | ||
}) | ||
} |
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,44 @@ | ||
package configs | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestCopyFolderWithAllFiles(t *testing.T) { | ||
src := t.TempDir() | ||
dst := t.TempDir() | ||
|
||
var err error | ||
files := []string{"file1.txt", "file2.txt", "dir/file3.txt"} | ||
for _, file := range files { | ||
path := filepath.Join(src, file) | ||
err = os.MkdirAll(filepath.Dir(path), 0755) | ||
require.Nil(t, err) | ||
|
||
err = os.WriteFile(path, []byte("Hello, World!"), 0644) | ||
require.Nil(t, err) | ||
} | ||
|
||
err = copyFolderWithAllFiles(src, dst) | ||
require.Nil(t, err) | ||
|
||
for _, file := range files { | ||
_, err = os.Stat(filepath.Join(dst, file)) | ||
if os.IsNotExist(err) { | ||
t.Errorf("file %s was not copied", file) | ||
} else if err != nil { | ||
t.Error(err) | ||
} | ||
} | ||
} | ||
|
||
func TestCopyFolderWithAllFilesNonExistentSrc(t *testing.T) { | ||
dst := t.TempDir() | ||
|
||
err := copyFolderWithAllFiles("/path/to/non/existent/directory", dst) | ||
require.NotNil(t, err) | ||
} |
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,37 @@ | ||
package git | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
) | ||
|
||
type gitFetcher struct{} | ||
|
||
// NewGitFetcher will create a new instance of gitFetcher | ||
func NewGitFetcher() *gitFetcher { | ||
return &gitFetcher{} | ||
} | ||
|
||
// Clone will clone the provided git repository in the provided destination dir | ||
func (gf *gitFetcher) Clone(repoURL, destDir string) error { | ||
cmd := exec.Command("git", "clone", repoURL, destDir) | ||
res, err := cmd.CombinedOutput() | ||
if err != nil { | ||
return fmt.Errorf("%s-%s", string(res), err.Error()) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Checkout will checkout or commit hash from the provided repository directory | ||
func (gf *gitFetcher) Checkout(repoDir string, commitHashOrBranch string) error { | ||
cmd := exec.Command("git", "checkout", commitHashOrBranch) | ||
cmd.Dir = repoDir | ||
|
||
res, err := cmd.CombinedOutput() | ||
if err != nil { | ||
return fmt.Errorf("%s-%s", string(res), err.Error()) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.