Add support for rust code generation #11
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file is part of Astarte. | |
# | |
# Copyright 2023 SECO Mind Srl | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
# | |
# SPDX-License-Identifier: Apache-2.0 | |
name: Code generation | |
on: | |
pull_request: | |
push: | |
branches: | |
- master | |
- 'release-*' | |
env: | |
PB_REL: https://github.com/protocolbuffers/protobuf/releases | |
jobs: | |
python_build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install protoc | |
run: | | |
curl -LO $PB_REL/download/v24.3/protoc-24.3-linux-x86_64.zip | |
unzip protoc-24.3-linux-x86_64.zip -d $HOME/.local | |
echo "$HOME/.local/bin" >> $GITHUB_PATH | |
- name: Make dir for grpc | |
run: mkdir ./grpc/ | |
- name: Restore cached grpc_python_plugin | |
id: cache-grpc-python-plugin-restore | |
uses: actions/cache/restore@v3 | |
with: | |
path: ./grpc/grpc_python_plugin | |
key: grpc-python-plugin-v1.58.1 | |
- name: Compile from source the grpc_python_plugin | |
if: steps.cache-grpc-python-plugin-restore.outputs.cache-hit != 'true' | |
run: | | |
git clone -b v1.58.1 https://github.com/grpc/grpc | |
cd grpc | |
git submodule update --init | |
cmake . | |
make grpc_python_plugin | |
- name: Save grpc_python_plugin | |
if: steps.cache-grpc-python-plugin-restore.outputs.cache-hit != 'true' | |
id: cache-grpc-python-plugin-save | |
uses: actions/cache/save@v3 | |
with: | |
path: ./grpc/grpc_python_plugin | |
key: ${{ steps.cache-grpc-python-plugin-restore.outputs.cache-primary-key }} | |
- name: Install Python dependencies | |
run: | | |
python3 -m pip install --upgrade pip | |
python3 -m pip install termcolor | |
- name: Remove old code | |
run: (! test -d ./astarteplatform) || rm -r ./astarteplatform | |
working-directory: ./python | |
- name: Generate Python code | |
run: python3 ./protoc.py "./../grpc/grpc_python_plugin" | |
working-directory: ./python | |
- name: Upload Python code | |
uses: actions/upload-artifact@v3 | |
with: | |
name: python | |
path: ./python | |
rust_build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install protoc | |
run: | | |
curl -LO $PB_REL/download/v24.3/protoc-24.3-linux-x86_64.zip | |
unzip protoc-24.3-linux-x86_64.zip -d $HOME/.local | |
echo "$HOME/.local/bin" >> $GITHUB_PATH | |
- name: Install rust toolchain | |
uses: actions-rs/toolchain@v1 | |
with: | |
profile: minimal | |
toolchain: 1.66.1 | |
override: true | |
- name: Remove Rust old code | |
run: (! test -d ./astarte-message-hub-proto/src/astarteplatform.msghub.rs) || rm ./astarte-message-hub-proto/src/astarteplatform.msghub.rs | |
working-directory: ./rust | |
- name: Generate Rust code with cargo build | |
run: cargo build | |
working-directory: ./rust | |
- name: Upload Rust code | |
uses: actions/upload-artifact@v3 | |
with: | |
name: rust | |
path: ./rust | |
commit_and_push_code: | |
if: github.event_name == 'push' | |
name: Commit and push generated code | |
needs: [python_build, rust_build] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Download all workflow run artifacts | |
uses: actions/download-artifact@v3 | |
- name: Commit the generated code | |
run: | | |
git config user.name github-actions | |
git config user.email [email protected] | |
git add ./python | |
git diff --staged --quiet || git commit -s -m "[Python]: Add generated code" | |
git add ./rust/astarte-message-hub-proto/src/astarteplatform.msghub.rs | |
git diff --staged --quiet || git commit -s -m "[Rust]: Add generated code" | |
git push |