1+ name : Generate Protobuf Documentation
2+
3+ # Define a manual trigger with input for version
4+ on :
5+ push :
6+ branches :
7+ - master
8+
9+ jobs :
10+ build :
11+ runs-on : ubuntu-latest
12+
13+ steps :
14+ # Step 1: Checkout the repository code
15+ - name : Checkout code
16+ uses : actions/checkout@v3
17+
18+ # Step 1.1: Check Version Number
19+ - name : Check Version Number
20+ run : |
21+ pwd
22+ PROTO_VERSION=$(grep -oP '(?<=version\s)[0-9]+\.[0-9]+' ./idl/grpc/service.proto)
23+ THRIFT_VERSION=$(grep -oP '(?<=version\s)[0-9]+\.[0-9]+' ./idl/thrift/soccer_service.thrift)
24+ if [ "$PROTO_VERSION" != "$THRIFT_VERSION" ]; then
25+ echo "Version mismatch: Protobuf version is $PROTO_VERSION, Thrift version is $THRIFT_VERSION"
26+ exit 1
27+ fi
28+
29+ # Step 2: Install dependencies for protoc
30+ - name : Install protoc dependencies
31+ run : sudo apt-get update && sudo apt-get install -y protobuf-compiler wget
32+
33+ # Step 3: Download precompiled protoc-gen-doc binary
34+ - name : Download protoc-gen-doc binary
35+ run : |
36+ # Download the appropriate precompiled binary for Linux
37+ 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
38+
39+ # Extract the binary from the tarball
40+ tar -xvf protoc-gen-doc.tar.gz
41+
42+ # Ensure it's an executable binary
43+ file protoc-gen-doc
44+
45+ # Make it executable
46+ chmod +x protoc-gen-doc
47+
48+ # Move the binary to /usr/local/bin
49+ sudo mv protoc-gen-doc /usr/local/bin/
50+
51+ # Step 4: Generate Markdown from the Protobuf file
52+ - name : Generate Protobuf Documentation
53+ run : |
54+ # Generate markdown from .proto file
55+ protoc --doc_out=./idl --doc_opt=markdown,readme.md ./idl/grpc/service.proto
56+
57+ # Step 5: Extract version from the first line of the .proto file
58+ - name : Extract version from .proto file
59+ id : extract_version
60+ run : |
61+ VERSION=$(grep -oP '(?<=version\s)[0-9]+\.[0-9]+' ./idl/grpc/service.proto)
62+ echo "VERSION=$VERSION" >> $GITHUB_ENV
63+
64+ # Step 6: Insert version into the generated Markdown file
65+ - name : Insert version into markdown
66+ run : |
67+ sed -i '3a\\n## Version: '"${{ env.VERSION }}"'\n' ./idl/readme.md
68+
69+ # Step 7: Replace > and < in Mermaid diagrams with > and <
70+ - name : Fix Mermaid symbols in readme.md
71+ run : |
72+ sed -i 's/>/>/g' ./idl/readme.md
73+ sed -i 's/</</g' ./idl/readme.md
74+
75+ # Step 8: Configure Git and commit the updated readme.md
76+ - name : Configure Git
77+ run : |
78+ git config --global user.name "GitHub Action"
79+ git config --global user.email "[email protected] " 80+
81+ # Step 10: Stage and Commit Changes
82+ - name : Stage and Commit Changes
83+ run : |
84+ ls ./idl
85+ git status
86+ git add ./idl/readme.md # Ensure the correct file is added
87+ git diff --quiet || git commit -m "Update protobuf documentation with version and fixed Mermaid symbols" || echo "No changes to commit"
88+
89+ # Step 11: Push the changes
90+ - name : Push Changes
91+ env :
92+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
93+ run : git push
94+
95+ # Step 12: Clone the website repository and push the updated protobuf.md
96+ - name : Push to Website Repo
97+ env :
98+ WEBSITE_TOKEN : ${{ secrets.WEBSITE_TOKEN }} # Add your Personal Access Token (PAT) as a secret
99+ run : |
100+ # Clone the website repository
101+ git clone https://[email protected] /CLSFramework/CLSFramework.github.io.git website 102+
103+ # Copy the generated readme.md and rename it to protobuf.md
104+ mv ./idl/readme.md ./website/docs/3-idl/protobuf.md
105+
106+ # Commit and push changes to the website repo only if there are changes
107+ cd website
108+ git config --global user.name "GitHub Action"
109+ git config --global user.email "[email protected] " 110+
111+ # Check if there are any changes
112+ if git diff --quiet; then
113+ echo "No changes detected, skipping commit and push."
114+ else
115+ git add ./docs/3-idl/protobuf.md
116+ git commit -m "Update protobuf documentation with version and fixed Mermaid symbols"
117+ git push
118+ fi
0 commit comments