2023-05-08 13:21:31 +00:00
|
|
|
package sdk
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"io"
|
2023-08-15 20:10:30 +00:00
|
|
|
"log/slog"
|
2023-05-08 13:21:31 +00:00
|
|
|
"time"
|
2023-08-15 19:46:02 +00:00
|
|
|
|
2023-08-17 15:04:58 +00:00
|
|
|
rpcv1 "code.icb4dc0.de/buildr/api/generated/rpc/v1"
|
2023-05-08 13:21:31 +00:00
|
|
|
)
|
|
|
|
|
2023-07-01 11:19:06 +00:00
|
|
|
type Category = rpcv1.Category
|
2023-05-08 13:21:31 +00:00
|
|
|
|
|
|
|
const (
|
2023-08-15 19:46:02 +00:00
|
|
|
CategoryTool = rpcv1.Category_CategoryTool
|
|
|
|
CategoryTask = rpcv1.Category_CategoryTask
|
|
|
|
CategoryBuild = rpcv1.Category_CategoryBuild
|
|
|
|
CategoryPackage = rpcv1.Category_CategoryPackage
|
2023-08-24 06:10:52 +00:00
|
|
|
CategoryRelease = rpcv1.Category_CategoryRelease
|
2023-05-08 13:21:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type StateMetadata struct {
|
|
|
|
ModifiedAt time.Time
|
|
|
|
TTL *time.Time
|
|
|
|
}
|
|
|
|
|
|
|
|
type ExecutionContext interface {
|
|
|
|
context.Context
|
|
|
|
WorkingDir() string
|
|
|
|
OutDir() string
|
|
|
|
BinariesDir() string
|
|
|
|
StdOut() io.Writer
|
|
|
|
StdErr() io.Writer
|
|
|
|
Logger() *slog.Logger
|
|
|
|
GetState(ctx context.Context, key string) ([]byte, StateMetadata, error)
|
|
|
|
SetState(ctx context.Context, key string, value []byte) error
|
|
|
|
}
|
|
|
|
|
2023-08-15 19:46:02 +00:00
|
|
|
type TaskSpec[T Module] struct {
|
|
|
|
Module T
|
|
|
|
ModuleName string
|
|
|
|
Container *rpcv1.ContainerSpec
|
|
|
|
OutputDir string
|
|
|
|
}
|
|
|
|
|
2023-05-08 13:21:31 +00:00
|
|
|
type Module interface {
|
|
|
|
Execute(ctx ExecutionContext) error
|
|
|
|
Category() Category
|
|
|
|
Type() string
|
|
|
|
}
|
|
|
|
|
2023-07-01 11:19:06 +00:00
|
|
|
type Helper interface {
|
|
|
|
Help() Help
|
|
|
|
}
|
|
|
|
|
2023-05-08 13:21:31 +00:00
|
|
|
type BinaryNamer interface {
|
|
|
|
BinaryName() string
|
|
|
|
}
|
|
|
|
|
|
|
|
type ToolModule interface {
|
|
|
|
Module
|
|
|
|
BinaryNamer
|
|
|
|
}
|
|
|
|
|
|
|
|
type Factory interface {
|
|
|
|
Create() Module
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ Factory = (*ModuleFactoryFunc)(nil)
|
|
|
|
|
|
|
|
type ModuleFactoryFunc func() Module
|
|
|
|
|
|
|
|
func (f ModuleFactoryFunc) Create() Module {
|
|
|
|
return f()
|
|
|
|
}
|