Compare commits
9 Commits
feat_packa
...
d4a660383e
| Author | SHA1 | Date | |
|---|---|---|---|
| d4a660383e | |||
| e96bbb5f49 | |||
| ad9060c8f6 | |||
| 58946000e1 | |||
| b08446bbff | |||
| 6c750a947f | |||
| b2e20c5d75 | |||
| 737b90d597 | |||
| e9969abf1c |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,8 +1,9 @@
|
|||||||
*.qcow2
|
*.qcow2
|
||||||
|
.envrc
|
||||||
result
|
result
|
||||||
example.json
|
example.json
|
||||||
go.sum
|
go.sum
|
||||||
go.mod
|
go.mod
|
||||||
gokill
|
./gokill
|
||||||
output.md
|
output.md
|
||||||
thoughts.md
|
thoughts.md
|
||||||
|
|||||||
@@ -7,10 +7,12 @@ import (
|
|||||||
"unknown.com/gokill/internal"
|
"unknown.com/gokill/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ActionResultChan chan error
|
||||||
|
|
||||||
type Action interface {
|
type Action interface {
|
||||||
Execute()
|
Execute()
|
||||||
DryExecute()
|
DryExecute()
|
||||||
Create(internal.ActionConfig, chan bool) (Action, error)
|
Create(internal.ActionConfig, ActionResultChan) (Action, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type DocumentedAction interface {
|
type DocumentedAction interface {
|
||||||
@@ -23,7 +25,7 @@ type Stage struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type StagedActions struct {
|
type StagedActions struct {
|
||||||
ActionChan chan bool
|
ActionChan ActionResultChan
|
||||||
StageCount int
|
StageCount int
|
||||||
Stages []Stage
|
Stages []Stage
|
||||||
}
|
}
|
||||||
@@ -40,7 +42,11 @@ func (a StagedActions) executeInternal(f func(Action)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for range stage.Actions {
|
for range stage.Actions {
|
||||||
<-a.ActionChan
|
err := <-a.ActionChan
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error occured on Stage %d: %s", idx+1, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,11 +70,11 @@ func (a StagedActions) Execute() {
|
|||||||
a.executeInternal(func(a Action) { a.Execute() })
|
a.executeInternal(func(a Action) { a.Execute() })
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a StagedActions) Create(config internal.ActionConfig, c chan bool) (Action, error) {
|
func (a StagedActions) Create(config internal.ActionConfig, c ActionResultChan) (Action, error) {
|
||||||
return StagedActions{}, nil
|
return StagedActions{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSingleAction(config internal.ActionConfig, c chan bool) (Action, error) {
|
func NewSingleAction(config internal.ActionConfig, c ActionResultChan) (Action, error) {
|
||||||
for _, availableAction := range GetAllActions() {
|
for _, availableAction := range GetAllActions() {
|
||||||
if config.Type == availableAction.GetName() {
|
if config.Type == availableAction.GetName() {
|
||||||
return availableAction.Create(config, c)
|
return availableAction.Create(config, c)
|
||||||
@@ -83,7 +89,7 @@ func NewAction(config []internal.ActionConfig) (Action, error) {
|
|||||||
return config[i].Stage < config[j].Stage
|
return config[i].Stage < config[j].Stage
|
||||||
})
|
})
|
||||||
|
|
||||||
stagedActions := StagedActions{make(chan bool), 0, []Stage{}}
|
stagedActions := StagedActions{make(ActionResultChan), 0, []Stage{}}
|
||||||
|
|
||||||
stageMap := make(map[int][]Action)
|
stageMap := make(map[int][]Action)
|
||||||
|
|
||||||
|
|||||||
@@ -9,20 +9,20 @@ import (
|
|||||||
|
|
||||||
type Printer struct {
|
type Printer struct {
|
||||||
Message string
|
Message string
|
||||||
ActionChan chan bool
|
ActionChan ActionResultChan
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Printer) Execute() {
|
func (p Printer) Execute() {
|
||||||
fmt.Printf("Print action fires. Message: %s\n", p.Message)
|
fmt.Printf("Print action fires. Message: %s\n", p.Message)
|
||||||
p.ActionChan <- true
|
p.ActionChan <- nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Printer) DryExecute() {
|
func (p Printer) DryExecute() {
|
||||||
fmt.Printf("Print action fire test. Message: %s\n", p.Message)
|
fmt.Printf("Print action fire test. Message: %s\n", p.Message)
|
||||||
p.ActionChan <- true
|
p.ActionChan <- nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Printer) Create(config internal.ActionConfig, c chan bool) (Action, error) {
|
func (p Printer) Create(config internal.ActionConfig, c ActionResultChan) (Action, error) {
|
||||||
var result Printer
|
var result Printer
|
||||||
err := json.Unmarshal(config.Options, &result)
|
err := json.Unmarshal(config.Options, &result)
|
||||||
|
|
||||||
@@ -44,6 +44,11 @@ func (p Printer) GetDescription() string {
|
|||||||
|
|
||||||
func (p Printer) GetOptions() []internal.ConfigOption {
|
func (p Printer) GetOptions() []internal.ConfigOption {
|
||||||
return []internal.ConfigOption{
|
return []internal.ConfigOption{
|
||||||
{"message", "string", "Message that should be printed", "\"\""},
|
{
|
||||||
|
Name: "message",
|
||||||
|
Type: "string",
|
||||||
|
Description: "Message that should be printed",
|
||||||
|
Default: "\"\"",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,13 +8,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Shutdown struct {
|
type Shutdown struct {
|
||||||
ActionChan chan bool
|
ActionChan ActionResultChan
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Shutdown) DryExecute() {
|
func (s Shutdown) DryExecute() {
|
||||||
fmt.Println("Test Shutdown executed...")
|
fmt.Println("Test Shutdown executed...")
|
||||||
|
|
||||||
s.ActionChan <- true
|
s.ActionChan <- nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,10 +25,10 @@ func (s Shutdown) Execute() {
|
|||||||
|
|
||||||
fmt.Println("Shutdown executed...")
|
fmt.Println("Shutdown executed...")
|
||||||
|
|
||||||
s.ActionChan <- true
|
s.ActionChan <- nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Shutdown) Create(config internal.ActionConfig, c chan bool) (Action, error) {
|
func (s Shutdown) Create(config internal.ActionConfig, c ActionResultChan) (Action, error) {
|
||||||
return Shutdown{c}, nil
|
return Shutdown{c}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
type TimeOut struct {
|
type TimeOut struct {
|
||||||
Duration time.Duration
|
Duration time.Duration
|
||||||
ActionChan chan bool
|
ActionChan ActionResultChan
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t TimeOut) DryExecute() {
|
func (t TimeOut) DryExecute() {
|
||||||
@@ -20,10 +20,10 @@ func (t TimeOut) DryExecute() {
|
|||||||
func (t TimeOut) Execute() {
|
func (t TimeOut) Execute() {
|
||||||
fmt.Printf("Waiting %d seconds\n", t.Duration)
|
fmt.Printf("Waiting %d seconds\n", t.Duration)
|
||||||
time.Sleep(time.Duration(t.Duration) * time.Second)
|
time.Sleep(time.Duration(t.Duration) * time.Second)
|
||||||
t.ActionChan <- true
|
t.ActionChan <- nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t TimeOut) Create(config internal.ActionConfig, c chan bool) (Action, error) {
|
func (t TimeOut) Create(config internal.ActionConfig, c ActionResultChan) (Action, error) {
|
||||||
var result TimeOut
|
var result TimeOut
|
||||||
err := json.Unmarshal(config.Options, &result)
|
err := json.Unmarshal(config.Options, &result)
|
||||||
|
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ import (
|
|||||||
|
|
||||||
type Command struct {
|
type Command struct {
|
||||||
Command string `json:"command"`
|
Command string `json:"command"`
|
||||||
ActionChan chan bool
|
ActionChan ActionResultChan
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Command) DryExecute() {
|
func (c Command) DryExecute() {
|
||||||
fmt.Printf("Test Executing Command:\n%s ", c.Command)
|
fmt.Printf("Test Executing Command:\n%s ", c.Command)
|
||||||
c.ActionChan <- true
|
c.ActionChan <- nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Command) splitCommandString() (string, []string, error) {
|
func (c Command) splitCommandString() (string, []string, error) {
|
||||||
@@ -38,8 +38,7 @@ func (c Command) Execute() {
|
|||||||
fmt.Println("Executing command: ", c.Command)
|
fmt.Println("Executing command: ", c.Command)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
c.ActionChan <- err
|
||||||
c.ActionChan <- false
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,10 +52,10 @@ func (c Command) Execute() {
|
|||||||
|
|
||||||
fmt.Println(string(stdout[:]))
|
fmt.Println(string(stdout[:]))
|
||||||
|
|
||||||
c.ActionChan <- true
|
c.ActionChan <- nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateCommand(config internal.ActionConfig, c chan bool) (Command, error) {
|
func CreateCommand(config internal.ActionConfig, c ActionResultChan) (Command, error) {
|
||||||
result := Command{}
|
result := Command{}
|
||||||
|
|
||||||
err := json.Unmarshal(config.Options, &result)
|
err := json.Unmarshal(config.Options, &result)
|
||||||
@@ -74,7 +73,7 @@ func CreateCommand(config internal.ActionConfig, c chan bool) (Command, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cc Command) Create(config internal.ActionConfig, c chan bool) (Action, error) {
|
func (cc Command) Create(config internal.ActionConfig, c ActionResultChan) (Action, error) {
|
||||||
return CreateCommand(config, c)
|
return CreateCommand(config, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
94
cmd/docbuilder/docbuilder.go
Normal file
94
cmd/docbuilder/docbuilder.go
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"os"
|
||||||
|
"flag"
|
||||||
|
|
||||||
|
"unknown.com/gokill/actions"
|
||||||
|
"unknown.com/gokill/triggers"
|
||||||
|
"unknown.com/gokill/internal"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getMarkdown(documenter internal.Documenter) string {
|
||||||
|
var result string
|
||||||
|
result += fmt.Sprintf("# %v\n%v\n## Options:\n", documenter.GetName(), documenter.GetDescription())
|
||||||
|
|
||||||
|
for _, opt := range documenter.GetOptions() {
|
||||||
|
result += fmt.Sprintf("### %v\n%v \n\n*Type:* %v \n\n*Default:* ```%v``` \n",
|
||||||
|
opt.Name, opt.Description, opt.Type, opt.Default)
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeToFile(path string, documenter internal.Documenter) error {
|
||||||
|
fileName := fmt.Sprintf("%s/%s.md", path, documenter.GetName())
|
||||||
|
|
||||||
|
f, err := os.Create(fileName)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
_, err = f.WriteString(getMarkdown(documenter))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeDocumentersToFiles(destination string) {
|
||||||
|
writeFolder := func(typeName string, documenters []internal.Documenter) {
|
||||||
|
path := fmt.Sprintf("%s/%s", destination, typeName)
|
||||||
|
_ = os.Mkdir(path, os.ModePerm)
|
||||||
|
for _, documenter := range documenters {
|
||||||
|
writeToFile(path, documenter)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
actions := actions.GetDocumenters()
|
||||||
|
writeFolder("actions", actions)
|
||||||
|
|
||||||
|
triggers := triggers.GetDocumenters()
|
||||||
|
writeFolder("triggers", triggers)
|
||||||
|
}
|
||||||
|
|
||||||
|
func printDocumentersSummary() {
|
||||||
|
result := fmt.Sprintf("- [Triggers](triggers/README.md)\n")
|
||||||
|
for _, trigger := range triggers.GetDocumenters() {
|
||||||
|
result += fmt.Sprintf("\t- [%s](triggers/%s.md)\n", trigger.GetName(), trigger.GetName())
|
||||||
|
}
|
||||||
|
|
||||||
|
result += fmt.Sprintf("- [Actions](actions/README.md)\n")
|
||||||
|
for _, action := range actions.GetDocumenters() {
|
||||||
|
result += fmt.Sprintf("\t- [%s](actions/%s.md)\n", action.GetName(), action.GetName())
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Print(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
outputPath := flag.String("output", "", "path where docs/ shoud be created")
|
||||||
|
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
if *outputPath == "" {
|
||||||
|
printDocumentersSummary()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(*outputPath) > 1 {
|
||||||
|
*outputPath = strings.TrimSuffix(*outputPath, "/")
|
||||||
|
}
|
||||||
|
|
||||||
|
writeDocumentersToFiles(*outputPath)
|
||||||
|
}
|
||||||
1
docs/.gitignore
vendored
Normal file
1
docs/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
book/*
|
||||||
4
docs/SUMMARY.md
Normal file
4
docs/SUMMARY.md
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Summary
|
||||||
|
|
||||||
|
- [Introduction](./gokill.md)
|
||||||
|
@GOKILL_OPTIONS@
|
||||||
1
docs/actions/README.md
Normal file
1
docs/actions/README.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# Actions
|
||||||
10
docs/book.toml
Normal file
10
docs/book.toml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[book]
|
||||||
|
authors = []
|
||||||
|
language = "en"
|
||||||
|
multilingual = false
|
||||||
|
src = "."
|
||||||
|
title = "gokill docs"
|
||||||
|
|
||||||
|
[output.html.fold]
|
||||||
|
enable = true
|
||||||
|
level = 0
|
||||||
32
docs/default.nix
Normal file
32
docs/default.nix
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
{ pkgs, lib, self, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
let
|
||||||
|
docbuilder = self.packages.x86_64-linux.gokill-docbuilder;
|
||||||
|
|
||||||
|
prepareMD = ''
|
||||||
|
# Copy inputs into the build directory
|
||||||
|
cp -r --no-preserve=all $inputs/* ./
|
||||||
|
|
||||||
|
${docbuilder}/bin/docbuilder --output ./
|
||||||
|
substituteInPlace ./SUMMARY.md \
|
||||||
|
--replace "@GOKILL_OPTIONS@" "$(${docbuilder}/bin/docbuilder)"
|
||||||
|
|
||||||
|
cat ./SUMMARY.md
|
||||||
|
'';
|
||||||
|
in
|
||||||
|
pkgs.stdenv.mkDerivation {
|
||||||
|
name = "gokill-docs";
|
||||||
|
phases = [ "buildPhase" ];
|
||||||
|
buildInputs = [ pkgs.mdbook ];
|
||||||
|
|
||||||
|
inputs = sourceFilesBySuffices ./. [ ".md" ".toml" ];
|
||||||
|
|
||||||
|
buildPhase = ''
|
||||||
|
dest=$out/share/doc
|
||||||
|
mkdir -p $dest
|
||||||
|
${prepareMD}
|
||||||
|
mdbook build
|
||||||
|
cp -r ./book/* $dest
|
||||||
|
'';
|
||||||
|
}
|
||||||
1
docs/gokill.md
Normal file
1
docs/gokill.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# Introduction
|
||||||
1
docs/triggers/README.md
Normal file
1
docs/triggers/README.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# Triggers
|
||||||
6
flake.lock
generated
6
flake.lock
generated
@@ -2,11 +2,11 @@
|
|||||||
"nodes": {
|
"nodes": {
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1697915759,
|
"lastModified": 1698553279,
|
||||||
"narHash": "sha256-WyMj5jGcecD+KC8gEs+wFth1J1wjisZf8kVZH13f1Zo=",
|
"narHash": "sha256-T/9P8yBSLcqo/v+FTOBK+0rjzjPMctVymZydbvR/Fak=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "51d906d2341c9e866e48c2efcaac0f2d70bfd43e",
|
"rev": "90e85bc7c1a6fc0760a94ace129d3a1c61c3d035",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|||||||
29
flake.nix
29
flake.nix
@@ -7,8 +7,17 @@
|
|||||||
outputs = { self, nixpkgs, ... }:
|
outputs = { self, nixpkgs, ... }:
|
||||||
let
|
let
|
||||||
forAllSystems = nixpkgs.lib.genAttrs [ "x86_64-linux" ];
|
forAllSystems = nixpkgs.lib.genAttrs [ "x86_64-linux" ];
|
||||||
|
pkgs = nixpkgs.legacyPackages."x86_64-linux";
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
devShell."x86_64-linux" = pkgs.mkShell {
|
||||||
|
packages = with pkgs; [
|
||||||
|
go
|
||||||
|
gotools
|
||||||
|
mdbook
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
packages.x86_64-linux.gokill = nixpkgs.legacyPackages.x86_64-linux.buildGoModule rec {
|
packages.x86_64-linux.gokill = nixpkgs.legacyPackages.x86_64-linux.buildGoModule rec {
|
||||||
pname = "gokill";
|
pname = "gokill";
|
||||||
version = "1.0";
|
version = "1.0";
|
||||||
@@ -19,6 +28,20 @@
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
packages.x86_64-linux.gokill-docbuilder = nixpkgs.legacyPackages.x86_64-linux.buildGoModule rec {
|
||||||
|
pname = "docbuilder";
|
||||||
|
version = "1.0";
|
||||||
|
vendorHash = null;
|
||||||
|
buildFLags = "-o . $dest/cmd/gokill/docbuilder";
|
||||||
|
src = ./.;
|
||||||
|
|
||||||
|
postInstall = ''
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
packages.x86_64-linux.docs = pkgs.callPackage (import ./docs/default.nix) { self = self; };
|
||||||
|
|
||||||
packages.x86_64-linux.default = self.packages.x86_64-linux.gokill;
|
packages.x86_64-linux.default = self.packages.x86_64-linux.gokill;
|
||||||
|
|
||||||
nixosModules.gokill = { config, lib, pkgs, ... }:
|
nixosModules.gokill = { config, lib, pkgs, ... }:
|
||||||
@@ -131,5 +154,11 @@
|
|||||||
${self.packages."x86_64-linux".testVm}/bin/run-nixos-vm
|
${self.packages."x86_64-linux".testVm}/bin/run-nixos-vm
|
||||||
'');
|
'');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
apps.x86_64-linux.docs = {
|
||||||
|
type = "app";
|
||||||
|
program = builtins.toString (nixpkgs.legacyPackages."x86_64-linux".writeScript "docs" ''
|
||||||
|
${pkgs.python3}/bin/python3 -m http.server --directory ${self.packages."x86_64-linux".docs}/share/doc'');
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user