all repos — memnarch @ 2bb6d24546698e84f332e59c36c22c5b8de764ba

featherweight orchestrator

fix webhook stuff and start decoding actions
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iHUEABYKAB0WIQR2zYvweXfSPsSU6pP1Tg1AaVJx1AUCZPK8mwAKCRD1Tg1AaVJx
1H2hAP9O254HDLGTIDL7r5NjyulFkfIcPjhDlPapehIr57Ka2QEAzQ293zDsQBdJ
7vKylUSasiwwRYxgiAvrpUHzlFL1LAs=
=o82Z
-----END PGP SIGNATURE-----
commit

2bb6d24546698e84f332e59c36c22c5b8de764ba

parent

2a1845f04cfe9eb566077f0c98f7133ec23dc6e3

5 files changed, 63 insertions(+), 7 deletions(-)

jump to
A action/action.go

@@ -0,0 +1,34 @@

+package action + +import ( + "fmt" + "os" + + "gopkg.in/yaml.v3" +) + +type Action struct { + Build struct { + Cmd string `yaml:"cmd"` + } `yaml:"build,omitempty"` + Deploy struct { + Hosts []string `yaml:"hosts"` + Artifacts map[string][]string `yaml:"artifacts"` + Before map[string]string `yaml:"before,omitempty"` + After map[string]string `yaml:"after,omitempty"` + } `yaml:"deploy,omitempty"` +} + +func Read(filename string) (*Action, error) { + b, err := os.ReadFile(filename) + if err != nil { + return nil, fmt.Errorf("reading action: %w", err) + } + + a := Action{} + if err := yaml.Unmarshal(b, &a); err != nil { + return nil, fmt.Errorf("parsing action: %w", err) + } + + return &a, nil +}
M go.modgo.mod

@@ -2,4 +2,7 @@ module forge.lightcrystal.systems/lightcrystal/memnarch

go 1.20 -require hacklab.nilfm.cc/quartzgun v0.3.2 +require ( + gopkg.in/yaml.v3 v3.0.1 + hacklab.nilfm.cc/quartzgun v0.3.2 +)
M go.sumgo.sum

@@ -1,2 +1,6 @@

+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= hacklab.nilfm.cc/quartzgun v0.3.2 h1:PmRFZ/IgsXVWyNn1iOsQ/ZeMnOQIQy0PzFakhXBdZoU= hacklab.nilfm.cc/quartzgun v0.3.2/go.mod h1:P6qK4HB0CD/xfyRq8wdEGevAPFDDmv0KCaESSvv93LU=
M main.gomain.go

@@ -14,7 +14,7 @@ "hacklab.nilfm.cc/quartzgun/renderer"

"hacklab.nilfm.cc/quartzgun/router" . "hacklab.nilfm.cc/quartzgun/util" - + "forge.lightcrystal.systems/lightcrystal/memnarch/action" "forge.lightcrystal.systems/lightcrystal/memnarch/webhook" )

@@ -65,18 +65,33 @@

// so we run the rest in a goroutine... go func() { // cd and checkout repo - cmd := exec.Command("git", "clone", repoUrl) - cmd.Dir = workingDir + clone := exec.Command("git", "clone", repoUrl) + clone.Dir = workingDir - err := cmd.Run() + err := clone.Run() if err != nil { // clone error - log it and quit return } // read memnarch action file + urlParams := req.Context().Value("params").(map[string]string) + jobName := urlParams["job"] + + jobFile := filepath.Join(workingDir, repo, jobName + ".yml") + a, err := action.Read(jobFile) + if err != nil { + fmt.Println(err.Error()) + } // decode and perform action + // build + buildCmd := exec.Command(a.Build.Cmd) + buildCmd.Dir = filepath.Join(workingDir, repo) + + // pre-deploy + // deploy + // post-deploy }() AddContextValue(req, "data", "job submitted")
M webhook/webhook.gowebhook/webhook.go

@@ -31,7 +31,7 @@ return false

} actual := make([]byte, 20) - hex.Decode(actual, []byte(h.Signature[5:])) + hex.Decode(actual, []byte(h.Signature)) return hmac.Equal(signBody(secret, h.Payload), actual) }

@@ -46,7 +46,7 @@ if !strings.EqualFold(req.Method, "POST") {

return nil, errors.New("Unknown method!") } - if hook.Signature = req.Header.Get("X-Signature-SHA256"); len(hook.Signature) == 0 { + if hook.Signature = req.Header.Get("X-Forgejo-Signature"); len(hook.Signature) == 0 { return nil, errors.New("No signature!") }