Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save show_action result while download action #523

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 29 additions & 15 deletions go/pkg/tool/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ func (c *Client) writeProto(m proto.Message, baseName string) error {
// input tree, as an InputSpec proto file in text format. Will be omitted
// if no NodeProperties are defined.
func (c *Client) DownloadAction(ctx context.Context, actionDigest, outputPath string, overwrite bool) error {
resPb, err := c.getActionResult(ctx, actionDigest)
if err != nil {
return err
}
acDg, err := digest.NewFromString(actionDigest)
if err != nil {
return err
Expand Down Expand Up @@ -418,10 +422,21 @@ func (c *Client) DownloadAction(ctx context.Context, actionDigest, outputPath st
is.InputNodeProperties[path] = command.NodePropertiesFromAPI(t.NodeProperties)
}
}
if len(is.InputNodeProperties) == 0 {
return nil
if len(is.InputNodeProperties) != 0 {
err = c.writeProto(is, filepath.Join(outputPath, "input_node_properties.textproto"))
if err != nil {
return err
}
}
res, err := c.formatActionResStr(ctx, actionProto, resPb, commandProto, cmdDg)
ywmei-brt1 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return fmt.Errorf("error showing action %v: %v", outputPath, err)
ywmei-brt1 marked this conversation as resolved.
Show resolved Hide resolved
}
return c.writeProto(is, filepath.Join(outputPath, "input_node_properties.textproto"))
err = os.WriteFile(filepath.Join(outputPath, "show_action.txt"), []byte(res), 0644)
ywmei-brt1 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return fmt.Errorf("error dumping to show_action.txt] %v: %v", outputPath, err)
ywmei-brt1 marked this conversation as resolved.
Show resolved Hide resolved
}
return nil
}

func (c *Client) prepProtos(ctx context.Context, actionRoot string) (string, error) {
Expand Down Expand Up @@ -532,7 +547,6 @@ func (c *Client) ExecuteAction(ctx context.Context, actionDigest, actionRoot, ou

// ShowAction parses and displays an action with its corresponding command.
func (c *Client) ShowAction(ctx context.Context, actionDigest string) (string, error) {
var showActionRes bytes.Buffer
resPb, err := c.getActionResult(ctx, actionDigest)
if err != nil {
return "", err
Expand All @@ -546,35 +560,35 @@ func (c *Client) ShowAction(ctx context.Context, actionDigest string) (string, e
if _, err := c.GrpcClient.ReadProto(ctx, acDg, actionProto); err != nil {
return "", err
}

if actionProto.Timeout != nil {
timeout := actionProto.Timeout.AsDuration()
showActionRes.WriteString(fmt.Sprintf("Timeout: %s\n", timeout.String()))
}

commandProto := &repb.Command{}
cmdDg, err := digest.NewFromProto(actionProto.GetCommandDigest())
if err != nil {
return "", err
}
showActionRes.WriteString("Command\n=======\n")
showActionRes.WriteString(fmt.Sprintf("Command Digest: %v\n", cmdDg))

log.Infof("Reading command from action digest..")
if _, err := c.GrpcClient.ReadProto(ctx, cmdDg, commandProto); err != nil {
return "", err
}
return c.formatActionResStr(ctx, actionProto, resPb, commandProto, cmdDg)
}

func (c *Client) formatActionResStr(ctx context.Context, actionProto *repb.Action, resPb *repb.ActionResult, commandProto *repb.Command, cmdDg digest.Digest) (string, error) {
var showActionRes bytes.Buffer
if actionProto.Timeout != nil {
timeout := actionProto.Timeout.AsDuration()
showActionRes.WriteString(fmt.Sprintf("Timeout: %s\n", timeout.String()))
}
showActionRes.WriteString("Command\n=======\n")
showActionRes.WriteString(fmt.Sprintf("Command Digest: %v\n", cmdDg))
for _, ev := range commandProto.GetEnvironmentVariables() {
showActionRes.WriteString(fmt.Sprintf("\t%s=%s\n", ev.Name, ev.Value))
}
cmdStr := strings.Join(commandProto.GetArguments(), " ")
showActionRes.WriteString(fmt.Sprintf("\t%v\n", cmdStr))

showActionRes.WriteString("\nPlatform\n========\n")
for _, property := range commandProto.GetPlatform().GetProperties() {
showActionRes.WriteString(fmt.Sprintf("\t%s=%s\n", property.Name, property.Value))
}

showActionRes.WriteString("\nInputs\n======\n")
log.Infof("Fetching input tree from input root digest..")
inpTree, _, err := c.getInputTree(ctx, actionProto.GetInputRootDigest())
Expand Down
Loading