Skip to content

Commit 587883d

Browse files
committed
WIP
1 parent 6bd2b69 commit 587883d

File tree

5 files changed

+43
-20
lines changed

5 files changed

+43
-20
lines changed

cmd/src/campaigns_common.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,15 @@ func campaignsExecute(ctx context.Context, out *output.Output, svc *campaigns.Se
237237
campaignsCompletePending(pending, "Resolved repositories")
238238
}
239239

240-
p := newCampaignProgressPrinter(out, opts.Parallelism)
241-
specs, err := svc.ExecuteCampaignSpec(ctx, repos, executor, campaignSpec, p.PrintStatuses)
240+
// p := newCampaignProgressPrinter(out, opts.Parallelism)
241+
// specs, err := svc.ExecuteCampaignSpec(ctx, repos, executor, campaignSpec, p.PrintStatuses)
242+
specs, err := svc.ExecuteCampaignSpec(ctx, repos, executor, campaignSpec, func(ts []*campaigns.TaskStatus) {
243+
fmt.Printf("len(ts)=%d\n", len(ts))
244+
})
242245
if err != nil {
243246
return "", "", err
244247
}
245-
p.Complete()
248+
// p.Complete()
246249

247250
if logFiles := executor.LogFiles(); len(logFiles) > 0 && flags.keepLogs {
248251
func() {

internal/campaigns/campaign_spec.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,18 @@ type OnQueryOrRepository struct {
6363
}
6464

6565
type Step struct {
66-
Run string `json:"run,omitempty" yaml:"run"`
67-
Container string `json:"container,omitempty" yaml:"container"`
68-
Env map[string]string `json:"env,omitempty" yaml:"env"`
69-
Files map[string]string `json:"files,omitempty" yaml:"files"`
66+
Run string `json:"run,omitempty" yaml:"run"`
67+
Container string `json:"container,omitempty" yaml:"container"`
68+
Env map[string]string `json:"env,omitempty" yaml:"env"`
69+
Files map[string]interface{} `json:"files,omitempty" yaml:"files"`
7070

7171
image string
7272
}
7373

74+
type StepLocalFileMount struct {
75+
FromFile string `json:"fromFile,omitempty"`
76+
}
77+
7478
func ParseCampaignSpec(data []byte) (*CampaignSpec, error) {
7579
var spec CampaignSpec
7680
if err := yaml.UnmarshalValidate(schema.CampaignSpecJSON, data, &spec); err != nil {

internal/campaigns/run_steps.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ func parseStepRun(run string, stepCtx *StepContext) (*template.Template, error)
330330
return template.New("step-run").Delims("${{", "}}").Funcs(stepCtx.ToFuncMap()).Parse(run)
331331
}
332332

333-
func parseStepFiles(specFilePath string, files map[string]string, stepCtx *StepContext) (map[string]string, error) {
333+
func parseStepFiles(specFilePath string, files map[string]interface{}, stepCtx *StepContext) (map[string]string, error) {
334334
containerFiles := make(map[string]string, len(files))
335335

336336
fnMap := stepCtx.ToFuncMap()
@@ -343,24 +343,28 @@ func parseStepFiles(specFilePath string, files map[string]string, stepCtx *StepC
343343
for fileName, fileRaw := range files {
344344
// If the file exists relative to the campaign spec, we read it and
345345
// mount it.
346-
localFileName := filepath.Join(basePath, fileRaw)
347-
ok, err := fileExists(localFileName)
348-
if err != nil {
349-
return containerFiles, err
350-
}
351-
if ok {
352-
content, err := ioutil.ReadFile(localFileName)
346+
fmt.Printf("fileraw=%T\n", fileRaw)
347+
if local, ok := fileRaw.(StepLocalFileMount); ok {
348+
fmt.Printf("local=%s\n", local)
349+
localFileName := filepath.Join(basePath, local.FromFile)
350+
ok, err := fileExists(localFileName)
353351
if err != nil {
354352
return containerFiles, err
355353
}
356-
containerFiles[fileName] = string(content)
357-
continue
354+
if ok {
355+
content, err := ioutil.ReadFile(localFileName)
356+
if err != nil {
357+
return containerFiles, err
358+
}
359+
containerFiles[fileName] = string(content)
360+
continue
361+
}
358362
}
359363
// Otherwise, we treat the file contents as a template and render it
360364
// into a buffer that we then mount into the code host.
361365
var out bytes.Buffer
362366

363-
tmpl, err := template.New(fileName).Delims("${{", "}}").Funcs(fnMap).Parse(fileRaw)
367+
tmpl, err := template.New(fileName).Delims("${{", "}}").Funcs(fnMap).Parse(fileRaw.(string))
364368
if err != nil {
365369
return containerFiles, err
366370
}

schema/campaign_spec.schema.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,13 @@
8484
},
8585
"files": {
8686
"type": "object",
87-
"description": "Files that should be mounted into or be created inside the Docker container."
87+
"description": "Files that should be mounted into or be created inside the Docker container.",
88+
"additionalProperties": {
89+
"oneOf": [
90+
{"type": "string"},
91+
{"type":"object", "additionalProperties": false, "properties": {"fromFile": {"type":"string"}}}
92+
]
93+
}
8894
}
8995
}
9096
}

schema/campaign_spec_stringdata.go

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)