Skip to content

Commit

Permalink
Advanced archiotecture guessing
Browse files Browse the repository at this point in the history
Similar to platform guessing we can check if the instances has "Arm" in the type url.

Related to cirruslabs/cirrus-ci-docs#905 (comment)
  • Loading branch information
fkorotkov committed Nov 29, 2022
1 parent d4c853d commit 0b1999e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions pkg/parser/instance/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,18 @@ func GuessPlatformOfProtoMessage(message protoreflect.Message, descriptor protor
return ""
}

func GuessArchitectureOfProtoMessage(anyInstance *anypb.Any, descriptor protoreflect.MessageDescriptor) string {
message := dynamicpb.NewMessage(descriptor)
_ = proto.Unmarshal(anyInstance.GetValue(), message)
func GuessArchitecture(anyInstance *anypb.Any, descriptor protoreflect.MessageDescriptor) string {
instanceType := anyInstance.TypeUrl
if strings.Contains(instanceType, "Arm") {
return "arm64"
}

dynamicMessage := dynamicpb.NewMessage(descriptor)
_ = proto.Unmarshal(anyInstance.GetValue(), dynamicMessage)
return GuessArchitectureOfProtoMessage(dynamicMessage, descriptor)
}

func GuessArchitectureOfProtoMessage(message protoreflect.Message, descriptor protoreflect.MessageDescriptor) string {
fields := descriptor.Fields()
architectureField := fields.ByJSONName("architecture")
if architectureField != nil && message.Has(architectureField) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/parser/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func NewTask(
},
)
}
architecture := instance.GuessArchitectureOfProtoMessage(anyInstance, scopedDescriptor)
architecture := instance.GuessArchitecture(anyInstance, scopedDescriptor)
if architecture != "" {
task.proto.Environment = environment.Merge(
task.proto.Environment, map[string]string{
Expand Down

0 comments on commit 0b1999e

Please sign in to comment.