-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
services_converter.go
36 lines (33 loc) · 1.06 KB
/
services_converter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package actionsdotnetactcompat
import (
"encoding/json"
"fmt"
"github.com/ChristopherHX/github-act-runner/protocol"
"github.com/nektos/act/pkg/model"
)
func ConvertServiceContainer(jobServiceContainers *protocol.TemplateToken) (map[string]*model.ContainerSpec, error) {
services := make(map[string]*model.ContainerSpec)
if jobServiceContainers != nil {
rawServiceContainer, ok := jobServiceContainers.ToRawObject().(map[interface{}]interface{})
if !ok {
return nil, fmt.Errorf("job service container is not nil, but also not a map")
}
for name, rawcontainer := range rawServiceContainer {
containerName, ok := name.(string)
if !ok {
return nil, fmt.Errorf("containername is not a string")
}
spec := &model.ContainerSpec{}
b, err := json.Marshal(toStringMap(rawcontainer))
if err != nil {
return nil, fmt.Errorf("failed to serialize ContainerSpec")
}
err = json.Unmarshal(b, &spec)
if err != nil {
return nil, fmt.Errorf("failed to deserialize ContainerSpec")
}
services[containerName] = spec
}
}
return services, nil
}