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

[CI-217] Step started event #825

Merged
merged 7 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
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
29 changes: 17 additions & 12 deletions cli/run_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"path/filepath"
"runtime"
"strconv"
"strings"
"time"

"github.com/bitrise-io/bitrise/analytics"
Expand Down Expand Up @@ -849,30 +850,34 @@ func activateAndRunSteps(
}

func logStepStarted(stepInfo stepmanModels.StepInfoModel, step stepmanModels.StepModel, idx int, stepExcutionId string, stepStartTime time.Time) {
idVersion := ""
if stepInfo.Step.Title != nil && *stepInfo.Step.Title != "" {
idVersion = *stepInfo.Step.Title
}

title := ""
if step.Title != nil {
title = *step.Title
}

params := log.StepStartedParams{
ExecutionId: stepExcutionId,
Position: idx,
IdVersion: idVersion,
Title: stepTitle(stepInfo, step),
Id: stepInfo.ID,
Version: stepInfo.Version,
Title: title,
Collection: stepInfo.Library,
Toolkit: toolkits.ToolkitForStep(step).ToolkitName(),
StartTime: stepStartTime.Format(time.RFC3339),
}
log.PrintStepStartedEvent(params)
}

func stepTitle(stepInfo stepmanModels.StepInfoModel, step stepmanModels.StepModel) string {
title := ""
if stepInfo.Step.Title != nil && *stepInfo.Step.Title != "" {
// At this point the title is either the overridden title from the bitrise.yml file or the composite step id.
title = *stepInfo.Step.Title
}

// The composite step id is not useful for the user. So let's replace it with the original step title defined in the step.yml file.
if strings.HasPrefix(title, stepInfo.ID) && step.Title != nil && *step.Title != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it working if the step ID composite has the collection part too?

  • git::<repo_utrl>
  • https://github.com/bitrise-io/bitrise-steplib.git::script@1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. Pushed a new commit with the updated logic.

title = *step.Title
}

return title
}

func prepareAnalyticsStepInfo(step stepmanModels.StepModel, stepInfoPtr stepmanModels.StepInfoModel) analytics.StepInfo {
return analytics.StepInfo{
StepID: stepInfoPtr.ID,
Expand Down
2 changes: 1 addition & 1 deletion log/event_print.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func generateStepStartedHeaderLines(params StepStartedParams) []string {

var lines []string
lines = append(lines, separator)
lines = append(lines, getHeaderTitle(params.Position, params.IdVersion))
lines = append(lines, getHeaderTitle(params.Position, params.Title))
lines = append(lines, separator)
lines = append(lines, getHeaderSubsection("id", params.Id))
lines = append(lines, getHeaderSubsection("version", params.Version))
Expand Down
11 changes: 4 additions & 7 deletions log/event_print_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ func TestStepHeaderPrinting(t *testing.T) {
params: StepStartedParams{
ExecutionId: "ExecutionId is not needed",
Position: 0,
IdVersion: "[email protected]",
Title: "[email protected]",
Id: "xcode-test",
Version: "4.1.2",
Title: "Title is not needed",
Collection: "Steplib",
Toolkit: "Go",
StartTime: "2022-10-19T10:28:33Z ",
Expand All @@ -47,17 +46,16 @@ func TestStepHeaderPrinting(t *testing.T) {
params: StepStartedParams{
ExecutionId: "random-uuid",
Position: 1,
IdVersion: "this-is-the-step-this-is-the-step-this-is-the-step-this-is-the-step-this-is-the-step-this-is-the-step-this-is-the-step-this-is-the-step@1",
Title: "Very long step name - Very long step name - Very long step name - Very long step name - Very long step name",
Id: "this-is-the-step-this-is-the-step-this-is-the-step-this-is-the-step-this-is-the-step-this-is-the-step-this-is-the-step-this-is-the-step",
Version: "1.1.2",
Title: "Very long step name - Very long step name - Very long step name - Very long step name - Very long step name",
Collection: "Steplib",
Toolkit: "Go",
StartTime: "Now",
},
expectedOutput: []string{
"+------------------------------------------------------------------------------+",
"| (1) this-is-the-step-this-is-the-step-this-is-the-step-this-is-the-step-t... |",
"| (1) Very long step name - Very long step name - Very long step name - Ver... |",
"+------------------------------------------------------------------------------+",
"| id: this-is-the-step-this-is-the-step-this-is-the-step-this-is-the-step-t... |",
"| version: 1.1.2 |",
Expand All @@ -73,10 +71,9 @@ func TestStepHeaderPrinting(t *testing.T) {
params: StepStartedParams{
ExecutionId: "another-random-uuid",
Position: 2,
IdVersion: "git::https://github.com/org/repo",
Title: "git::https://github.com/org/repo",
Id: "https://github.com/org/repo",
Version: "",
Title: "",
Collection: "Git",
Toolkit: "",
StartTime: "42",
Expand Down
3 changes: 1 addition & 2 deletions log/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ package log
type StepStartedParams struct {
ExecutionId string `json:"uuid"`
Position int `json:"idx"`
IdVersion string `json:"id_version"`
Title string `json:"title"`
Id string `json:"id"`
Version string `json:"version"`
Title string `json:"title"`
Collection string `json:"collection"`
Toolkit string `json:"toolkit"`
StartTime string `json:"-"` // This value is only needed for the console logging.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't we still need this for the log conversion (json->console)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No we do not because every json log will have a timestamp by default. We can use that time and print it as the step start time because the step execution starts after the step header is printed.

Expand Down
10 changes: 4 additions & 6 deletions log/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,28 @@ func TestStepStartedEventSerialisesToTheExpectedJsonMessage(t *testing.T) {
params: StepStartedParams{
ExecutionId: "ExecutionId",
Position: 0,
IdVersion: "IdVersion",
Title: "Title",
Id: "Id",
Version: "Version",
Title: "Title",
Collection: "Collection",
Toolkit: "Toolkit",
StartTime: "This is not needed",
},
expectedOutput: "{\"uuid\":\"ExecutionId\",\"idx\":0,\"id_version\":\"IdVersion\",\"id\":\"Id\",\"version\":\"Version\",\"title\":\"Title\",\"collection\":\"Collection\",\"toolkit\":\"Toolkit\"}",
expectedOutput: "{\"uuid\":\"ExecutionId\",\"idx\":0,\"title\":\"Title\",\"id\":\"Id\",\"version\":\"Version\",\"collection\":\"Collection\",\"toolkit\":\"Toolkit\"}",
},
{
name: "Empty fields are kept",
params: StepStartedParams{
ExecutionId: "ExecutionId",
Position: 0,
IdVersion: "IdVersion",
Title: "Title",
Id: "Id",
Version: "",
Title: "",
Collection: "Collection",
Toolkit: "",
StartTime: "",
},
expectedOutput: "{\"uuid\":\"ExecutionId\",\"idx\":0,\"id_version\":\"IdVersion\",\"id\":\"Id\",\"version\":\"\",\"title\":\"\",\"collection\":\"Collection\",\"toolkit\":\"\"}",
expectedOutput: "{\"uuid\":\"ExecutionId\",\"idx\":0,\"title\":\"Title\",\"id\":\"Id\",\"version\":\"\",\"collection\":\"Collection\",\"toolkit\":\"\"}",
},
}

Expand Down