Awesome
sparrowgo
Write SparrowCI tasks on Golang
How to
Create golang task
task.go
:
package main
import (
"fmt"
"github.com/melezhik/sparrowgo"
)
func main() {
sparrowgo.DebugOn()
type Params struct {
Message string
}
type Message struct {
Message string
}
var params Params
sparrowgo.Config(¶ms)
fmt.Printf("Sparrow says: %s\n", params.Message)
switch sparrowgo.Os() {
case "darwin":
fmt.Println("hello Mac")
case "arch":
fmt.Println("hello Arch Linux")
case "debian":
fmt.Println("hello Debian")
// so on
}
sparrowgo.UpdateState(&Message{Message : "Hello from Go"})
}
Create Sparrow wrapper
test.raku
:
use Sparrow6::DSL;
my $s = task-run ".", %(
message => "Hello from Raku"
);
say "message: ", $s<Message>;
Run:
raku test.raku
Output will be:
[task run: task.bash - .]
[task stdout]
13:08:47 :: Sparrow says: Hello from Raku
message: Hello from Go
Other options
Enable debug
sparrowgo.DebugOn()
Disable debug
sparrowgo.DebugOff()
Get know OS name
switch sparrowgo.Os() {
case "darwin":
fmt.Println("hello Mac")
case "arch":
fmt.Println("hello Arch Linux")
case "debian":
fmt.Println("hello Debian")
// so on
}
To get the list of supported OS follow this link
Advanced topics
Hooks and subtasks
Create hook task, hook.go
package main
import (
"github.com/melezhik/sparrowgo"
)
func main() {
type Params struct {
Message string
}
sparrowgo.RunTask("foo",Params{Message: "hello from main"})
}
Create subtask:
mkdir -p tasks/foo
tasks/foo/task.go
package main
import (
"fmt"
"github.com/melezhik/sparrowgo"
)
func main() {
type Vars struct {
Message string
}
type Message struct {
Message string
}
var task_vars Vars
sparrowgo.TaskVars(&task_vars)
fmt.Printf("foo subtask get this: %s\n",task_vars.Message)
sparrowgo.UpdateState(Message{Message: "Hello from subtask"})
}
Create Sparrow wrapper:
test.raku
:
use Sparrow6::DSL;
my $s = task-run ".";
say $s<Message>;
Run:
raku test.raku
Output will be:
[task run: task - .]
[task stdout]
12:59:14 :: foo subtask get this: hello from main
Hello from subtask
Get task state
Use sparrowgo.GetState
function to get task state.
Example:
task.go
:
package main
import (
"fmt"
"github.com/melezhik/sparrowgo"
)
func main() {
// sparrowgo.DebugOn()
type State struct { Message string }
var state State
sparrowgo.GetState(&state)
fmt.Printf("task state: %s\n",state.Message)
}
Set stdout
Use SetStdout
function to register some stdout in hook:
sparrowgo.SetStdout("here we go\nnext line")
Ignore task error
Use IgnoreError
function to ingnore task error (none zero exit code):
sparrowgo.IgnoreError()