Skip to content

Commit

Permalink
feat: gRPC interface support (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
doosuu authored Sep 15, 2023
1 parent b3abb47 commit 086bc4e
Show file tree
Hide file tree
Showing 55 changed files with 2,178 additions and 160 deletions.
43 changes: 43 additions & 0 deletions .github/actions/update-velocitas-json/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright (c) 2023 Robert Bosch GmbH
#
# This program and the accompanying materials are made available under the
# terms of the Apache License, Version 2.0 which is available at
# https://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: update-velocitas-json
description: Update the project's velocitas JSON.
inputs:
project_path:
description: Path to the directory containing the Velocitas project
required: true
template_path:
description: Path to a JSON file which will replace the .velocitas.json file.
default: None
runs:
using: composite
steps:
- run: |
COMMIT_REF=$GITHUB_SHA
if [ "$GITHUB_EVENT_NAME" = "pull_request" ];
then
echo "Running in context of a PR!"
COMMIT_REF=$GITHUB_HEAD_REF
fi
if [ "${{ inputs.template_path }}" != "None" ]; then
echo "Copying template file..."
cp -f ${{ inputs.template_path }} ${{ inputs.project_path }}/.velocitas.json
fi
NEW_CONFIG="$(jq --arg COMMIT_REF "$COMMIT_REF" '.packages[0].version |= $COMMIT_REF' ${{ inputs.project_path }}/.velocitas.json)"
echo "${NEW_CONFIG}" > ${{ inputs.project_path }}/.velocitas.json
shell: bash
130 changes: 46 additions & 84 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install deps
run: |
Expand All @@ -48,26 +48,34 @@ jobs:
name: "Run unit tests"
runs-on: ubuntu-22.04
container: ghcr.io/eclipse-velocitas/devcontainer-base-images/python:v0.1
strategy:
matrix:
component: ["setup", "grpc-interface-support", "vehicle-model-lifecycle", "sdk-installer"]
fail-fast: false

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install required packages
run: |
pip install -r vehicle-model-lifecycle/src/requirements.txt
pip install -r vehicle-model-lifecycle/test/requirements.txt
if [ -e "${{ matrix.component }}/requirements.txt" ]; then
pip install -r ${{ matrix.component }}/requirements.txt
fi
if [ -e "${{ matrix.component }}/test/requirements.txt" ]; then
pip install -r ${{ matrix.component }}/test/requirements.txt
fi
- name: unit test
shell: bash
run: |
pytest --rootdir=./vehicle-model-lifecycle/test \
--override-ini junit_family=xunit1 \
pytest --override-ini junit_family=xunit1 \
--junit-xml=./results/UnitTest/junit.xml \
--cov . \
--cov-report=xml:results/CodeCoverage/cobertura-coverage.xml \
--cov-branch \
./vehicle-model-lifecycle/test
./${{ matrix.component }}/test/unit
- name: Publish Test Report
uses: mikepenz/action-junit-report@v3
Expand All @@ -93,96 +101,50 @@ jobs:
strategy:
matrix:
language: ["python", "cpp"]
component: ["setup", "grpc-interface-support", "vehicle-model-lifecycle", "sdk-installer"]
fail-fast: false
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Checkout template repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: eclipse-velocitas/vehicle-app-${{ matrix.language }}-template
path: test/${{ matrix.language }}/repo

- name: Install requirements
run: pip install -r test/requirements.txt
fetch-depth: 0

- name: Prepare .velocitas.json for integration test
- name: Add safe directory
run: |
COMMIT_REF=$GITHUB_SHA
if [ "$GITHUB_EVENT_NAME" = "pull_request" ];
then
echo "Running in context of a PR!"
COMMIT_REF=$GITHUB_HEAD_REF
fi
NEW_CONFIG="$(jq --arg COMMIT_REF "$COMMIT_REF" '.packages[0].version |= $COMMIT_REF' test/${{ matrix.language }}/.velocitas.json)"
echo "${NEW_CONFIG}" > test/${{ matrix.language }}/repo/.velocitas.json
git config --global --add safe.directory $(pwd)
- name: Init velocitas project
- name: Get template repo ref
id: get-repo-ref
run: |
cd test/${{ matrix.language }}/repo
velocitas init
- name: Check if vehicle model is generated
run: |
cd test/${{ matrix.language }}/repo
generatedModelPath=$(cat .velocitas.json | jq -r .variables.generatedModelPath)
if [ -d "$generatedModelPath" ];
then
echo "$generatedModelPath directory exists."
else
echo "$generatedModelPath does not exist."
exit 1
REF=main
if [ "${{ matrix.language }}" = "cpp" ]; then
REF=manifest-v3
fi
echo "ref=$REF" >> $GITHUB_OUTPUT
- name: Sync velocitas project
run: |
cd test/${{ matrix.language }}/repo
velocitas sync
- name: Test for CLI Auto-Upgrade
run: |
cd test/${{ matrix.language }}/repo
pytest -s ../../integration/test_poststart.py
- name: Reset .velocitas.json to latest template state
run: |
cd test/${{ matrix.language }}/repo
git checkout .velocitas.json
- name: Checkout template repository
uses: actions/checkout@v4
with:
repository: eclipse-velocitas/vehicle-app-${{ matrix.language }}-template
path: test/${{ matrix.language }}/repo
ref: ${{ steps.get-repo-ref.outputs.ref }}

- name: Fix dubious ownership
- name: Add safe directory
run: |
git config --global --add safe.directory $( pwd )
git config --global --add safe.directory $(pwd)/test/${{ matrix.language }}/repo
- name: Identify changes in devenv repo
uses: dorny/paths-filter@v2
id: changesInPath
- name: Update Velocitas JSON with correct version
uses: ./.github/actions/update-velocitas-json
with:
filters: |
setupCommon:
- 'setup/src/common/**'
setupLang:
- 'setup/src/${{ matrix.language }}/**'
- name: Check if cloned template repo has changes after sync
if: (steps.changesInPath.outputs.setupCommon == 'true' || steps.changesInPath.outputs.setupLang == 'true')
id: changes
project_path: test/${{ matrix.language }}/repo
template_path: test/${{ matrix.language }}/.velocitas.json

- name: Run integration tests
run: |
cd test/${{ matrix.language }}/repo
git diff
if [[ -z "$(git status --porcelain .)" ]];
then
echo "No Changes"
echo "changed=0" >> $GITHUB_OUTPUT
else
echo "Changes"
echo "changed=1" >> $GITHUB_OUTPUT
fi
shell: bash
export THIS_REPO_PATH=$(pwd)
export VELOCITAS_TEST_LANGUAGE=${{ matrix.language }}
export VELOCITAS_TEST_ROOT=test/${{ matrix.language }}/repo
- name: Fail if there are changes in setup files detected but sync probably failed
if: |
(steps.changes.outputs.changed == 0 && steps.changesInPath.outputs.setupCommon == 'true') ||
(steps.changes.outputs.changed == 0 && steps.changesInPath.outputs.setupLang == 'true')
run: exit 1
python -m pip install -r ./${{ matrix.component }}/test/requirements.txt
python -m pip install -r ./${{ matrix.component }}/requirements.txt
pytest ./${{ matrix.component }}/test/integration
24 changes: 21 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,27 @@ repos:
rev: 5.12.0
hooks:
- id: isort
exclude: >
(?x)^(
.*_pb2.py|
.*_pb2.pyi|
.*_pb2_grpc.py|
.*conanfile.py|
.*templates.*.py
)$
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
exclude: >
(?x)^(
.*_pb2.py|
.*_pb2.pyi|
.*_pb2_grpc.py|
.*conanfile.py|
.*templates.*.py
)$
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
Expand All @@ -27,7 +43,9 @@ repos:
(?x)^(
.*_pb2.py|
.*_pb2.pyi|
.*_pb2_grpc.py
.*_pb2_grpc.py|
.*conanfile.py|
.*templates.*.py
)$
additional_dependencies:
- flake8-bugbear
Expand All @@ -37,15 +55,15 @@ repos:
rev: 1.7.4
hooks:
- id: bandit
args: ["--skip=B101,B404,B603"]
args: ["--skip=B101,B404,B603,B607"]
types_or: [python]
exclude: test

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.0.1"
hooks:
- id: mypy
args: [vehicle-model-lifecycle/src]
args: [--strict, --ignore-missing-imports, --exclude=conanfile.py, --exclude=.*templates.*.py, vehicle-model-lifecycle/src, grpc-interface-support/src]
language: system
pass_filenames: false

Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# devenv-devcontainer-setup
# Velocitas Package for DevContainer Setup

Repo for Devcontainer Configuration and vehicle model generation on container startup.

## Components in this package

* [Basic Setup](./setup/README.md)
* [gRPC Interface Support](./grpc-service-support/README.md)
* [Vehicle Signal Interface Support](./vehicle-model-lifecycle/README.md)
* [SDK Installer](./sdk-installer/README.md)
5 changes: 5 additions & 0 deletions grpc-interface-support/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# gRPC Interface Support

Extends Velocitas applications and services with the ability to describe a dependency to a gRPC service via its interface definition in a proto file.

The component provides CLI exec targets which will generate service client SDKs for all dependent services which will be made available for the application to use via a simple factory interface.
1 change: 1 addition & 0 deletions grpc-interface-support/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
git+https://github.com/eclipse-velocitas/velocitas-lib.git@v0.0.2
13 changes: 13 additions & 0 deletions grpc-interface-support/src/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2023 Contributors to the Eclipse Foundation
#
# This program and the accompanying materials are made available under the
# terms of the Apache License, Version 2.0 which is available at
# https://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
Loading

0 comments on commit 086bc4e

Please sign in to comment.