import "github.com/egdaemon/eg/runtime/x/wasi/egtarball"
Package egtarball basic functionality for creating tar balls. it proves the following functionality: - build deterministic paths to a directory for adding contents. - build dterministric archive names from patterns using information provided by the eg environment. - common patterns Assumptions: - tar/gh cli commands are available. - the archive patterns used are unique within the repository the workload is associated with. Compability guarentee: as long as you only use the functions provided by this package for accessing and generating the tarballs we'll ensure no breaking changes.
<a name="Archive"></a>
func Archive(pattern string) string
Return the path to the archive for the given pattern after Pack has been called.
<a name="EnvPattern"></a>
func EnvPattern(pattern string, env func(string) string) string
<a name="GitPattern"></a>
func GitPattern(prefix string) string
simple template for naming a tarball from git commit information. see eggit.commit.StringReplace for details.
<a name="Name"></a>
func Name(pattern string) string
replaces the substitution values within the pattern, resulting in the final resulting archive file's name.
<a name="Pack"></a>
func Pack(pattern string) eg.OpFn
create a tarball from the contents of the archive's folder.
<details><summary>Example</summary> <p>package main
import (
"context"
"log"
"github.com/egdaemon/eg/runtime/wasi/eg"
"github.com/egdaemon/eg/runtime/wasi/egenv"
"github.com/egdaemon/eg/runtime/wasi/shell"
"github.com/egdaemon/eg/runtime/x/wasi/egtarball"
)
func archive() string {
return egtarball.GitPattern("example")
}
func Pack(ctx context.Context, op eg.Op) error {
archive := egtarball.GitPattern("example")
return eg.Perform(
ctx,
egtarball.Pack(archive),
egtarball.SHA256Op(archive),
)
}
func Populate(ctx context.Context, _ eg.Op) error {
runtime := shell.Runtime().
Environ("CONTENT", egenv.EphemeralDirectory("example.txt")).
Environ("ARCHIVE", egtarball.Path(archive()))
return shell.Run(
ctx,
runtime.Newf("printf \"hello world\n\" | tee ${CONTENT}"),
runtime.Newf("cp ${CONTENT} ${ARCHIVE}"),
)
}
func main() {
var (
err error
)
ctx := context.Background()
err = eg.Perform(
ctx,
Populate,
Pack,
)
if err != nil {
log.Fatalln(err)
}
}
</p>
</details>
<a name="Path"></a>
func Path(pattern string) string
Path generate a unique directory for the contents that will be inside the archive can be placed.
<a name="SHA256"></a>
func SHA256(pattern string) string
Reads the cached sha256 from disk, if it cant locate it, recalculates and stores it. will panic if there is an issue calculating the sha256/persisting
<a name="SHA256Op"></a>
func SHA256Op(pattern string) eg.OpFn