-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cybozu.validate is a normalization and validation system for Protocol Buffers. The repository is set up for a Buf module in order to prepare publishing protobuf files on BSR. This commit does not include any code generator but includes a hand-written Go code `examples/validation_cybozu_validate2.pb.go` to demonstrate what to be generated.
- Loading branch information
Showing
25 changed files
with
4,718 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
name: Bug report | ||
about: Create a report to help us improve | ||
title: '' | ||
labels: bug | ||
assignees: '' | ||
|
||
--- | ||
|
||
**Describe the bug** | ||
A clear and concise description of what the bug is. | ||
|
||
**Environments** | ||
- Version: | ||
- OS: | ||
|
||
**To Reproduce** | ||
Steps to reproduce the behavior: | ||
1. Go to '...' | ||
2. Click on '....' | ||
3. Scroll down to '....' | ||
4. See error | ||
|
||
**Expected behavior** | ||
A clear and concise description of what you expected to happen. | ||
|
||
**Additional context** | ||
Add any other context about the problem here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
name: Task | ||
about: Describe this issue | ||
title: '' | ||
labels: '' | ||
assignees: '' | ||
|
||
--- | ||
|
||
## What | ||
|
||
Describe what this issue should address. | ||
|
||
## How | ||
|
||
Describe how to address the issue. | ||
|
||
## Checklist | ||
|
||
- [ ] Finish implementation of the issue | ||
- [ ] Test all functions | ||
- [ ] Have enough logs to trace activities | ||
- [ ] Notify developers of necessary actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: CI | ||
on: [push] | ||
jobs: | ||
test: | ||
name: Run tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-go@v3 | ||
with: | ||
go-version-file: go.mod | ||
cache: true | ||
- run: make lint | ||
- run: make check-generate | ||
- run: make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Release | ||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
release: | ||
name: Release on GitHub | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- run: git fetch --force --tags | ||
- uses: actions/setup-go@v3 | ||
with: | ||
go-version-file: go.mod | ||
cache: true | ||
- uses: bufbuild/buf-setup-action@b5ee8ca8d082edeeb8b0fc7fe1178ae0d671816a # v1.15.0 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
- uses: bufbuild/buf-push-action@1c45f6a21ec277ee4c1fa2772e49b9541ea17f38 # v1.1.1 | ||
with: | ||
buf_token: ${{ secrets.BSR_TOKEN }} | ||
- name: GoReleaser | ||
uses: goreleaser/goreleaser-action@f82d6c1c344bcacabba2c841718984797f664a6b # v4.2.0 | ||
with: | ||
distribution: goreleaser | ||
version: latest | ||
args: release --clean | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# This is an example .goreleaser.yml file with some sensible defaults. | ||
# Make sure to check the documentation at https://goreleaser.com | ||
builds: | ||
- env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- linux | ||
- windows | ||
- darwin | ||
main: ./cmd/protoc-gen-go-cybozu-validate | ||
binary: protoc-gen-go-cybozu-validate | ||
|
||
archives: | ||
- format: tar.gz | ||
# this name template makes the OS and Arch compatible with the results of uname. | ||
name_template: >- | ||
{{ .ProjectName }}_ | ||
{{- title .Os }}_ | ||
{{- if eq .Arch "amd64" }}x86_64 | ||
{{- else if eq .Arch "386" }}i386 | ||
{{- else }}{{ .Arch }}{{ end }} | ||
{{- if .Arm }}v{{ .Arm }}{{ end }} | ||
# use zip for windows archives | ||
format_overrides: | ||
- goos: windows | ||
format: zip | ||
checksum: | ||
name_template: 'checksums.txt' | ||
snapshot: | ||
name_template: "{{ incpatch .Version }}-next" | ||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- '^docs:' | ||
- '^test:' | ||
|
||
release: | ||
prerelease: auto | ||
|
||
# The lines beneath this are called `modelines`. See `:help modeline` | ||
# Feel free to remove those if you don't want/use them. | ||
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json | ||
# vim: set ts=2 sw=2 tw=0 fo=cnqoj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Makefile for compiling protobuf files | ||
|
||
# Tool versions | ||
BUF_VERSION = 1.15.0 | ||
GO_VERSION := $(shell awk '/^go / {print $$2}' go.mod) | ||
PROTOC_GEN_GO_VERSION := $(shell awk '/google.golang.org\/protobuf/ {print substr($$NF, 2)}' go.mod) | ||
|
||
|
||
## sanity checks | ||
ifeq ($(shell go version | grep -F $(GO_VERSION)),) | ||
$(error Go must be version $(GO_VERSION)) | ||
endif | ||
|
||
# Variables | ||
PWD := $(shell pwd) | ||
BUF = $(PWD)/bin/buf | ||
RUN_BUF = PATH=$(PWD)/bin:$$PATH ./bin/buf | ||
PROTOC_GEN_GO = $(PWD)/bin/protoc-gen-go | ||
PROTOC_GEN_GO_CYBOZU_VALIDATE = $(PWD)/bin/protoc-gen-go-validate | ||
|
||
help: | ||
@echo 'Available targets:' | ||
@echo ' all: build everything.' | ||
@echo ' test: run tests.' | ||
@echo ' clean: remove downloaded files.' | ||
@echo ' check-generate: test if the generated files are up-to-date or not.' | ||
@echo ' lint: lint protobuf files.' | ||
@echo ' format: format protobuf files.' | ||
@echo ' go: generate Go code with protoc-gen-go.' | ||
@echo ' validate: generate code for normalization/validation.' | ||
@echo ' create-tag: creates a new Git tag.' | ||
|
||
$(BUF): | ||
mkdir -p bin | ||
GOBIN=$(PWD)/bin go install github.com/bufbuild/buf/cmd/buf@v$(BUF_VERSION) | ||
|
||
$(PROTOC_GEN_GO): | ||
mkdir -p bin | ||
GOBIN=$(PWD)/bin go install google.golang.org/protobuf/cmd/protoc-gen-go@v$(PROTOC_GEN_GO_VERSION) | ||
|
||
$(PROTOC_GEN_GO_CYBOZU_VALIDATE): | ||
mkdir -p bin | ||
go build -o $@ ./cmd/protoc-gen-go-cybozu-validate | ||
|
||
.PHONY: all | ||
all: | ||
$(MAKE) format | ||
$(MAKE) go | ||
echo skip this for now $(MAKE) validate | ||
|
||
.PHONY: test | ||
test: | ||
go test -count 1 -v ./... | ||
go vet ./... | ||
test -z $$(gofmt -s -l . | tee /dev/stderr) | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf bin dist | ||
|
||
.PHONY: check-generate | ||
check-generate: | ||
$(MAKE) all | ||
go mod tidy | ||
git diff --exit-code --name-only | ||
|
||
.PHONY: lint | ||
lint: $(BUF) | ||
$(RUN_BUF) lint | ||
|
||
.PHONY: format | ||
format: $(BUF) | ||
$(RUN_BUF) format -w | ||
|
||
.PHONY: go | ||
go: $(BUF) $(PROTOC_GEN_GO) | ||
$(RUN_BUF) generate --template buf.go.gen.yaml | ||
|
||
.PHONY: validate | ||
validate: $(BUF) $(PROTOC_GEN_GO_CYBOZU_VALIDATE) | ||
$(RUN_BUF) generate --template buf.go-cybozu-validate.gen.yaml | ||
|
||
.PHONY: create-tag | ||
create-tag: | ||
./create-tag.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,67 @@ | ||
# protonorm | ||
Normalization and validation system for Protocol Buffers | ||
# Cybozu Public Protocol Buffers Schema | ||
|
||
This repository contains public Protocol Buffer files and related tools from Cybozu. | ||
|
||
This repository forms a [Buf module][module] to publish protobuf files on [BSR][BSR]. | ||
You can import packages in this repository by adding the following lines to `buf.yaml`. | ||
|
||
```yaml | ||
version: v1 | ||
deps: | ||
- buf.build/cybozu/protobuf | ||
``` | ||
If you are not familiar with `buf`, read https://docs.buf.build/manuals/cli/overview | ||
|
||
## `cybozu.validate` | ||
|
||
This protobuf package provides custom options to normalize and validate messages. | ||
Read [examples/validation.proto](examples/validation.proto) for example usage. | ||
|
||
You can get the code generator for Go as follows: | ||
|
||
```console | ||
$ go install github.com/cybozu/protobuf/cmd/protoc-gen-go-cybozu-validate@latest | ||
``` | ||
|
||
The following is an example `buf.gen.yaml` to generate validation code: | ||
|
||
```yaml | ||
version: v1 | ||
plugins: | ||
- plugin: go | ||
out: . | ||
opt: paths=source_relative | ||
- plugin: go-cybozu-validate | ||
out: . | ||
opt: paths=source_relative | ||
``` | ||
|
||
## API documentation | ||
|
||
Visit https://buf.build/cybozu/protobuf | ||
|
||
## Versioning and backward-compatibility | ||
|
||
We keep backward-compatibility of Protocol Buffers files. | ||
When we want to add breaking changes to Protocol Buffers files, we create | ||
a different package like `cybozu.foo.v2` not to break the current package. | ||
|
||
However, the generated code in this repository may not be backward compatible. | ||
For example, Go code generated by `protoc-gen-go` may not be always backward compatible. | ||
|
||
So, we use a [semver](https://semver.org/) with major version zero (0.y.z) to | ||
tag this repository to declare the generated code may bring breaking changes. | ||
|
||
### For developers | ||
|
||
Running `make create-tag` creates a new tag and push it to GitHub automatically. | ||
The rest of the release process will be done by GitHub Actions. | ||
|
||
## License | ||
|
||
All code in this repository is licensed under the Apache License Version 2.0. | ||
Read [LICENSE](LICENSE) for terms and conditions. | ||
|
||
[module]: https://docs.buf.build/bsr/overview#modules | ||
[BSR]: https://docs.buf.build/bsr/introduction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
version: v1 | ||
plugins: | ||
- name: go-cybozu-validate | ||
out: . | ||
opt: | ||
- paths=source_relative |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
version: v1 | ||
plugins: | ||
- name: go | ||
out: . | ||
opt: | ||
- paths=source_relative |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Cybozu Public Protocol Buffers Schema | ||
|
||
This module provides Protocol Buffers packages that are intended for public use. | ||
Currently, following packages are available: | ||
|
||
- `cybozu.validate`: custom options for generating normalization & validation code. | ||
- `examples`: usage examples of our custom Protocol Buffer options. | ||
|
||
The source code is available on https://github.com/cybozu/protobuf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
version: v1 | ||
name: buf.build/cybozu/protobuf | ||
breaking: | ||
use: | ||
- FILE | ||
lint: | ||
use: | ||
- BASIC | ||
except: | ||
- ENUM_PASCAL_CASE | ||
- ENUM_NO_ALLOW_ALIAS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package main | ||
|
||
func main() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
if [ "$(git branch --show-current)" != main ]; then | ||
echo "not on the main branch." | ||
exit 1 | ||
fi | ||
|
||
echo "Running git pull to be up-to-date." | ||
git fetch origin --prune --prune-tags | ||
|
||
MAJOR=0 | ||
MINOR=$(date '+%Y%m%d') | ||
REV=0 | ||
|
||
while true; do | ||
TAG=v${MAJOR}.${MINOR}.${REV} | ||
if git tag | grep -qF ${TAG}; then | ||
REV=$((REV + 1)) | ||
else | ||
break | ||
fi | ||
done | ||
|
||
echo "Creating a new Git tag ${TAG}" | ||
echo -n "Proceed? [y/N]: " | ||
read t | ||
if echo $t | grep -i '^y'; then | ||
: | ||
else | ||
echo "Aborted." | ||
exit 1 | ||
fi | ||
|
||
git tag -a -m "Release ${TAG}" ${TAG} | ||
git push origin ${TAG} | ||
|
||
echo "Tagged and pushed ${TAG}" |
Oops, something went wrong.