-
Notifications
You must be signed in to change notification settings - Fork 18
/
uploadcaches.go
67 lines (55 loc) · 1.58 KB
/
uploadcaches.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package command
import (
"fmt"
"github.com/cirruslabs/cirrus-ci-agent/api"
"github.com/cirruslabs/cirrus-cli/pkg/parser/node"
"github.com/cirruslabs/cirrus-cli/pkg/parser/schema"
jsschema "github.com/lestrrat-go/jsschema"
)
func UploadCachesHelper(
env map[string]string,
previousCommands []*api.Command,
node *node.Node,
) ([]*api.Command, error) {
var result []*api.Command
cacheNames, err := node.GetSliceOfExpandedStrings(env)
if err != nil {
return nil, err
}
for _, cacheName := range cacheNames {
var isCacheNameDefined bool
for _, command := range previousCommands {
if command.Name == cacheName {
isCacheNameDefined = true
break
}
}
if !isCacheNameDefined {
return nil, node.ParserError("no cache with name %q is defined", cacheName)
}
var hasCacheUploadCommand bool
cacheUploadCommandName := fmt.Sprintf("Upload '%s' cache", cacheName)
for _, command := range previousCommands {
if command.Name == cacheUploadCommandName {
hasCacheUploadCommand = true
break
}
}
if hasCacheUploadCommand {
return nil, node.ParserError("the cache with name %q is already scheduled to be uploaded in one "+
"of the previous upload_caches instructions", cacheUploadCommandName)
}
result = append(result, &api.Command{
Name: cacheUploadCommandName,
Instruction: &api.Command_UploadCacheInstruction{
UploadCacheInstruction: &api.UploadCacheInstruction{
CacheName: cacheName,
},
},
})
}
return result, nil
}
func UploadCachesSchema() *jsschema.Schema {
return schema.ArrayOf(schema.String("Cache name to upload."))
}