fix: Regenerate flatbuffers in a Docker container by default

pull/24376/head
Carol (Nichols || Goulding) 2021-04-15 12:53:42 -04:00 committed by kodiakhq[bot]
parent 2934370426
commit 9cc5b1950a
2 changed files with 69 additions and 36 deletions

View File

@ -168,7 +168,7 @@ jobs:
- rust_components # Regenerating flatbuffers uses rustfmt - rust_components # Regenerating flatbuffers uses rustfmt
- run: - run:
name: Check Flatbuffers name: Check Flatbuffers
command: ./generated_types/check-flatbuffers.sh command: LOCAL=1 ./generated_types/check-flatbuffers.sh
# Compile a cargo "release" profile binary for branches that end in `/perf` # Compile a cargo "release" profile binary for branches that end in `/perf`
# #

View File

@ -24,45 +24,78 @@ FB_COMMIT="86401e078d0746d2381735415f8c2dfe849f3f52"
# - Check in the changes to the generated code along with your changes to the `Cargo.lock` file and # - Check in the changes to the generated code along with your changes to the `Cargo.lock` file and
# this script. # this script.
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" # By default, this script will run a Docker container that uses the same image we use in CI that
pushd $DIR # will have all the necessary dependencies. If you don't want to run Docker, run this script with
# LOCAL=1.
if [ -z ${LOCAL} ]; then
echo "Running in Docker..."
echo "Building flatc from source ..." CI_IMAGE=quay.io/influxdb/rust:ci
FB_URL="https://github.com/google/flatbuffers" DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
FB_DIR=".flatbuffers" pushd $DIR
FLATC="$FB_DIR/bazel-bin/flatc"
if [ -z $(which bazel) ]; then DOCKER_IOX_DIR=/home/rust/influxdb_iox
echo "bazel is required to build flatc"
exit 1
fi
echo "Bazel version: $(bazel version | head -1 | awk -F':' '{print $2}')" docker kill flatc || true
docker rm flatc || true
if [ ! -e $FB_DIR ]; then docker pull ${CI_IMAGE} || true
echo "git clone $FB_URL ..."
git clone -b master --no-tag $FB_URL $FB_DIR docker run \
-it \
--detach \
--name=flatc \
--volume ${DIR}/..:${DOCKER_IOX_DIR} \
${CI_IMAGE}
docker exec -e LOCAL=1 flatc .${DOCKER_IOX_DIR}/generated_types/regenerate-flatbuffers.sh
docker kill flatc || true
docker rm flatc || true
else else
echo "git pull $FB_URL ..." echo "Running locally..."
git -C $FB_DIR pull --ff-only
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
pushd $DIR
echo "Building flatc from source ..."
FB_URL="https://github.com/google/flatbuffers"
FB_DIR=".flatbuffers"
FLATC="$FB_DIR/bazel-bin/flatc"
if [ -z $(which bazel) ]; then
echo "bazel is required to build flatc"
exit 1
fi
echo "Bazel version: $(bazel version | head -1 | awk -F':' '{print $2}')"
if [ ! -e $FB_DIR ]; then
echo "git clone $FB_URL ..."
git clone -b master --no-tag $FB_URL $FB_DIR
else
echo "git pull $FB_URL ..."
git -C $FB_DIR pull --ff-only
fi
echo "hard reset to $FB_COMMIT"
git -C $FB_DIR reset --hard $FB_COMMIT
pushd $FB_DIR
echo "run: bazel build :flatc ..."
bazel build :flatc
popd
RUST_DIR="$DIR/src"
while read -r FBS_FILE; do
echo "Compiling ${FBS_FILE}"
$FLATC --rust -o $RUST_DIR $FBS_FILE
done < <(git ls-files $DIR/*.fbs)
cargo fmt
popd
echo "DONE! Please run 'cargo test' and check in any changes."
fi fi
echo "hard reset to $FB_COMMIT"
git -C $FB_DIR reset --hard $FB_COMMIT
pushd $FB_DIR
echo "run: bazel build :flatc ..."
bazel build :flatc
popd
RUST_DIR="$DIR/src"
while read -r FBS_FILE; do
echo "Compiling ${FBS_FILE}"
$FLATC --rust -o $RUST_DIR $FBS_FILE
done < <(git ls-files $DIR/*.fbs)
cargo fmt
popd
echo "DONE! Please run 'cargo test' and check in any changes."