diff --git a/cmd/pagine/workflow.go b/cmd/pagine/workflow.go index fc69e78..227ab79 100644 --- a/cmd/pagine/workflow.go +++ b/cmd/pagine/workflow.go @@ -15,7 +15,7 @@ import ( ) func CollectAndRunWorkflows(root, dest *vfs.DirFS, jobBuilderRoot fs.StatFS) error { - bases, err := CollectWorkflows(root, dest) + bases, err := CollectWorkflows(root) if err != nil { return err } @@ -27,7 +27,16 @@ func CollectAndRunWorkflows(root, dest *vfs.DirFS, jobBuilderRoot fs.StatFS) err var workflows []*workflow.Workflow for _, base := range bases { - wf, err := config.LoadWorkflow(base, jobBuilderRoot) + origin, err := root.Chroot(base) + if err != nil { + return err + } + wfRoot, err := dest.Chroot(base) + if err != nil { + return err + } + + wf, err := config.LoadWorkflow(origin, wfRoot, jobBuilderRoot) if err != nil { return err } @@ -56,7 +65,7 @@ func CollectAndRunWorkflows(root, dest *vfs.DirFS, jobBuilderRoot fs.StatFS) err return nil } -func CollectWorkflows(root, dest *vfs.DirFS) (dirs []*vfs.DirFS, _ error) { +func CollectWorkflows(root *vfs.DirFS) (dirs []string, _ error) { return dirs, fs.WalkDir(root, "/", func(path string, _ fs.DirEntry, err error) error { if err != nil { return err @@ -67,12 +76,7 @@ func CollectWorkflows(root, dest *vfs.DirFS) (dirs []*vfs.DirFS, _ error) { return nil // Skip. } - sub, err := dest.Chroot(path) - if err != nil { - return err - } - - dirs = append(dirs, sub) + dirs = append(dirs, path) return nil }) diff --git a/config/workflow.go b/config/workflow.go index a85bd64..11bb514 100644 --- a/config/workflow.go +++ b/config/workflow.go @@ -25,29 +25,29 @@ type Workflow struct { } `yaml:"stage"` } -func LoadJob(root *vfs.DirFS, m map[string]any, jobBuilderRoot fs.StatFS) (*workflow.Job, error) { +func LoadJob(origin, root *vfs.DirFS, m map[string]any, jobBuilderRoot fs.StatFS) (*workflow.Job, error) { if m["type"] == nil { return nil, fmt.Errorf("job type is not specified") } jobBuilderFile := m["type"].(string) + ".tmpl" if jobBuilderRoot == nil { - return workflow.BuildJob(builtin.Builders, jobBuilderFile, root, m) + return workflow.BuildJob(builtin.Builders, jobBuilderFile, origin, root, m) } _, err := jobBuilderRoot.Stat(jobBuilderFile) switch { case err == nil: case os.IsNotExist(err): - return workflow.BuildJob(builtin.Builders, jobBuilderFile, root, m) + return workflow.BuildJob(builtin.Builders, jobBuilderFile, origin, root, m) default: return nil, err } - return workflow.BuildJob(jobBuilderRoot, jobBuilderFile, root, m) + return workflow.BuildJob(jobBuilderRoot, jobBuilderFile, origin, root, m) } -func LoadWorkflow(root *vfs.DirFS, jobBuilderRoot fs.StatFS) (*workflow.Workflow, error) { +func LoadWorkflow(origin, root *vfs.DirFS, jobBuilderRoot fs.StatFS) (*workflow.Workflow, error) { var ( rawWorkflow Workflow @@ -64,7 +64,7 @@ func LoadWorkflow(root *vfs.DirFS, jobBuilderRoot fs.StatFS) (*workflow.Workflow var jobs collection.Vector[*workflow.Job] for _, job := range stage.Job { - job, err := LoadJob(root, job, jobBuilderRoot) + job, err := LoadJob(origin, root, job, jobBuilderRoot) if err != nil { return nil, err } diff --git a/workflow/build.go b/workflow/build.go index df40416..e960e4e 100644 --- a/workflow/build.go +++ b/workflow/build.go @@ -15,7 +15,7 @@ import ( "text/template" ) -func BuildJob(builderTmplRoot fs.FS, builderTmpl string, root *vfs.DirFS, config map[string]any) (*Job, error) { +func BuildJob(builderTmplRoot fs.FS, builderTmpl string, origin, root *vfs.DirFS, config map[string]any) (*Job, error) { var args common.Slice var export = common.Map{ Raw: map[string]any{ @@ -26,6 +26,7 @@ func BuildJob(builderTmplRoot fs.FS, builderTmpl string, root *vfs.DirFS, config } funcMap := map[string]any{ + "origin": common.WrapObject(origin.Path), "root": common.WrapObject(root.Path), "job": common.WrapObject(&export), "path": common.WrapObject(common.V1Path{}), diff --git a/workflow/builtin/tailwindcss/v1.tmpl b/workflow/builtin/tailwindcss/v1.tmpl index 12b1379..1911a4a 100644 --- a/workflow/builtin/tailwindcss/v1.tmpl +++ b/workflow/builtin/tailwindcss/v1.tmpl @@ -1,7 +1,9 @@ -{{ if eq .title nil }}{{ panic "missing property: title" }}{{ end }} {{ if eq .config nil }}{{ panic "missing property: config" }}{{ end }} {{ if eq .input nil }}{{ panic "missing property: input" }}{{ end }} {{ if eq .output nil }}{{ panic "missing property: output" }}{{ end }} -{{ job.Set "title" .title }} +{{ if strings.Contains .config ".." }}{{ panic (printf "%s is illegal" .config) }}{{ end }} +{{ if strings.Contains .input ".." }}{{ panic (printf "%s is illegal" .input) }}{{ end }} +{{ if strings.Contains .output ".." }}{{ panic (printf "%s is illegal" .output) }}{{ end }} +{{ job.Set "title" "Build Tailwind CSS" }} {{ job.Set "executable" "tailwindcss" }} -{{ (job.Get "args").Push "-c" (path.Join root .config) "--input" (path.Join root .input) "--output" (path.Join root .output) }} +{{ (job.Get "args").Push "-c" (path.Join origin .config) "--input" (path.Join origin .input) "--output" (path.Join root .output) }} diff --git a/workflow/builtin/tsc/v1.tmpl b/workflow/builtin/tsc/v1.tmpl index d66a044..95d0d35 100644 --- a/workflow/builtin/tsc/v1.tmpl +++ b/workflow/builtin/tsc/v1.tmpl @@ -1,5 +1,4 @@ {{ if eq .path nil }}{{ panic "missing property: path" }}{{ end }} -{{ if eq .title nil }}{{ panic "missing property: title" }}{{ end }} {{ job.Set "title" "Build TypeScript" }} {{ job.Set "executable" "tsc" }} {{ if strings.Contains .path ".." }}{{ panic (printf "%s is illegal" .path) }}{{ end }}