Skip to content

Commit

Permalink
Advanced architecture guessing (#586)
Browse files Browse the repository at this point in the history
* Advanced archiotecture guessing

Similar to platform guessing we can check if the instances has "Arm" in the type url.

Related to cirruslabs/cirrus-ci-docs#905 (comment)

* Use scaleway worker
  • Loading branch information
fkorotkov authored Nov 30, 2022
1 parent d4c853d commit 18ccee5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
3 changes: 1 addition & 2 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ task:
alias: Tests
persistent_worker:
labels:
os: darwin
tart: installed
name: scaleway-m1
env:
CIRRUS_INTERNAL_TART_VM: ghcr.io/cirruslabs/macos-monterey-vanilla:12.4
CIRRUS_INTERNAL_TART_SSH_PASSWORD: admin
Expand Down
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 18ccee5

Please sign in to comment.