Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate protos workflow #799

Merged
merged 4 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/compile-protobufs.yaml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 8 additions & 2 deletions api/builder/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
18 changes: 17 additions & 1 deletion api/builder/build-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
.
--build-arg PROTOC_URL="${PROTOC_URL}" \
--build-arg UID=$(id -u) \
.

if [ $? -ne 0 ]; then
exit 1
fi
14 changes: 14 additions & 0 deletions api/builder/is-repo-clean.sh
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions api/builder/protoc-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 16 additions & 0 deletions api/builder/protoc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}" \
Expand All @@ -21,13 +25,21 @@ 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"
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}" \
Expand All @@ -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
Loading