Skip to content

Commit 3002f60

Browse files
committed
chore: add shell script simulating the developer experience
1 parent ac531ae commit 3002f60

3 files changed

Lines changed: 41 additions & 13 deletions

File tree

examples/foo.pb.go

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

examples/foo.proto

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ package foo;
55
message Foo {
66
string name = 1;
77
string description = 2;
8-
int32 age = 3;
98
}

examples/test.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Shows an end-to-end workflow for accepting new patches without failing the build.
4+
set -o errexit -o pipefail -o nounset
5+
6+
if [ "$#" -eq 0 ]; then
7+
echo "usage: test.sh [target pattern...]"
8+
exit 1
9+
fi
10+
11+
fix=""
12+
buildevents=$(mktemp)
13+
filter='.namedSetOfFiles | values | .files[] | select(.name | endswith($ext)) | ((.pathPrefix | join("/")) + "/" + .name)'
14+
15+
args=(
16+
"--keep_going"
17+
"--output_groups=diff_bzl__patch"
18+
"--build_event_json_file=$buildevents"
19+
"--remote_download_regex='.*\.patch'"
20+
)
21+
22+
# Run build with validation disabled and output group for patches.
23+
# This will present us with patches to apply
24+
if ! bazel build ${args[@]} $@; then
25+
echo "Build failed, applying patches"
26+
to_apply_patches=$(jq --arg ext .patch --raw-output "$filter" "$buildevents" | tr -d '\r')
27+
wksp=$(bazel info workspace)
28+
for patch in $to_apply_patches; do
29+
# continue if patch file content is empty
30+
if [[ ! -s "${wksp}/${patch}" ]]; then
31+
continue
32+
fi
33+
echo "Applying patch ${patch}"
34+
patch -d ${wksp} -p0 <${wksp}/${patch}
35+
done
36+
fi
37+
38+
exec bazel test $@

0 commit comments

Comments
 (0)