mageutil

package module
v0.0.0-...-0f1ff63 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

README

Mageutil

A collection of common helpers meant for use in magefiles.

Examples:

Single command

func Build() error {
    ctx := context.Background()
    return mageutil.RunDir(ctx, "cmd/server", "go build -o ../../bin/livekit-server")
}

Multiple commands

const gstVersion = 1.20.3

func BuildDocker(version string) error {
    return mageutil.Run(context.Background(),
        fmt.Sprintf("docker pull livekit/gstreamer:%s-dev", gstVersion),
        fmt.Sprintf("docker pull livekit/gstreamer:%s-prod", gstVersion),
        fmt.Sprintf("docker build -t livekit/egress:v%s -f build/Dockerfile .", version),
    )
}

Updating repos

func BuildLivekit() error {
    ctx := context.Background()
	
    dir, err := filepath.Abs("..")
    if err != nil {
        return err
    }

    if err = mageutil.CloneRepo("livekit", "livekit", dir); err != nil {
        return err
    }
    
    dir, err = filepath.Abs("../livekit")
    if err != nil {
        return err
    }
	
    return mageutil.RunDir(ctx, dir, "mage build")
}

Tools

func Generate() error {
    ctx := context.Background()
    err := mageutil.InstallTool("github.com/google/wire/cmd/wire", "latest", false)
    if err != nil {
        return err
    }
    return mageutil.Run(ctx, "go generate ./...")
}

Group

func RunLivekitWithEgress() error {
    ctx := context.Background()
    group := mageutil.NewGroup(ctx)
    group.Go(func () error {
        return RunDir(ctx, "../livekit", "bin/livekit-server --dev")
    })
    group.Go(func () error {
        return Run(ctx, "docker run --rm -e EGRESS_CONFIG_FILE=/out/local.yaml -v ~/livekit/egress/test:/out livekit/egress")
    })
    group.Wait()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloneRepo

func CloneRepo(org, name string, basePath string, branch string) error

func Command

func Command(ctx context.Context, command string) *exec.Cmd

func CommandDir

func CommandDir(ctx context.Context, dir, command string) *exec.Cmd

func ConnectStd

func ConnectStd(cmd *exec.Cmd)

func GetPkgDir

func GetPkgDir(pkg string) (string, error)

func GetToolPath

func GetToolPath(name string) (string, error)

func InstallTool

func InstallTool(url, version string, force bool) error

func InstallTools

func InstallTools(tools map[string]string, force bool) error

func Out

func Out(ctx context.Context, command string) ([]byte, error)

func OutDir

func OutDir(ctx context.Context, dir, command string) ([]byte, error)

func Pipe

func Pipe(first, second string) error

func Run

func Run(ctx context.Context, commands ...string) error

func RunDir

func RunDir(ctx context.Context, dir string, commands ...string) error

func UpdateRepo

func UpdateRepo(name string, basePath string, branch string) error

Types

type Checksummer

type Checksummer struct {
	IgnoredPaths []string
	// contains filtered or unexported fields
}

A helper checksum library that generates a fast, non-portable checksum over a directory of files it's designed as a quick way to bypass

func NewChecksummer

func NewChecksummer(dir string, checksumfile string, exts ...string) *Checksummer

func (*Checksummer) IsChanged

func (c *Checksummer) IsChanged() bool

func (*Checksummer) ReadChecksum

func (c *Checksummer) ReadChecksum() (string, error)

func (*Checksummer) WriteChecksum

func (c *Checksummer) WriteChecksum() error

type Group

type Group struct {
	*errgroup.Group
	// contains filtered or unexported fields
}

func NewGroup

func NewGroup(ctx context.Context) (*Group, context.Context)

func (*Group) Cancel

func (g *Group) Cancel()

func (*Group) Wait

func (g *Group) Wait() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL