home

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit eb7926478032dbc01975788cff193a5605ea3eb2
parent 0364b43b5ec2cc4eb2cadd618b5f3e08b3b4285f
Author: Vincent Demeester <vincent@sbr.pm>
Date:   Mon, 25 May 2020 09:43:05 +0200

tools/bus: fix nightly builds 🌔

Add home as source for the nightly (automatically added for a git push)

Signed-off-by: Vincent Demeester <vincent@sbr.pm>

Diffstat:
Mtools/bus/default.nix | 17+++--------------
Atools/bus/go.mod | 5+++++
Atools/bus/go.sum | 3+++
Mtools/bus/main.go | 37+++++++++++++++++++++++++++++++++++--
4 files changed, 46 insertions(+), 16 deletions(-)

diff --git a/tools/bus/default.nix b/tools/bus/default.nix @@ -1,19 +1,8 @@ -{ stdenv, lib, go }: +{ stdenv, lib, buildGoModule }: -stdenv.mkDerivation rec { +buildGoModule rec { name = "bus"; src = ./.; - phases = "buildPhase installPhase"; - buildInputs = [ go ]; - - buildPhase = '' - HOME=$(pwd) - cp $src/main.go . - go build -o bus main.go - ''; - installPhase = '' - mkdir $out - install -D bus $out/bin/bus - ''; + modSha256 = "1633qy8a24pacr337v20ws12p3wgr2kf7q2mymar90qrq301wfnx"; } diff --git a/tools/bus/go.mod b/tools/bus/go.mod @@ -0,0 +1,5 @@ +module home/tools/bus + +go 1.14 + +require gopkg.in/yaml.v2 v2.3.0 diff --git a/tools/bus/go.sum b/tools/bus/go.sum @@ -0,0 +1,3 @@ +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/tools/bus/main.go b/tools/bus/main.go @@ -12,6 +12,8 @@ import ( "os" "path/filepath" "strings" + + yaml "gopkg.in/yaml.v2" ) var ( @@ -28,6 +30,23 @@ type Build struct { Tags []string `json:"tags"` } +// Represents a build trigger object as described on <the docs for +// this are currently down> +type Trigger struct { + Action string `json:"action"` + Condition string `json:"condition"` + To string `json:"to"` +} + +// Represents a build manifest for sourcehut. +type Manifest struct { + Image string `json:"image"` + Sources []string `json:"sources"` + Secrets []string `json:"secrets"` + Tasks [](map[string]string) `json:"tasks"` + Triggers []Trigger `json:"triggers"` +} + func triggerBuild(token, name, manifest, branch string) { build := Build{ Manifest: manifest, @@ -69,6 +88,15 @@ func triggerBuild(token, name, manifest, branch string) { } } +func prepareManifest(manifest []byte) ([]byte, error) { + var m Manifest + if err := yaml.Unmarshal(manifest, &m); err != nil { + return manifest, err + } + m.Sources = append(m.Sources, "https://git.sr.ht/~vdemeester/home") + return yaml.Marshal(m) +} + func main() { flag.Parse() token, err := ioutil.ReadFile(*secret) @@ -78,7 +106,7 @@ func main() { } files, err := ioutil.ReadDir(*builds) if err != nil { - fmt.Fprintf(os.Stderr, "cannot list builds manifest from %s.", *builds) + fmt.Fprintf(os.Stderr, "cannot list builds manifest from %s: %v.\n", *builds, err) os.Exit(1) } fmt.Fprintf(os.Stdout, "triggering builds for %v\n", *branch) @@ -86,7 +114,12 @@ func main() { path := filepath.Join(*builds, f.Name()) manifest, err := ioutil.ReadFile(path) if err != nil { - fmt.Fprintf(os.Stderr, "cannot read manifest %s.", path) + fmt.Fprintf(os.Stderr, "cannot read manifest %s: %v.\n", path, err) + os.Exit(1) + } + manifest, err = prepareManifest(manifest) + if err != nil { + fmt.Fprintf(os.Stderr, "failed to prepare manifest %s: %v.\n", path, err) os.Exit(1) } triggerBuild(string(token), f.Name(), string(manifest), *branch)