Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ All notable changes to `src-cli` are documented in this file.

### Added

- EXPERIMENTAL: Templated campaign specs and file mounting. The campaign specs evaluated by `src campaign [preview|apply]` can now include template variables in `steps.run`, `steps.env`, and the new `steps.files` property, which allows users to create files inside the container in which the step is executed. The feature is marked as EXPERIMENTAL because it might change in the near future until we deem it non-experimental. See [#361](https://github.com/sourcegraph/src-cli/pull/361) for details.

### Changed

### Fixed
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions internal/campaigns/campaign_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type Step struct {
Run string `json:"run,omitempty" yaml:"run"`
Container string `json:"container,omitempty" yaml:"container"`
Env map[string]string `json:"env,omitempty" yaml:"env"`
Files map[string]string `json:"files,omitempty" yaml:"files,omitempty"`

image string
}
Expand Down
27 changes: 25 additions & 2 deletions internal/campaigns/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,24 @@ func TestExecutor_Integration(t *testing.T) {
executorTimeout: 100 * time.Millisecond,
wantErrInclude: "execution in github.com/sourcegraph/src-cli failed: Timeout reached. Execution took longer than 100ms.",
},
{
name: "templated",
repos: []*graphql.Repository{srcCLIRepo},
archives: []mockRepoArchive{
{repo: srcCLIRepo, files: map[string]string{
"README.md": "# Welcome to the README\n",
"main.go": "package main\n\nfunc main() {\n\tfmt.Println( \"Hello World\")\n}\n",
}},
},
steps: []Step{
{Run: `go fmt main.go`, Container: "doesntmatter:13"},
{Run: `touch modified-${{ join previous_step.modified_files " " }}.md`, Container: "alpine:13"},
{Run: `touch added-${{ join previous_step.added_files " " }}`, Container: "alpine:13"},
},
wantFilesChanged: map[string][]string{
srcCLIRepo.ID: []string{"main.go", "modified-main.go.md", "added-modified-main.go.md"},
},
},
}

for _, tc := range tests {
Expand Down Expand Up @@ -170,11 +188,16 @@ func TestExecutor_Integration(t *testing.T) {

diffsByName := map[string]*diff.FileDiff{}
for _, fd := range fileDiffs {
diffsByName[fd.OrigName] = fd
if fd.NewName == "/dev/null" {
diffsByName[fd.OrigName] = fd
} else {
diffsByName[fd.NewName] = fd
}
}

for _, file := range wantFiles {
if _, ok := diffsByName[file]; !ok {
t.Errorf("%s was not changed", file)
t.Errorf("%s was not changed (diffsByName=%#v)", file, diffsByName)
}
}
}
Expand Down
20 changes: 19 additions & 1 deletion internal/campaigns/graphql/repository.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package graphql

import "strings"
import (
"sort"
"strings"
)

const RepositoryFieldsFragment = `
fragment repositoryFields on Repository {
Expand Down Expand Up @@ -30,6 +33,8 @@ type Repository struct {
URL string
ExternalRepository struct{ ServiceType string }
DefaultBranch *Branch

FileMatches map[string]bool
}

func (r *Repository) BaseRef() string {
Expand All @@ -43,3 +48,16 @@ func (r *Repository) Rev() string {
func (r *Repository) Slug() string {
return strings.ReplaceAll(r.Name, "/", "-")
}

func (r *Repository) SearchResultPaths() (list fileMatchPathList) {
var files []string
for f := range r.FileMatches {
files = append(files, f)
}
sort.Strings(files)
return fileMatchPathList(files)
}

type fileMatchPathList []string

func (f fileMatchPathList) String() string { return strings.Join(f, " ") }
Loading