bitrise-io/bitrise-workflow-editor

Don't reformat and reorder the entire bitrise.yml file

GrahamBorland opened this issue · 2 comments

When you save a file using the offline workflow editor, it reformats and reorders everything in the file. It gives completely different output from the online version of the editor at https://app.bitrise.io/.

This makes it impossible to do a meaningful code-review of the changes you make.

We have to use the offline editor to make changes to our bitrise.yml on a branch, to be reviewed and merged in a PR. The online editor only works on the repo's default branch which is why we can't use it.

For example, here's the result of taking a file which was originally generated by the online editor, and then making a tiny change in the offline editor.

It's reformatted and reordered EVERYTHING.

image

tiwoc commented

The root cause for this seems to be that the GET /api/bitrise-yml.json endpoint of the local API server doesn't do a YAML to JSON conversion but parses the data into a models.BitriseDataModel structure which it then serializes to JSON.

var yamlContObj models.BitriseDataModel
if err := yaml.Unmarshal([]byte(contStr), &yamlContObj); err != nil {
log.Errorf("Failed to parse the content of bitrise.yml file (invalid YML), error: %s", err)
RespondWithJSONBadRequestErrorMessage(w, "Failed to parse the content of bitrise.yml file (invalid YML), error: %s", err)
return
}

The order of the fields inside the BitriseDataModel is not the same as the one that's used for the Bitrise production server.

type BitriseDataModel struct {
FormatVersion string `json:"format_version" yaml:"format_version"`
DefaultStepLibSource string `json:"default_step_lib_source,omitempty" yaml:"default_step_lib_source,omitempty"`
ProjectType string `json:"project_type" yaml:"project_type"`
//
Title string `json:"title,omitempty" yaml:"title,omitempty"`
Summary string `json:"summary,omitempty" yaml:"summary,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
//
App AppModel `json:"app,omitempty" yaml:"app,omitempty"`
Meta map[string]interface{} `json:"meta,omitempty" yaml:"meta,omitempty"`
TriggerMap TriggerMapModel `json:"trigger_map,omitempty" yaml:"trigger_map,omitempty"`
Pipelines map[string]PipelineModel `json:"pipelines,omitempty" yaml:"pipelines,omitempty"`
Stages map[string]StageModel `json:"stages,omitempty" yaml:"stages,omitempty"`
Workflows map[string]WorkflowModel `json:"workflows,omitempty" yaml:"workflows,omitempty"`
}

Two ways out of this situation that come to mind:

  • Convert YAML directly to JSON, or
  • reorder the fields inside BitriseDataModel and its substructures to match whatever the prod server does.

We recently ran into this issue as well. Some of our devs use the editor on bitrise.io and others run the editor locally. This usually causes large and messy diffs when committing the yml file back to our repo.