Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e21d7f2394 | ||
|
|
2caed6fd6f | ||
|
|
8d493c6579 | ||
|
|
ce2c54acf2 | ||
|
|
35d0739b63 | ||
|
|
d6c399fded | ||
|
|
c3339ab49a | ||
|
|
85a6397d1d | ||
|
|
47e0e79550 |
No files matched your search
+34
-13
@@ -1,16 +1,12 @@
|
|||||||
name: Build protos
|
name: Build protos
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
paths:
|
||||||
- main
|
- '*.proto'
|
||||||
types:
|
- '**/*.proto'
|
||||||
- opened
|
|
||||||
- synchronize
|
permissions:
|
||||||
- reopened
|
contents: write
|
||||||
- edited
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- 'v*.*.*'
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@@ -21,6 +17,7 @@ jobs:
|
|||||||
uses: actions/checkout@v7
|
uses: actions/checkout@v7
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
ref: ${{ github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.head.sha || github.sha }}
|
||||||
|
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v7
|
uses: actions/setup-go@v7
|
||||||
@@ -29,13 +26,37 @@ jobs:
|
|||||||
|
|
||||||
- name: Install protoc
|
- name: Install protoc
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update
|
curl --fail --location --silent --show-error \
|
||||||
sudo apt-get install -y protobuf-compiler
|
--output "$RUNNER_TEMP/protoc.zip" \
|
||||||
|
https://github.com/protocolbuffers/protobuf/releases/download/v36.2/protoc-36.2-linux-x86_64.zip
|
||||||
|
unzip -q "$RUNNER_TEMP/protoc.zip" -d "$RUNNER_TEMP/protoc"
|
||||||
|
echo "$RUNNER_TEMP/protoc/bin" >> "$GITHUB_PATH"
|
||||||
|
|
||||||
- name: Install protoc-gen-go
|
- name: Install protoc-gen-go
|
||||||
run: |
|
run: |
|
||||||
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
|
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.36.12
|
||||||
|
|
||||||
- name: Generate Protobufs
|
- name: Generate Protobufs
|
||||||
run: |
|
run: |
|
||||||
make proto
|
make proto
|
||||||
|
|
||||||
|
- name: Commit and push changes
|
||||||
|
env:
|
||||||
|
HEAD_REPOSITORY: ${{ github.event.pull_request.head.repo.full_name }}
|
||||||
|
HEAD_REF: ${{ github.event.pull_request.head.ref }}
|
||||||
|
REPOSITORY: ${{ github.repository }}
|
||||||
|
run: |
|
||||||
|
git add -- '*.pb.go'
|
||||||
|
if git diff --cached --quiet; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$HEAD_REPOSITORY" != "$REPOSITORY" ]; then
|
||||||
|
echo "::error::Generated protobufs are out of date. Run make proto and commit the changes."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
git config user.name "actions[bot]"
|
||||||
|
git config user.email "noreply@beejay.kim"
|
||||||
|
git commit -m "Update generated Protobufs"
|
||||||
|
git push origin "HEAD:refs/heads/$HEAD_REF"
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
# Fog Model
|
||||||
|
|
||||||
|
This module contains the Protocol Buffer schemas and generated Go types used to
|
||||||
|
represent Fog deployment data and control messages.
|
||||||
|
|
||||||
|
## Schemas
|
||||||
|
|
||||||
|
- `deployment.proto` defines `DeploymentAction` (`STOP` or `START`),
|
||||||
|
`GlobalEnvironment`, `ConfigFile`, and `Deployment`.
|
||||||
|
- `c2o/operation.proto` defines request `Message` values and `RequestType`
|
||||||
|
(`PING` or `DEPLOYMENT`).
|
||||||
|
|
||||||
|
The generated Go packages are `beejay.kim/fog/model` and
|
||||||
|
`beejay.kim/fog/model/c2o`, respectively. The generated `.pb.go` files are
|
||||||
|
checked in; edit the `.proto` files rather than editing generated code.
|
||||||
|
|
||||||
|
## Using the Go types
|
||||||
|
|
||||||
|
Import the generated package and use the standard Protocol Buffers Go API:
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
model "beejay.kim/fog/model"
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
deployment := &model.Deployment{
|
||||||
|
Id: "example",
|
||||||
|
Action: model.DeploymentAction_START,
|
||||||
|
Env: &model.GlobalEnvironment{
|
||||||
|
Version: "1",
|
||||||
|
Variables: map[string]string{"REGION": "west"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := proto.Marshal(deployment)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var decoded model.Deployment
|
||||||
|
if err := proto.Unmarshal(data, &decoded); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
fmt.Println(decoded.GetId())
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The module requires Go 1.27 and `google.golang.org/protobuf`.
|
||||||
|
|
||||||
|
## Regenerating Go code
|
||||||
|
|
||||||
|
Install `protoc` 36.2 using the [official installation
|
||||||
|
instructions](https://protobuf.dev/installation/), and ensure it and the Go
|
||||||
|
generator are on `PATH`:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
protoc --version
|
||||||
|
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.36.12
|
||||||
|
make proto
|
||||||
|
```
|
||||||
|
|
||||||
|
`make proto` regenerates the Go files from both schemas. Commit the updated
|
||||||
|
`.pb.go` files together with any schema changes. The workflow pushes generated
|
||||||
|
files to same-repository pull request branches; for pull requests from forks,
|
||||||
|
it reports an error if generated files are out of date.
|
||||||
+6
-2
@@ -26,6 +26,7 @@ type DeploymentAction int32
|
|||||||
const (
|
const (
|
||||||
DeploymentAction_STOP DeploymentAction = 0
|
DeploymentAction_STOP DeploymentAction = 0
|
||||||
DeploymentAction_START DeploymentAction = 1
|
DeploymentAction_START DeploymentAction = 1
|
||||||
|
DeploymentAction_CLEANUP DeploymentAction = 2
|
||||||
)
|
)
|
||||||
|
|
||||||
// Enum value maps for DeploymentAction.
|
// Enum value maps for DeploymentAction.
|
||||||
@@ -33,10 +34,12 @@ var (
|
|||||||
DeploymentAction_name = map[int32]string{
|
DeploymentAction_name = map[int32]string{
|
||||||
0: "STOP",
|
0: "STOP",
|
||||||
1: "START",
|
1: "START",
|
||||||
|
2: "CLEANUP",
|
||||||
}
|
}
|
||||||
DeploymentAction_value = map[string]int32{
|
DeploymentAction_value = map[string]int32{
|
||||||
"STOP": 0,
|
"STOP": 0,
|
||||||
"START": 1,
|
"START": 1,
|
||||||
|
"CLEANUP": 2,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -278,10 +281,11 @@ const file_deployment_proto_rawDesc = "" +
|
|||||||
"\x06action\x18\x03 \x01(\x0e2\x17.proto.DeploymentActionR\x06action\x12\x10\n" +
|
"\x06action\x18\x03 \x01(\x0e2\x17.proto.DeploymentActionR\x06action\x12\x10\n" +
|
||||||
"\x03hcl\x18\x04 \x01(\fR\x03hcl\x124\n" +
|
"\x03hcl\x18\x04 \x01(\fR\x03hcl\x124\n" +
|
||||||
"\fconfig_files\x18\n" +
|
"\fconfig_files\x18\n" +
|
||||||
" \x03(\v2\x11.proto.ConfigFileR\vconfigFiles*'\n" +
|
" \x03(\v2\x11.proto.ConfigFileR\vconfigFiles*4\n" +
|
||||||
"\x10DeploymentAction\x12\b\n" +
|
"\x10DeploymentAction\x12\b\n" +
|
||||||
"\x04STOP\x10\x00\x12\t\n" +
|
"\x04STOP\x10\x00\x12\t\n" +
|
||||||
"\x05START\x10\x01B\x16Z\x14beejay.kim/fog/modelb\x06proto3"
|
"\x05START\x10\x01\x12\v\n" +
|
||||||
|
"\aCLEANUP\x10\x02B\x16Z\x14beejay.kim/fog/modelb\x06proto3"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
file_deployment_proto_rawDescOnce sync.Once
|
file_deployment_proto_rawDescOnce sync.Once
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ option go_package = "beejay.kim/fog/model";
|
|||||||
enum DeploymentAction {
|
enum DeploymentAction {
|
||||||
STOP = 0;
|
STOP = 0;
|
||||||
START = 1;
|
START = 1;
|
||||||
|
CLEANUP = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GlobalEnvironment {
|
message GlobalEnvironment {
|
||||||
|
|||||||
Reference in new issue
Block a user