From 413dde7dee99e272c7152e7f6f01061cde7d24b1 Mon Sep 17 00:00:00 2001 From: Cody Littley <56973212+cody-littley@users.noreply.github.com> Date: Fri, 11 Oct 2024 09:01:19 -0500 Subject: [PATCH] Validate protos workflow (#799) Signed-off-by: Cody Littley --- .github/workflows/compile-protobufs.yaml | 22 ++++++++++++++++++++++ api/builder/Dockerfile | 10 ++++++++-- api/builder/build-docker.sh | 18 +++++++++++++++++- api/builder/is-repo-clean.sh | 14 ++++++++++++++ api/builder/protoc-docker.sh | 7 +++++++ api/builder/protoc.sh | 16 ++++++++++++++++ 6 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/compile-protobufs.yaml create mode 100755 api/builder/is-repo-clean.sh diff --git a/.github/workflows/compile-protobufs.yaml b/.github/workflows/compile-protobufs.yaml new file mode 100644 index 000000000..88c54069b --- /dev/null +++ b/.github/workflows/compile-protobufs.yaml @@ -0,0 +1,22 @@ +name: compile-protobufs +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + golangci: + name: Compile Protobufs + runs-on: ubuntu-latest + steps: + - name: Checkout EigenDA + uses: actions/checkout@v3 + - name: Recompile Protobufs + run: | + make clean + make protoc + - name: Verify No Git Changes + run: ./api/builder/is-repo-clean.sh diff --git a/api/builder/Dockerfile b/api/builder/Dockerfile index 97fc309b5..612f8df3c 100644 --- a/api/builder/Dockerfile +++ b/api/builder/Dockerfile @@ -1,11 +1,17 @@ FROM golang:1.21.12-bookworm +# The URL where the protoc binary can be downloaded. Is different depending on architecture. +ARG PROTOC_URL + +# The UID of the user to create +ARG UID + # Install core dependencies RUN apt update RUN apt install -y wget unzip bash # Set up user -RUN useradd -m -s /bin/bash user +RUN useradd -u $UID -m -s /bin/bash user USER user WORKDIR /home/user # Remove default crud @@ -14,7 +20,7 @@ RUN rm .bash_logout RUN rm .profile # Install protoc -RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v23.4/protoc-23.4-linux-aarch_64.zip +RUN wget $PROTOC_URL RUN mkdir protoc RUN cd protoc && unzip ../*.zip RUN rm ./*.zip diff --git a/api/builder/build-docker.sh b/api/builder/build-docker.sh index 1ae4147ba..eb826b43a 100755 --- a/api/builder/build-docker.sh +++ b/api/builder/build-docker.sh @@ -3,10 +3,26 @@ # The location where this script can be found. SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +ARCH=$(uname -m) +if [ "${ARCH}" == "arm64" ]; then + PROTOC_URL='https://github.com/protocolbuffers/protobuf/releases/download/v23.4/protoc-23.4-linux-aarch_64.zip' +elif [ "${ARCH}" == "x86_64" ]; then + PROTOC_URL='https://github.com/protocolbuffers/protobuf/releases/download/v23.4/protoc-23.4-linux-x86_64.zip' +else + echo "Unsupported architecture: ${ARCH}" + exit 1 +fi + # Add the --no-cache flag to force a rebuild. # Add the --progress=plain flag to show verbose output during the build. docker build \ -f "${SCRIPT_DIR}/Dockerfile" \ --tag pbuf-compiler:latest \ - . \ No newline at end of file + --build-arg PROTOC_URL="${PROTOC_URL}" \ + --build-arg UID=$(id -u) \ + . + +if [ $? -ne 0 ]; then + exit 1 +fi \ No newline at end of file diff --git a/api/builder/is-repo-clean.sh b/api/builder/is-repo-clean.sh new file mode 100755 index 000000000..22dddf4ee --- /dev/null +++ b/api/builder/is-repo-clean.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +# This script exits with error code 0 if the git repository is clean, and error code 1 if it is not. +# This is utilized by the github workflow that checks to see if the repo is clean after recompiling +# protobufs. + +if output=$(git status --porcelain) && [ -z "$output" ]; then + echo "Repository is clean." + exit 0 +else + echo "Repository is dirty:" + git status + exit 1 +fi \ No newline at end of file diff --git a/api/builder/protoc-docker.sh b/api/builder/protoc-docker.sh index 5d61552c2..ff6f1496c 100755 --- a/api/builder/protoc-docker.sh +++ b/api/builder/protoc-docker.sh @@ -11,8 +11,15 @@ if [ -z "$(docker images -q pbuf-compiler:latest 2> /dev/null)" ]; then "${SCRIPT_DIR}"/build-docker.sh fi +if [ $? -ne 0 ]; then + exit 1 +fi docker container run \ --rm \ --mount "type=bind,source=${ROOT},target=/home/user/eigenda" \ pbuf-compiler bash -c "source ~/.bashrc && eigenda/api/builder/protoc.sh" + +if [ $? -ne 0 ]; then + exit 1 +fi \ No newline at end of file diff --git a/api/builder/protoc.sh b/api/builder/protoc.sh index f5d23c9df..20819d2d8 100755 --- a/api/builder/protoc.sh +++ b/api/builder/protoc.sh @@ -12,6 +12,10 @@ PROTO_DIR="${API_DIR}/proto" GRPC_DIR="${API_DIR}/grpc" mkdir -p "${GRPC_DIR}" +if [ $? -ne 0 ]; then + exit 1 +fi + PROTO_FILES=( $(find "${PROTO_DIR}" -name '*.proto') ) protoc -I "${PROTO_DIR}" \ @@ -21,6 +25,10 @@ protoc -I "${PROTO_DIR}" \ --go-grpc_opt=paths=source_relative \ ${PROTO_FILES[@]} +if [ $? -ne 0 ]; then + exit 1 +fi + # Build protobufs in the disperser/api/proto directory. DISPERSER_DIR="$SCRIPT_DIR/../../disperser" @@ -28,6 +36,10 @@ DISPERSER_PROTO_DIR="$DISPERSER_DIR/api/proto" DISPERSER_GRPC_DIR="$DISPERSER_DIR/api/grpc" mkdir -p "${DISPERSER_GRPC_DIR}" +if [ $? -ne 0 ]; then + exit 1 +fi + DISPERSER_PROTO_FILES=( $(find "${DISPERSER_PROTO_DIR}" -name '*.proto') ) protoc -I "${DISPERSER_PROTO_DIR}" -I "${PROTO_DIR}" \ @@ -36,3 +48,7 @@ protoc -I "${DISPERSER_PROTO_DIR}" -I "${PROTO_DIR}" \ --go-grpc_out="${DISPERSER_GRPC_DIR}" \ --go-grpc_opt=paths=source_relative \ ${DISPERSER_PROTO_FILES[@]} + +if [ $? -ne 0 ]; then + exit 1 +fi \ No newline at end of file