Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
naderzare authored Oct 19, 2024
2 parents 7085b65 + 3903a0a commit 7616cd7
Show file tree
Hide file tree
Showing 6 changed files with 3,473 additions and 185 deletions.
118 changes: 118 additions & 0 deletions .github/workflows/generator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
name: Generate Protobuf Documentation

# Define a manual trigger with input for version
on:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest

steps:
# Step 1: Checkout the repository code
- name: Checkout code
uses: actions/checkout@v3

# Step 1.1: Check Version Number
- name: Check Version Number
run: |
pwd
PROTO_VERSION=$(grep -oP '(?<=version\s)[0-9]+\.[0-9]+' ./idl/grpc/service.proto)
THRIFT_VERSION=$(grep -oP '(?<=version\s)[0-9]+\.[0-9]+' ./idl/thrift/soccer_service.thrift)
if [ "$PROTO_VERSION" != "$THRIFT_VERSION" ]; then
echo "Version mismatch: Protobuf version is $PROTO_VERSION, Thrift version is $THRIFT_VERSION"
exit 1
fi
# Step 2: Install dependencies for protoc
- name: Install protoc dependencies
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler wget

# Step 3: Download precompiled protoc-gen-doc binary
- name: Download protoc-gen-doc binary
run: |
# Download the appropriate precompiled binary for Linux
wget https://github.com/pseudomuto/protoc-gen-doc/releases/download/v1.5.1/protoc-gen-doc_1.5.1_linux_amd64.tar.gz -O protoc-gen-doc.tar.gz
# Extract the binary from the tarball
tar -xvf protoc-gen-doc.tar.gz
# Ensure it's an executable binary
file protoc-gen-doc
# Make it executable
chmod +x protoc-gen-doc
# Move the binary to /usr/local/bin
sudo mv protoc-gen-doc /usr/local/bin/
# Step 4: Generate Markdown from the Protobuf file
- name: Generate Protobuf Documentation
run: |
# Generate markdown from .proto file
protoc --doc_out=./idl --doc_opt=markdown,readme.md ./idl/grpc/service.proto
# Step 5: Extract version from the first line of the .proto file
- name: Extract version from .proto file
id: extract_version
run: |
VERSION=$(grep -oP '(?<=version\s)[0-9]+\.[0-9]+' ./idl/grpc/service.proto)
echo "VERSION=$VERSION" >> $GITHUB_ENV
# Step 6: Insert version into the generated Markdown file
- name: Insert version into markdown
run: |
sed -i '3a\\n## Version: '"${{ env.VERSION }}"'\n' ./idl/readme.md
# Step 7: Replace &gt; and &lt; in Mermaid diagrams with > and <
- name: Fix Mermaid symbols in readme.md
run: |
sed -i 's/&gt;/>/g' ./idl/readme.md
sed -i 's/&lt;/</g' ./idl/readme.md
# Step 8: Configure Git and commit the updated readme.md
- name: Configure Git
run: |
git config --global user.name "GitHub Action"
git config --global user.email "[email protected]"
# Step 10: Stage and Commit Changes
- name: Stage and Commit Changes
run: |
ls ./idl
git status
git add ./idl/readme.md # Ensure the correct file is added
git diff --quiet || git commit -m "Update protobuf documentation with version and fixed Mermaid symbols" || echo "No changes to commit"
# Step 11: Push the changes
- name: Push Changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: git push

# Step 12: Clone the website repository and push the updated protobuf.md
- name: Push to Website Repo
env:
WEBSITE_TOKEN: ${{ secrets.WEBSITE_TOKEN }} # Add your Personal Access Token (PAT) as a secret
run: |
# Clone the website repository
git clone https://[email protected]/CLSFramework/CLSFramework.github.io.git website
# Copy the generated readme.md and rename it to protobuf.md
mv ./idl/readme.md ./website/docs/3-idl/protobuf.md
# Commit and push changes to the website repo only if there are changes
cd website
git config --global user.name "GitHub Action"
git config --global user.email "[email protected]"
# Check if there are any changes
if git diff --quiet; then
echo "No changes detected, skipping commit and push."
else
git add ./docs/3-idl/protobuf.md
git commit -m "Update protobuf documentation with version and fixed Mermaid symbols"
git push
fi
13 changes: 12 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,15 @@ grpc/python-v1/src/__pycache__/
.idea/
cmake-build-debug-event-trace/
__pycache__/
grpc/python-v1/src/__pycache__/
grpc/python-v1/src/__pycache__/

src/grpc-generated/service.grpc.pb.cc
src/grpc-generated/service.grpc.pb.h
src/grpc-generated/service.pb.cc
src/grpc-generated/service.pb.h
src/thrift-generated/Game_server.skeleton.cpp
src/thrift-generated/Game.cpp
src/thrift-generated/Game.h
src/thrift-generated/soccer_service_types.cpp
src/thrift-generated/soccer_service_types.h
idl/test.md
28 changes: 28 additions & 0 deletions idl/generate-local-md.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh

# sudo apt-get update && sudo apt-get install -y protobuf-compiler wget

# # Download the appropriate precompiled binary for Linux
# wget https://github.com/pseudomuto/protoc-gen-doc/releases/download/v1.5.1/protoc-gen-doc_1.5.1_linux_amd64.tar.gz -O protoc-gen-doc.tar.gz

# # Extract the binary from the tarball
# tar -xvf protoc-gen-doc.tar.gz

# # Ensure it's an executable binary
# file protoc-gen-doc

# # Make it executable
# chmod +x protoc-gen-doc

# # Move the binary to /usr/local/bin
# sudo mv protoc-gen-doc /usr/local/bin/

protoc --doc_out=./ --doc_opt=markdown,test.md ./grpc/service.proto

VERSION=$(grep -oP '(?<=version\s)[0-9]+\.[0-9]+' ./grpc/service.proto)
echo "VERSION=$VERSION"

sed -i '3a\\n## Version: '"$VERSION"'\n' ./test.md

sed -i 's/&gt;/>/g' ./test.md
sed -i 's/&lt;/</g' ./test.md
Loading

0 comments on commit 7616cd7

Please sign in to comment.