Skip to content

Commit 6291577

Browse files
authored
Fix "file not found" errors by fixing rendering of steps.files (#464)
1 parent b192404 commit 6291577

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ All notable changes to `src-cli` are documented in this file.
2121
### Fixed
2222

2323
- When `docker` becomes unresponsive `src campaign [apply|preview]` would get stuck and ignore Ctrl-C signals. That is now fixed.
24+
- The `steps.files` attributes in campaign specs have been broken since 3.23.2 and now work again.
2425

2526
### Removed
2627

internal/campaigns/templating.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func parseAsTemplate(name, input string, stepCtx *StepContext) (*template.Templa
2727
func renderStepMap(m map[string]string, stepCtx *StepContext) (map[string]string, error) {
2828
rendered := make(map[string]string, len(m))
2929

30-
for k, v := range rendered {
30+
for k, v := range m {
3131
var out bytes.Buffer
3232

3333
if err := renderStepTemplate(k, v, &out, stepCtx); err != nil {

internal/campaigns/templating_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,50 @@ ${{ step.stderr}}
188188
}
189189
}
190190

191+
func TestRenderStepMap(t *testing.T) {
192+
stepCtx := &StepContext{
193+
PreviousStep: StepResult{
194+
files: &StepChanges{
195+
Modified: []string{"go.mod"},
196+
Added: []string{"main.go.swp"},
197+
Deleted: []string{".DS_Store"},
198+
Renamed: []string{"new-filename.txt"},
199+
},
200+
Stdout: bytes.NewBufferString("this is previous step's stdout"),
201+
Stderr: bytes.NewBufferString("this is previous step's stderr"),
202+
},
203+
Outputs: map[string]interface{}{},
204+
Repository: graphql.Repository{
205+
Name: "github.com/sourcegraph/src-cli",
206+
FileMatches: map[string]bool{
207+
"README.md": true,
208+
"main.go": true,
209+
},
210+
},
211+
}
212+
213+
input := map[string]string{
214+
"/tmp/my-file.txt": `${{ previous_step.modified_files }}`,
215+
"/tmp/my-other-file.txt": `${{ previous_step.added_files }}`,
216+
"/tmp/my-other-file2.txt": `${{ previous_step.deleted_files }}`,
217+
}
218+
219+
have, err := renderStepMap(input, stepCtx)
220+
if err != nil {
221+
t.Fatalf("unexpected error: %s", err)
222+
}
223+
224+
want := map[string]string{
225+
"/tmp/my-file.txt": "[go.mod]",
226+
"/tmp/my-other-file.txt": "[main.go.swp]",
227+
"/tmp/my-other-file2.txt": "[.DS_Store]",
228+
}
229+
230+
if diff := cmp.Diff(want, have); diff != "" {
231+
t.Fatalf("wrong output:\n%s", diff)
232+
}
233+
}
234+
191235
func TestRenderChangesetTemplateField(t *testing.T) {
192236
// To avoid bugs due to differences between test setup and actual code, we
193237
// do the actual parsing of YAML here to get an interface{} which we'll put

0 commit comments

Comments
 (0)