-
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
1 parent
ad7af52
commit 234e28b
Showing
20 changed files
with
381 additions
and
88 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 was deleted.
Oops, something went wrong.
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,83 @@ | ||
package enginee2e | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"github.com/hephbuild/heph/internal/engine" | ||
"github.com/hephbuild/heph/internal/hartifact" | ||
pluginv1 "github.com/hephbuild/heph/plugin/gen/heph/plugin/v1" | ||
"github.com/hephbuild/heph/plugin/pluginexec" | ||
"github.com/hephbuild/heph/plugin/pluginstaticprovider" | ||
"github.com/stretchr/testify/require" | ||
"google.golang.org/protobuf/types/known/structpb" | ||
) | ||
|
||
func TestHashDeps(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
dir, err := os.MkdirTemp("", "") | ||
require.NoError(t, err) | ||
defer os.RemoveAll(dir) | ||
|
||
e, err := engine.New(ctx, dir, engine.Config{}) | ||
require.NoError(t, err) | ||
|
||
staticprovider := pluginstaticprovider.NewFunc(func() []pluginstaticprovider.Target { | ||
return []pluginstaticprovider.Target{ | ||
{ | ||
Spec: &pluginv1.TargetSpec{ | ||
Ref: &pluginv1.TargetRef{ | ||
Package: "some/package", | ||
Name: "sometarget", | ||
Driver: "sh", | ||
}, | ||
Config: map[string]*structpb.Value{ | ||
"run": newValueMust([]any{`echo hello > out`}), | ||
"out": newValueMust([]any{"out"}), | ||
"runtime_env": newValueMust(map[string]any{ | ||
"VAR1": time.Now().String(), | ||
}), | ||
}, | ||
}, | ||
}, | ||
} | ||
}) | ||
|
||
_, err = e.RegisterProvider(ctx, staticprovider) | ||
require.NoError(t, err) | ||
|
||
_, err = e.RegisterDriver(ctx, pluginexec.NewSh(), nil) | ||
require.NoError(t, err) | ||
|
||
var at time.Time | ||
{ | ||
ch := e.Result(ctx, "some/package", "sometarget", []string{""}, engine.ResultOptions{}) | ||
|
||
res := <-ch | ||
require.NoError(t, res.Err) | ||
|
||
require.Len(t, res.Artifacts, 2) | ||
|
||
m, err := hartifact.ManifestFromArtifact(ctx, res.Artifacts[1].Artifact) | ||
require.NoError(t, err) | ||
|
||
at = m.CreatedAt | ||
} | ||
|
||
{ | ||
ch := e.Result(ctx, "some/package", "sometarget", []string{""}, engine.ResultOptions{}) | ||
|
||
res := <-ch | ||
require.NoError(t, res.Err) | ||
|
||
require.Len(t, res.Artifacts, 2) | ||
|
||
m, err := hartifact.ManifestFromArtifact(ctx, res.Artifacts[1].Artifact) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, at, m.CreatedAt) | ||
} | ||
} |
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,93 @@ | ||
package hartifact | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"io" | ||
"os" | ||
"time" | ||
|
||
"github.com/hephbuild/heph/internal/hfs" | ||
|
||
pluginv1 "github.com/hephbuild/heph/plugin/gen/heph/plugin/v1" | ||
) | ||
|
||
var ManifestName = "manifest.v1.json" | ||
|
||
type ManifestArtifact struct { | ||
Hashout string | ||
|
||
Group string | ||
Name string | ||
Type pluginv1.Artifact_Type | ||
Encoding pluginv1.Artifact_Encoding | ||
} | ||
|
||
type Manifest struct { | ||
Version string | ||
CreatedAt time.Time | ||
Hashin string | ||
Artifacts []ManifestArtifact | ||
} | ||
|
||
func (m Manifest) GetArtifacts(output string) []ManifestArtifact { | ||
a := make([]ManifestArtifact, 0) | ||
for _, artifact := range m.Artifacts { | ||
if artifact.Group != output { | ||
continue | ||
} | ||
|
||
a = append(a, artifact) | ||
} | ||
|
||
return a | ||
} | ||
|
||
func NewManifestArtifact(fs hfs.FS, m Manifest) (*pluginv1.Artifact, error) { | ||
b, err := json.Marshal(m) //nolint:musttag | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
err = hfs.WriteFile(fs, ManifestName, b, os.ModePerm) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &pluginv1.Artifact{ | ||
Name: ManifestName, | ||
Type: pluginv1.Artifact_TYPE_MANIFEST_V1, | ||
Encoding: pluginv1.Artifact_ENCODING_NONE, | ||
Uri: "file://" + hfs.At(fs, ManifestName).Path(), | ||
}, nil | ||
} | ||
|
||
func ManifestFromArtifact(ctx context.Context, a *pluginv1.Artifact) (Manifest, error) { | ||
r, err := Reader(ctx, a) | ||
if err != nil { | ||
return Manifest{}, err | ||
} | ||
defer r.Close() | ||
|
||
return openManifest(r) | ||
} | ||
|
||
func ManifestFromFS(fs hfs.FS) (Manifest, error) { | ||
f, err := hfs.Open(fs, ManifestName) | ||
if err != nil { | ||
return Manifest{}, err | ||
} | ||
defer f.Close() | ||
|
||
return openManifest(f) | ||
} | ||
|
||
func openManifest(r io.Reader) (Manifest, error) { | ||
var manifest Manifest | ||
err := json.NewDecoder(r).Decode(&manifest) //nolint:musttag | ||
if err != nil { | ||
return Manifest{}, err | ||
} | ||
|
||
return manifest, nil | ||
} |
Oops, something went wrong.