-
Notifications
You must be signed in to change notification settings - Fork 5
145 lines (139 loc) · 5.18 KB
/
code-generation.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# 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: dtolnay/rust-toolchain@master
with:
toolchain: 1.59
components: clippy
- name: Remove Rust old code
run: (! test -f ./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 run -- --proto-directory ../../proto --out ../astarte-message-hub-proto/src/
working-directory: ./rust/rust-codegen
- name: cargo clippy
run: cargo clippy --all-targets --all-features -- -D warnings
working-directory: ./rust/astarte-message-hub-proto
- name: cargo doc
run: cargo doc --no-deps --all-features
env:
RUSTDOCFLAGS: --cfg docsrs -D warnings
working-directory: ./rust/astarte-message-hub-proto
- name: cargo install cargo-hack
uses: taiki-e/install-action@cargo-hack
- name: remove dev-deps
run: cargo hack --remove-dev-deps
working-directory: ./rust/astarte-message-hub-proto
- name: update to minimal deps
run: cargo update -Z direct-minimal-versions
working-directory: ./rust/astarte-message-hub-proto
- name: cargo check
run: cargo check --all-features
env:
RUSTDOCFLAGS: -D warnings
working-directory: ./rust/astarte-message-hub-proto
- name: Upload Rust code
uses: actions/upload-artifact@v3
with:
name: rust-dist
path: ./rust/astarte-message-hub-proto/src/astarteplatform.msghub.rs
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"
mv ./rust-dist/astarteplatform.msghub.rs ./rust/astarte-message-hub-proto/src/astarteplatform.msghub.rs
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