100 lines
2.6 KiB
Go
100 lines
2.6 KiB
Go
package task
|
|
|
|
import (
|
|
"context"
|
|
|
|
"code.icb4dc0.de/buildr/buildr/modules"
|
|
)
|
|
|
|
func (s ScriptTask) Help(context.Context) (help modules.Help, err error) {
|
|
return modules.Help{
|
|
Name: "Script - run single commands or complete scripts",
|
|
Description: `This module helps to run arbitrary commands or complete scripts.
|
|
It's possible to either inline all commands or specify an external script file.
|
|
Furthermore, it's possible to specify which shell should be used to execute the commands.
|
|
Right now this will only work with Linux/MacOS shells.`,
|
|
Examples: []modules.Example{
|
|
{
|
|
Name: "Hello world",
|
|
Description: `Simples possible script.`,
|
|
Spec: &modules.Metadata[ScriptTask]{
|
|
ModuleName: "hello_world",
|
|
Module: ScriptTask{
|
|
Inline: []string{`echo 'Hello world!'`},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
Name: "Multiline inline script",
|
|
Description: `Specify multiple array entries to run a script.
|
|
All lines of the inline script will be joined to a single string so it's possible to use some context
|
|
like changing the current working directory.`,
|
|
Spec: &modules.Metadata[ScriptTask]{
|
|
ModuleName: "multi_inline_script",
|
|
Module: ScriptTask{
|
|
Inline: []string{
|
|
`mkdir test`,
|
|
`echo 'Hello world' > test/sample.txt`,
|
|
`cd test`,
|
|
`cat sample.txt`,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
Name: "External script file",
|
|
Description: `Call a script from a file.`,
|
|
Spec: &modules.Metadata[ScriptTask]{
|
|
ModuleName: "external_script_file",
|
|
Module: ScriptTask{
|
|
Script: "testdata/sample.sh",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
Name: "Manipulate environment variables",
|
|
Description: `Set environment variables and use it in a script`,
|
|
Spec: &modules.Metadata[ScriptTask]{
|
|
ModuleName: "env_script",
|
|
Module: ScriptTask{
|
|
Inline: []string{
|
|
`echo "$GREETING world"`,
|
|
},
|
|
Env: map[string]string{
|
|
"GREETING": "Hello",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
Name: "Change working directory",
|
|
Description: `Set the working directory to another directory.`,
|
|
Spec: &modules.Metadata[ScriptTask]{
|
|
ModuleName: "script_with_working_dir",
|
|
Module: ScriptTask{
|
|
Inline: []string{
|
|
`cat sample.txt`,
|
|
},
|
|
WorkingDir: "testdata",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
Name: "Container script",
|
|
Description: `Run a script inside a container.`,
|
|
Spec: &modules.Metadata[ScriptTask]{
|
|
ModuleName: "container_script",
|
|
Container: &modules.ContainerSpec{
|
|
Image: "busybox",
|
|
},
|
|
Module: ScriptTask{
|
|
Inline: []string{
|
|
`echo 'Hello, world!'`,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}, nil
|
|
}
|