Files
mesh-catalog/modules/mesh-build-image/cmd/mesh-build-image/steps.go
T

66 lines
3.1 KiB
Go

package main
// **The verb `steps`** (design 47 G §22, §307, §328): an image has no lint, unit or integration test step, so `steps`
// answers none for it and the seed has those steps `bypass` (*A module's registration*). The answer is the same for
// every fingerprint, so nothing is kept for it.
import (
"fmt"
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildimage"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/steprun"
stdio "git.novox.be/novox/mesh-sdk/go"
)
// StepsAnswer is what `steps` answers.
type StepsAnswer struct {
Artifact string `json:"artifact"`
Fingerprint string `json:"fingerprint,omitempty"`
Steps []seat.DetectedStep `json:"steps"`
// Dropped is the artifact a drop was recorded for; Error why a drop deleted nothing, naming the hand-act log.
Dropped string `json:"dropped,omitempty"`
Error string `json:"error,omitempty"`
}
// stepsTool is the seat's verb `steps`.
func (m *Module) stepsTool() stdio.Tool {
return stdio.Tool{Name: Seat + "." + seat.VerbSteps,
Description: "Which pipeline steps an image artifact can run: none (an image has no lint, unit or integration test step).",
Input: map[string]any{"type": "object", "required": []string{"module", "artifact"}, "properties": map[string]any{
"module": map[string]any{"type": "string"},
"artifact": map[string]any{"type": "string", "description": "the artifact reference, <module>:<artifact>"},
"fingerprint": map[string]any{"type": "string"},
"fetch": map[string]any{"type": "object", "description": "not read: an image's steps need no tree"},
"again": map[string]any{"type": "boolean", "description": "not read: the answer is the same anew"},
"drop": map[string]any{"type": "boolean", "description": "delete the artifact's kept key instead (an image keeps none); needs why, written in the hand-act log first"},
"why": map[string]any{"type": "string", "description": "with drop, why: a non-empty text"},
}},
Run: m.steps}
}
func (m *Module) steps(args map[string]any) (any, error) {
str := func(k string) string { s, _ := args[k].(string); return s }
if str("artifact") == "" || str("module") == "" {
return nil, fmt.Errorf("steps: the module and the artifact are asked")
}
if drop, _ := args["drop"].(bool); drop {
return m.dropDetected(args, stdio.CallerOf(args))
}
return StepsAnswer{Artifact: str("artifact"), Fingerprint: str("fingerprint"), Steps: []seat.DetectedStep{}}, nil
}
// dropDetected is `steps` with drop (§463, §480): the act is written in the hand-act log with the caller the bus proved;
// an image keeps no detected steps, so there is no key to delete.
func (m *Module) dropDetected(args map[string]any, caller string) (any, error) {
artifact, _ := args["artifact"].(string)
why, _ := args["why"].(string)
failed, err := steprun.DropDetected(artifact, why, caller, "", m.RecordAct, nil)
if err != nil {
return nil, err
}
if failed != "" {
return StepsAnswer{Artifact: artifact, Error: failed}, nil
}
return StepsAnswer{Artifact: artifact, Dropped: artifact}, nil
}