Skip to content

Commit

Permalink
cmd/relui: add proto definition for workflows
Browse files Browse the repository at this point in the history
Using configuration for our workflows will help separate concerns
between implementation and workflow configuration.

Eventually, similar tasks can be re-used in different workflows, such as
fetching from Git, updating the VERSION file, or publishing a tag.

The current configuration definition is mainly illustrative, and is
expected to change as we build out a prototype.

For golang/go#40279

Change-Id: I5c6f8a18571ab819de0b1d026c86050735efeed9
Reviewed-on: https://go-review.googlesource.com/c/build/+/243340
Run-TryBot: Alexander Rakoczy <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Andrew Bonventre <[email protected]>
  • Loading branch information
toothrot committed Jul 29, 2020
1 parent 0afb23e commit a6019d6
Show file tree
Hide file tree
Showing 10 changed files with 458 additions and 96 deletions.
32 changes: 31 additions & 1 deletion cmd/relui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
package main

import (
"io/ioutil"
"log"
"net/http"
"os"
"path/filepath"

"github.com/golang/protobuf/proto"
reluipb "golang.org/x/build/cmd/relui/protos"
)

func main() {
s := &server{store: &memoryStore{}}
s := &server{store: &memoryStore{}, configs: loadWorkflowConfig("./workflows")}
http.Handle("/workflows/create", http.HandlerFunc(s.createWorkflowHandler))
http.Handle("/workflows/new", http.HandlerFunc(s.newWorkflowHandler))
http.Handle("/", fileServerHandler(relativeFile("./static"), http.HandlerFunc(s.homeHandler)))
Expand All @@ -23,3 +28,28 @@ func main() {
log.Printf("Listening on :" + port)
log.Fatal(http.ListenAndServe(":"+port, http.DefaultServeMux))
}

// loadWorkflowConfig loads Workflow configuration files from dir. It expects all files to be in textproto format.
func loadWorkflowConfig(dir string) []*reluipb.Workflow {
fs, err := filepath.Glob(filepath.Join(relativeFile(dir), "*.textpb"))
if err != nil {
log.Fatalf("Error perusing %q for configuration", filepath.Join(dir, "*.textpb"))
}
if len(fs) == 0 {
log.Println("No workflow configuration found.")
}
var ws []*reluipb.Workflow
for _, f := range fs {
b, err := ioutil.ReadFile(f)
if err != nil {
log.Printf("ioutil.ReadFile(%q) = _, %v, wanted no error", f, err)
}
w := new(reluipb.Workflow)
if err = proto.UnmarshalText(string(b), w); err != nil {
log.Printf("Error unmarshalling Workflow from %q: %v", f, err)
continue
}
ws = append(ws, w)
}
return ws
}
11 changes: 11 additions & 0 deletions cmd/relui/protos/protos.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package protos

// Run "go generate" in this directory to update. You need to have:
//
// - a protoc binary (see https://github.com/golang/protobuf#installation)
// - go get -u github.com/golang/protobuf/protoc-gen-go

//go:generate protoc --proto_path=$GOPATH/src:. --go_out=plugins=grpc:. relui.proto
281 changes: 281 additions & 0 deletions cmd/relui/protos/relui.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions cmd/relui/protos/relui.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

syntax = "proto3";

package protos;

message Workflow {
// name is a unique name for a workflow, such as local_go_release. The name must be unique across
// all workflow configurations.
string name = 1;

// buildable_asks is a list of tasks to be performed by the workflow.
repeated BuildableTask buildable_tasks = 2;

// params are parameters provided when creating a workflow.
map<string, string> params = 3;
}

message BuildableTask {
// name is a unique name for a task, such as fetch_go_source. The name must be unique across
// all workflow configurations.
string name = 1;

// depends_on is the name of a task this task depends on. Artifacts from the depends_on task will be available
// to this task.
string depends_on = 2;

// task_status is the current status of a task.
TaskStatus status = 3;

// artifact_url is an optional URL to an artifact published by this task.
string artifact_url = 4;

// git_source is an optional configuration for which git source to fetch.
GitSource git_source = 5;

// task_type is a unique type for a task, such as FetchGerritSource. Types are used by task runners to identify
// how to execute a task.
string task_type = 6;
}

message GitSource {
string url = 1;
string ref = 2;
}

enum TaskStatus {
TASK_STATUS_UNKNOWN = 0;
TASK_STATUS_CREATED = 1;
TASK_STATUS_STARTED = 2;
}
Loading

0 comments on commit a6019d6

Please sign in to comment.