Skip to content

Commit aa861a7

Browse files
committed
Add ability to depend on an arbitary upstream commit
Signed-off-by: Sri Krishna <[email protected]>
1 parent 6568497 commit aa861a7

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

build.gradle.kts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,19 @@ tasks.register("generateTestSources") {
166166
description = "Generates code with buf generate for unit tests"
167167
}
168168

169+
val semverRegex = Regex("""^v\d+\.\d+\.\d+(?:-.+)?$""")
169170
tasks.register<Exec>("exportProtovalidateModule") {
170171
dependsOn("configureBuf")
171172
description = "Exports the bufbuild/protovalidate module sources to src/main/resources."
173+
val version = "${project.findProperty("protovalidate.version")}"
174+
var input = "buf.build/bufbuild/protovalidate:$version"
175+
if (!semverRegex.matches(version)) {
176+
input = "https://github.com/bufbuild/protovalidate.git#subdir=proto/protovalidate,ref=$version"
177+
}
172178
commandLine(
173179
buf.asPath,
174180
"export",
175-
"buf.build/bufbuild/protovalidate:${project.findProperty("protovalidate.version")}",
181+
input,
176182
"--output",
177183
"src/main/resources",
178184
)

conformance/build.gradle.kts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,21 @@ tasks.register<Copy>("filterBufGenYaml") {
6262
filteringCharset = "UTF-8"
6363
}
6464

65+
val semverRegex = Regex("""^v\d+\.\d+\.\d+(?:-.+)?$""")
6566
tasks.register<Exec>("generateConformance") {
6667
dependsOn("configureBuf", "filterBufGenYaml")
6768
description = "Generates sources for the bufbuild/protovalidate-testing module to build/generated/sources/bufgen."
69+
val version = "${project.findProperty("protovalidate.version")}"
70+
var input = "buf.build/bufbuild/protovalidate-testing:$version"
71+
if (!semverRegex.matches(version)) {
72+
input = "https://github.com/bufbuild/protovalidate.git#subdir=proto/protovalidate-testing,ref=$version"
73+
}
6874
commandLine(
6975
buf.asPath,
7076
"generate",
7177
"--template",
7278
"${layout.buildDirectory.get()}/buf-gen-templates/buf.gen.yaml",
73-
"buf.build/bufbuild/protovalidate-testing:${project.findProperty("protovalidate.version")}",
79+
input,
7480
)
7581
}
7682

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Version of buf.build/bufbuild/protovalidate to use.
2-
protovalidate.version = v1.1.0
2+
protovalidate.version = 895eefca6d1346f742fc18b9983d40478820906d
33

44
# Arguments to the protovalidate-conformance CLI
55
protovalidate.conformance.args = --strict_message --strict_error --expected_failures=expected-failures.yaml

src/main/resources/buf/validate/validate.proto

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,34 @@
1414

1515
syntax = "proto2";
1616

17+
// [Protovalidate](https://protovalidate.com/) is the semantic validation library for Protobuf.
18+
// It provides standard annotations to validate common rules on messages and fields, as well as the ability to use [CEL](https://cel.dev) to write custom rules.
19+
// It's the next generation of [protoc-gen-validate](https://github.com/bufbuild/protoc-gen-validate).
20+
//
21+
// This package provides the options, messages, and enums that power Protovalidate.
22+
// Apply its options to messages, fields, and oneofs in your Protobuf schemas to add validation rules:
23+
//
24+
// ```proto
25+
// message User {
26+
// string id = 1 [(buf.validate.field).string.uuid = true];
27+
// string first_name = 2 [(buf.validate.field).string.max_len = 64];
28+
// string last_name = 3 [(buf.validate.field).string.max_len = 64];
29+
//
30+
// option (buf.validate.message).cel = {
31+
// id: "first_name_requires_last_name"
32+
// message: "last_name must be present if first_name is present"
33+
// expression: "!has(this.first_name) || has(this.last_name)"
34+
// };
35+
// }
36+
// ```
37+
//
38+
// These rules are enforced at runtime by language-specific libraries.
39+
// See the [developer quickstart](https://protovalidate.com/quickstart/) to get started, or go directly to the runtime library for your language:
40+
// [Go](https://github.com/bufbuild/protovalidate-go)
41+
// [JavaScript/TypeScript](https://github.com/bufbuild/protovalidate-es),
42+
// [Java](https://github.com/bufbuild/protovalidate-java),
43+
// [Python](https://github.com/bufbuild/protovalidate-python),
44+
// or [C++](https://github.com/bufbuild/protovalidate-cc).
1745
package buf.validate;
1846

1947
import "google/protobuf/descriptor.proto";

0 commit comments

Comments
 (0)