Skip to content

Commit a6019d6

Browse files
committed
cmd/relui: add proto definition for workflows
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]>
1 parent 0afb23e commit a6019d6

File tree

10 files changed

+458
-96
lines changed

10 files changed

+458
-96
lines changed

cmd/relui/main.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@
55
package main
66

77
import (
8+
"io/ioutil"
89
"log"
910
"net/http"
1011
"os"
12+
"path/filepath"
13+
14+
"github.com/golang/protobuf/proto"
15+
reluipb "golang.org/x/build/cmd/relui/protos"
1116
)
1217

1318
func main() {
14-
s := &server{store: &memoryStore{}}
19+
s := &server{store: &memoryStore{}, configs: loadWorkflowConfig("./workflows")}
1520
http.Handle("/workflows/create", http.HandlerFunc(s.createWorkflowHandler))
1621
http.Handle("/workflows/new", http.HandlerFunc(s.newWorkflowHandler))
1722
http.Handle("/", fileServerHandler(relativeFile("./static"), http.HandlerFunc(s.homeHandler)))
@@ -23,3 +28,28 @@ func main() {
2328
log.Printf("Listening on :" + port)
2429
log.Fatal(http.ListenAndServe(":"+port, http.DefaultServeMux))
2530
}
31+
32+
// loadWorkflowConfig loads Workflow configuration files from dir. It expects all files to be in textproto format.
33+
func loadWorkflowConfig(dir string) []*reluipb.Workflow {
34+
fs, err := filepath.Glob(filepath.Join(relativeFile(dir), "*.textpb"))
35+
if err != nil {
36+
log.Fatalf("Error perusing %q for configuration", filepath.Join(dir, "*.textpb"))
37+
}
38+
if len(fs) == 0 {
39+
log.Println("No workflow configuration found.")
40+
}
41+
var ws []*reluipb.Workflow
42+
for _, f := range fs {
43+
b, err := ioutil.ReadFile(f)
44+
if err != nil {
45+
log.Printf("ioutil.ReadFile(%q) = _, %v, wanted no error", f, err)
46+
}
47+
w := new(reluipb.Workflow)
48+
if err = proto.UnmarshalText(string(b), w); err != nil {
49+
log.Printf("Error unmarshalling Workflow from %q: %v", f, err)
50+
continue
51+
}
52+
ws = append(ws, w)
53+
}
54+
return ws
55+
}

cmd/relui/protos/protos.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2020 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
package protos
5+
6+
// Run "go generate" in this directory to update. You need to have:
7+
//
8+
// - a protoc binary (see https://github.com/golang/protobuf#installation)
9+
// - go get -u github.com/golang/protobuf/protoc-gen-go
10+
11+
//go:generate protoc --proto_path=$GOPATH/src:. --go_out=plugins=grpc:. relui.proto

cmd/relui/protos/relui.pb.go

Lines changed: 281 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/relui/protos/relui.proto

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright 2020 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
syntax = "proto3";
6+
7+
package protos;
8+
9+
message Workflow {
10+
// name is a unique name for a workflow, such as local_go_release. The name must be unique across
11+
// all workflow configurations.
12+
string name = 1;
13+
14+
// buildable_asks is a list of tasks to be performed by the workflow.
15+
repeated BuildableTask buildable_tasks = 2;
16+
17+
// params are parameters provided when creating a workflow.
18+
map<string, string> params = 3;
19+
}
20+
21+
message BuildableTask {
22+
// name is a unique name for a task, such as fetch_go_source. The name must be unique across
23+
// all workflow configurations.
24+
string name = 1;
25+
26+
// depends_on is the name of a task this task depends on. Artifacts from the depends_on task will be available
27+
// to this task.
28+
string depends_on = 2;
29+
30+
// task_status is the current status of a task.
31+
TaskStatus status = 3;
32+
33+
// artifact_url is an optional URL to an artifact published by this task.
34+
string artifact_url = 4;
35+
36+
// git_source is an optional configuration for which git source to fetch.
37+
GitSource git_source = 5;
38+
39+
// task_type is a unique type for a task, such as FetchGerritSource. Types are used by task runners to identify
40+
// how to execute a task.
41+
string task_type = 6;
42+
}
43+
44+
message GitSource {
45+
string url = 1;
46+
string ref = 2;
47+
}
48+
49+
enum TaskStatus {
50+
TASK_STATUS_UNKNOWN = 0;
51+
TASK_STATUS_CREATED = 1;
52+
TASK_STATUS_STARTED = 2;
53+
}

0 commit comments

Comments
 (0)