Wippersnapper_Protobuf/.github/workflows/protoc-wrapper-generation.yml
2025-05-20 14:49:30 -04:00

134 lines
5.6 KiB
YAML

name: Generate .proto Wrapper Files
on:
push:
branches: master
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: write
pages: write
id-token: write
jobs:
build:
runs-on: ubuntu-latest
steps:
# Setup
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
version: '3.13.0'
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install Python dependencies
run : |
python -m pip install --upgrade pip
pip install protobuf setuptools
- name: Self Checkout
uses: actions/checkout@v4
with:
path: protobuf-checkout
submodules: true
- name: Configure Git
run: |
git config --global user.name adafruitio
git config --global user.email adafruitio@adafruit.com
# Arduino wrappers for the microcontrollers
- name: Generate Arduino files from .proto Files
env:
PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION: python
run: |
mkdir ./arduino_out
mkdir ./doc
echo "Installing protobuf-gen-doc"
go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc@latest
cp ~/go/bin/protoc-gen-doc .
echo "Generating docs..."
protoc --plugin=protobuf-checkout/nanopb/generator/protoc-gen-nanopb -Iprotobuf-checkout/nanopb/generator/proto --proto_path=./protobuf-checkout/proto ./protobuf-checkout/proto/wippersnapper/*/*/*.proto --nanopb_out=./arduino_out --nanopb_opt=-I./protobuf-checkout/proto --nanopb_opt=-t --plugin=protoc-gen-doc=./protoc-gen-doc --doc_out=./doc --doc_opt=html,index.html
# Local (non-CI) build command:
# protoc --plugin=nanopb/generator/protoc-gen-nanopb -Inanopb/generator/proto --proto_path=./proto ./proto/wippersnapper/*/*/*.proto --nanopb_out=./arduino_out --nanopb_opt=-I./proto --nanopb_opt=-t --plugin=protoc-gen-doc=./protoc-gen-doc --doc_out=./doc --doc_opt=html,index.html
- name: Checkout Arduino Repo
uses: actions/checkout@v4
with:
repository: adafruit/Adafruit_Wippersnapper_Arduino
token: ${{ secrets.IO_BOT_PAT }}
path: arduino-checkout
- name: Copy Generated Arduino Files to Arduino Repo
run: |
rm -rf ./arduino-checkout/src/wippersnapper/
mkdir ./arduino-checkout/src/wippersnapper/
cp -a ./arduino_out/. ./arduino-checkout/src/
- name: Open Arduino Pull Request
env:
GITHUB_USER: adafruitio
GITHUB_TOKEN: ${{ secrets.IO_BOT_PAT }}
PROTOBUF_BRANCH_NAME: protobuf-update
run: |
cd arduino-checkout
git checkout -b $PROTOBUF_BRANCH_NAME-$GITHUB_SHA
git status
git add src
git commit -m "Updating protobuf wrappers" || exit 0 # quit cleanly if nothing to commit
hub push origin $PROTOBUF_BRANCH_NAME-$GITHUB_SHA
hub pull-request --base main --message ".proto file wrappers updated" --message "Auto-generated by [GitHub Actions on Protobuf Repo][1]" --message "[1]: https://github.com/adafruit/Wippersnapper_Protobuf/blob/master/.github/workflows/protoc-wrapper-generation.yml"
# NodeJS wrappers for the mqtt broker
- name: Generate JS Wrapper Files from .proto Files
run: |
mkdir ./js_out
protoc --proto_path=./protobuf-checkout/proto ./protobuf-checkout/proto/wippersnapper/*/*/*.proto --js_out=import_style=commonjs,binary:js_out
protoc ./protobuf-checkout/nanopb/generator/proto/nanopb.proto --js_out=import_style=commonjs,binary:js_out
- name: Checkout io-node Repo
uses: actions/checkout@v4
with:
repository: AdafruitInternalDev/io-node
token: ${{ secrets.IO_BOT_PAT }}
path: js-checkout
ref: main
- name: Copy JS Files
run: |
rm -rf ./js-checkout/lib/wprsnpr/protobufs/wippersnapper/
cp -r ./js_out/wippersnapper/ ./js-checkout/lib/wprsnpr/protobufs/wippersnapper/
rm -rf ./js-checkout/lib/wprsnpr/protobufs/nanopb/
mkdir ./js-checkout/lib/wprsnpr/protobufs/nanopb/
mv ./js_out/protobuf-checkout/nanopb/generator/proto/nanopb_pb.js ./js-checkout/lib/wprsnpr/protobufs/nanopb/nanopb_pb.js
- name: Open Node Pull Request
env:
GITHUB_USER: adafruitio
GITHUB_TOKEN: ${{ secrets.IO_BOT_PAT }}
PROTOBUF_BRANCH_NAME: protobuf-update
run: |
cd js-checkout
git checkout -b $PROTOBUF_BRANCH_NAME-$GITHUB_SHA
git add lib/wprsnpr/protobufs/
git commit -m "Updating protobuf wrappers" || exit 0 # quit cleanly if nothing to commit
hub push origin $PROTOBUF_BRANCH_NAME-$GITHUB_SHA
hub pull-request --base main --message ".proto file wrappers updated" --message "Auto-generated by [GitHub Actions on Protobuf Repo][1]" --message "[1]: https://github.com/adafruit/Wippersnapper_Protobuf/blob/master/.github/workflows/protoc-wrapper-generation.yml"
# Docs
- name: Checkout doc branch
uses: actions/checkout@v4
with:
ref: gh-pages
path: protobuf-docs-checkout
- name: Commit and push generated HTML Docs file
run: |
cd protobuf-docs-checkout
cp -r ../doc ./doc
git add doc/
git commit -m "Add generated HTML documentation for $GITHUB_SHA" || exit 0 # quit cleanly if nothing to commit
git push
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: 'protobuf-docs-checkout/doc'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4