-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d649596
commit ed99674
Showing
50 changed files
with
1,776 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Package taskdoc implements documentation rendering for tasks. | ||
// It is intended to be run via `go run`, passing a task YAML manifest | ||
// and a description in Asciidoctor format. The combined result will be | ||
// written to the specified destination. | ||
// | ||
// Example invocation: | ||
// | ||
// go run github.com/opendevstack/ods-pipeline/cmd/taskdoc \ | ||
// -task tasks/my-task.yaml \ | ||
// -description build/docs/my-task.adoc \ | ||
// -destination docs/my-task.adoc | ||
// | ||
// By default, taskdoc will use the template located at | ||
// docs/tasks/template.adoc.tmpl to produce the resulting file. Another | ||
// template can be specified via -template: | ||
// | ||
// go run github.com/opendevstack/ods-pipeline/cmd/taskdoc \ | ||
// -task tasks/my-task.yaml \ | ||
// -description build/docs/my-task.adoc \ | ||
// -template /path/to/my-custom-template.adoc.tmpl \ | ||
// -destination docs/my-task.adoc | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
"os" | ||
"text/template" | ||
|
||
"github.com/opendevstack/ods-pipeline/internal/projectpath" | ||
"github.com/opendevstack/ods-pipeline/pkg/taskdoc" | ||
) | ||
|
||
func main() { | ||
taskFile := flag.String("task", "", "Task manifest") | ||
descriptionFile := flag.String("description", "", "Description snippet") | ||
templateFile := flag.String("template", projectpath.RootedPath("docs/tasks/template.adoc.tmpl"), "Template file") | ||
destinationFile := flag.String("destination", "", "Destination file") | ||
flag.Parse() | ||
if err := render(*taskFile, *descriptionFile, *templateFile, *destinationFile); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func render(taskFile, descriptionFile, templateFile, destinationFile string) error { | ||
t, err := os.ReadFile(taskFile) | ||
if err != nil { | ||
return err | ||
} | ||
d, err := os.ReadFile(descriptionFile) | ||
if err != nil { | ||
return err | ||
} | ||
tmpl, err := template.ParseFiles(templateFile) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
task, err := taskdoc.ParseTask(t, d) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
w, err := os.Create(destinationFile) | ||
if err != nil { | ||
return err | ||
} | ||
return taskdoc.RenderTaskDocumentation(w, tmpl, task) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Package taskmanifest implements manifest rendering for tasks. | ||
// It is intended to be run via `go run`, passing a task YAML template | ||
// and data to be rendered. The combined result will be | ||
// written to the specified destination. The -data flag can be passed | ||
// multiple times and may specify any key-value combination, which can then | ||
// be consumed in the template through Go's text/template package. E.g. | ||
// passing -data Foo=bar will replace {{.Foo}} in the template with bar. | ||
// | ||
// Example invocation: | ||
// | ||
// go run github.com/opendevstack/ods-pipeline/cmd/taskmanifest \ | ||
// -data ImageRepository=ghcr.io/my-org/my-repo \ | ||
// -data Version=latest \ | ||
// -template build/tasks/my-task.yaml \ | ||
// -destination tasks/my-task.yaml | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"os" | ||
"strings" | ||
"text/template" | ||
|
||
"github.com/opendevstack/ods-pipeline/pkg/taskmanifest" | ||
"github.com/opendevstack/ods-pipeline/pkg/tektontaskrun" | ||
) | ||
|
||
func main() { | ||
templateFile := flag.String("template", "", "Template file") | ||
destinationFile := flag.String("destination", "", "Destination file") | ||
cc := tektontaskrun.NewClusterConfig() | ||
mf := &MapFlag{v: cc.DefaultTaskTemplateData()} | ||
flag.Var(mf, "data", "Key-value pairs") | ||
flag.Parse() | ||
if err := render(*templateFile, *destinationFile, mf.v); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func render(templateFile, destinationFile string, data map[string]string) error { | ||
tmpl, err := template.ParseFiles(templateFile) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
w, err := os.Create(destinationFile) | ||
if err != nil { | ||
return err | ||
} | ||
return taskmanifest.RenderTask(w, tmpl, data) | ||
} | ||
|
||
type MapFlag struct { | ||
v map[string]string | ||
} | ||
|
||
func (mf *MapFlag) String() string { | ||
return fmt.Sprintf("%v", mf.v) | ||
} | ||
func (mf *MapFlag) Set(v string) error { | ||
key, value, ok := strings.Cut(v, "=") | ||
if !ok { | ||
return fmt.Errorf("must have = sign") | ||
} | ||
mf.v[key] = value | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package odstasktest | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
// AssertFilesExist checks that all files named by wantFiles exist in wsDir. | ||
// Any files that do not exist will report a test error. | ||
func AssertFilesExist(t *testing.T, wsDir string, wantFiles ...string) { | ||
for _, wf := range wantFiles { | ||
filename := filepath.Join(wsDir, wf) | ||
if _, err := os.Stat(filename); os.IsNotExist(err) { | ||
t.Errorf("Want %s, but got nothing", filename) | ||
} | ||
} | ||
} | ||
|
||
// AssertFileContent checks that the file named by filename in the directory | ||
// wsDir has the exact context specified by want. | ||
func AssertFileContent(t *testing.T, wsDir, filename, want string) { | ||
got, err := getTrimmedFileContent(filepath.Join(wsDir, filename)) | ||
if err != nil { | ||
t.Errorf("get content of %s: %s", filename, err) | ||
return | ||
} | ||
if got != want { | ||
t.Errorf("got '%s', want '%s' in file %s", got, want, filename) | ||
} | ||
} | ||
|
||
func getTrimmedFileContent(filename string) (string, error) { | ||
content, err := os.ReadFile(filename) | ||
if err != nil { | ||
return "", err | ||
} | ||
return strings.TrimSpace(string(content)), nil | ||
} |
Oops, something went wrong.