Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: build using buf #3368

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions .github/workflows/generated-files.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,41 @@ on:
- main
- v*
paths-ignore:
- 'docs/**'
- "docs/**"
pull_request:
paths-ignore:
- 'docs/**'
- "docs/**"

jobs:
checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: 0
- name: Lint protobuf
run: |
# TODO: enable linting once we have a chance to fix the underlying issues
# make -C api lint EXTRA_BUF_FLAGS="--error-format=github-actions"
make -C api check-breaking EXTRA_BUF_FLAGS="--error-format=github-actions" BUF_BREAKING_AGAINST_BRANCH="origin/${{ github.base_ref }}"
make -C api format EXTRA_BUF_FLAGS="--exit-code --error-format=github-actions"
generated-files:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- name: Install Go
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
with:
# renovate: datasource=golang-version depName=go
go-version: '1.23.5'
go-version: "1.23.5"
- name: Go version
run: go version
- name: Validate that generated files are up to date.
run: |
make generate
make codegen
make codegen BUF_BREAKING_AGAINST_BRANCH="origin/${{ github.base_ref }}"
git status
git diff
test -z "$(git status --porcelain)"
Expand Down
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@

include Makefile.defs

GO ?= go
INSTALL = $(QUIET)install
BINDIR ?= /usr/local/bin
CONTAINER_ENGINE ?= docker
DOCKER_IMAGE_TAG ?= latest
LOCAL_CLANG ?= 0
LOCAL_CLANG_FORMAT ?= 0
Expand Down
8 changes: 8 additions & 0 deletions Makefile.defs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ endef
define print_help_option
@printf " \033[35m%-22s\033[0m %s\n" $(1) '$(2)'
endef

GO ?= go
CONTAINER_ENGINE ?= docker

BUF ?= buf
BUF_BREAKING_AGAINST_BRANCH ?= origin/main
# renovate: datasource=docker
BUILDER_IMAGE=quay.io/cilium/cilium-builder:cd04ac813fb4763f840911c88beae99efc4aa457
50 changes: 38 additions & 12 deletions api/Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,53 @@
# Copyright 2017-2020 Authors of Cilium
# SPDX-License-Identifier: Apache-2.0

# renovate: datasource=docker
BUILDER_IMAGE=quay.io/cilium/cilium-builder@sha256:a2036a3f6420647e6702695dabd2ffa4d2832db45157042d0255bdc707b8e1f2
GO ?= go
include ../Makefile.defs

EXTRA_BUF_FLAGS ?=

.PHONY: all
all: proto
all:

# FIXME: re-enable lint on the all target once we have a chance to fix the lints
.PHONY: __all_local
__all_local: __format_local __check-breaking_local __proto_local #__lint_local

.PHONY: __proto_local
__proto_local:
$(BUF) generate $(EXTRA_BUF_FLAGS)

.PHONY: __lint_local
__lint_local:
$(BUF) lint $(EXTRA_BUF_FLAGS)

.PHONY: __format_local
__format_local:
$(BUF) format -w $(EXTRA_BUF_FLAGS)

.PHONY: proto
proto: v1
.PHONY: __check-breaking_local
__check-breaking_local:
$(BUF) breaking /src/api --against "$(CURDIR)/../.git#branch=$(BUF_BREAKING_AGAINST_BRANCH),subdir=api/v1" $(EXTRA_BUF_FLAGS)

.PHONY: proto lint format check-breaking
all proto lint format check-breaking:
$(CONTAINER_ENGINE) container run --rm \
--volume $(CURDIR)/..:/src \
--workdir /src/api \
--user "$(shell id -u):$(shell id -g)" \
$(BUILDER_IMAGE) \
make -C /src/api __$@_local BUF_BREAKING_AGAINST_BRANCH=$(BUF_BREAKING_AGAINST_BRANCH)

.PHONY: v1
v1:
docker container run --rm \
.PHONY: debug
debug:
@echo $(CONTAINER_ENGINE) container run --rm \
--volume $(CURDIR)/..:/src \
--workdir /src/api \
--user "$(shell id -u):$(shell id -g)" \
$(BUILDER_IMAGE) \
make -C /src/api/v1 -f Makefile.protoc
./export-doc.sh ../docs/content/en/docs/reference/grpc-api.md
buf $(EXTRA_BUF_FLAGS)

.PHONY: vendor
vendor:
$(GO) mod tidy
$(GO) mod vendor
$(GO) mod verify
$(GO) mod verify
16 changes: 16 additions & 0 deletions api/buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: v2
plugins:
- local: protoc-gen-go
out: ./v1
opt:
- paths=source_relative
- local: protoc-gen-go-json
out: ./v1
opt:
- paths=source_relative
- orig_name=true
- local: protoc-gen-doc
out: ./v1
opt:
- markdown
- README.md
28 changes: 28 additions & 0 deletions api/buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: v2

modules:
- path: v1

lint:
use:
# See full list here: https://buf.build/docs/lint/rules/
# TODO: it's going to take a lot of work to document everything before enabling this.
# - COMMENTS
- STANDARD
enum_zero_value_suffix: UNDEF
except:
# Too late to do this without breaking.
- ENUM_VALUE_PREFIX
# Might be too late to do this without breaking.
- PACKAGE_VERSION_SUFFIX
disallow_comment_ignores: false

breaking:
use:
- FILE
- WIRE_JSON
except:
- FILE_SAME_GO_PACKAGE
# Ignores packages with a last component that's one of the unstable forms
# (e.g. foo.bar.v1alpha foo.bar.v1beta)
ignore_unstable_packages: true
67 changes: 0 additions & 67 deletions api/v1/Makefile.protoc

This file was deleted.

Loading
Loading