MarshalWithFieldOrder marshals a map to YAML with fields in a specific order. This function ensures deterministic field ordering in the generated YAML by using yaml.MapSlice internally. Priority fields are emitted first in the order specified, then remaining fields are emitted alphabetically. This
(data map[string]any, priorityFields []string)
| 254 | // // permissions: ... |
| 255 | // // jobs: ... |
| 256 | func MarshalWithFieldOrder(data map[string]any, priorityFields []string) ([]byte, error) { |
| 257 | yamlLog.Printf("Marshaling YAML with field order: %d priority fields", len(priorityFields)) |
| 258 | |
| 259 | // Convert the map to an ordered MapSlice structure |
| 260 | orderedData := OrderMapFields(data, priorityFields) |
| 261 | |
| 262 | // Marshal the ordered data with proper options for GitHub Actions |
| 263 | return yaml.MarshalWithOptions(orderedData, DefaultMarshalOptions...) |
| 264 | } |
| 265 | |
| 266 | // OrderMapFields converts a map to yaml.MapSlice with fields in a specific order. |
| 267 | // |