test: enable integration test with enhanced debug output #27
This file contains hidden or 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 maintained by velocitas CLI, do not modify manually. Change settings in .velocitas.json | |
| # Copyright (c) 2022-2024 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 | |
| name: CI workflow | |
| concurrency: | |
| group: ${{ github.ref }} | |
| cancel-in-progress: true | |
| on: | |
| workflow_dispatch: | |
| push: | |
| # Run only on branches/commits and not tags | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| jobs: | |
| unit-tests: | |
| runs-on: ubuntu-22.04 | |
| container: ghcr.io/eclipse-velocitas/devcontainer-base-images/python:v0.4 | |
| name: Run unit tests and linters | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - uses: de-vri-es/setup-git-credentials@v2 | |
| with: | |
| credentials: https://user:${{ secrets.GITHUB_TOKEN }}@github.com/ | |
| - name: Ensure Velocitas CLI version | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| desired=$(python3 -c "import json; print(json.load(open('.velocitas.json'))['cliVersion'])") | |
| echo "Desired Velocitas CLI: ${desired}" | |
| url="https://github.com/eclipse-velocitas/cli/releases/download/${desired}/velocitas-linux-x64" | |
| echo "Downloading ${url}" | |
| curl -fsSL "${url}" -o /usr/local/bin/velocitas | |
| chmod +x /usr/local/bin/velocitas | |
| velocitas --version | |
| - name: Init velocitas project | |
| id: velocitas_init | |
| continue-on-error: true | |
| shell: bash | |
| run: | | |
| set +e | |
| velocitas --version | |
| velocitas init | |
| code=$? | |
| echo "exit_code=$code" >> "$GITHUB_OUTPUT" | |
| if [ $code -ne 0 ]; then | |
| echo "::group::Velocitas init diagnostics (unit-tests)" | |
| echo "pwd=$(pwd)" | |
| ls -la | |
| echo "--- .velocitas.json ---" | |
| cat .velocitas.json || true | |
| echo "--- app/AppManifest.json ---" | |
| cat app/AppManifest.json || true | |
| echo "--- gen/ ---" | |
| ls -la gen || true | |
| ls -la gen/vehicle_model || true | |
| echo "--- find logs / vspec / generated model ---" | |
| find . -maxdepth 6 -type f \( -iname "*.log" -o -iname "*vspec*" -o -iname "vss*.json" -o -iname "*vehicle_model*" -o -path "*/.velocitas/*" \) -print | head -n 200 || true | |
| echo "--- preview first lines of vspec-like files (if any) ---" | |
| for f in $(find . -maxdepth 6 -type f \( -iname "*vspec*" -o -iname "vss*.json" \) 2>/dev/null | head -n 5); do | |
| echo "### ${f}" | |
| head -n 20 "${f}" || true | |
| done | |
| echo "::endgroup::" | |
| fi | |
| exit 0 | |
| - name: Upload velocitas debug artifacts (unit-tests) | |
| if: steps.velocitas_init.outputs.exit_code != '0' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: velocitas-debug-unit-tests | |
| path: | | |
| .velocitas/** | |
| gen/** | |
| app/AppManifest.json | |
| .velocitas.json | |
| if-no-files-found: warn | |
| - name: Fail job if velocitas init failed (unit-tests) | |
| if: steps.velocitas_init.outputs.exit_code != '0' | |
| shell: bash | |
| run: | | |
| echo "velocitas init failed with exit code ${{ steps.velocitas_init.outputs.exit_code }}" | |
| exit 1 | |
| - name: Install required packages | |
| run: | | |
| pip install -r requirements.txt | |
| pip install -r app/requirements-links.txt | |
| pip install -r app/requirements.txt | |
| pip install -r app/tests/requirements.txt | |
| - name: Fix dubious ownership | |
| run: | | |
| git config --global --add safe.directory $( pwd ) | |
| - name: Run Linters | |
| uses: pre-commit/action@v3.0.1 | |
| - name: Clone Release Documentation Action repository | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: eclipse-velocitas/release-documentation-action | |
| path: "./.github/release-documentation/actions" | |
| - name: unit test | |
| shell: bash | |
| run: | | |
| pytest --rootdir=./app/tests/unit \ | |
| --override-ini junit_family=xunit1 \ | |
| --junit-xml=./results/UnitTest/junit.xml \ | |
| --cov ./app/src \ | |
| --cov-report=xml:results/CodeCoverage/cobertura-coverage.xml \ | |
| --cov-branch ./app/tests/unit | |
| - name: Publish Test Report | |
| uses: mikepenz/action-junit-report@v4 | |
| if: always() | |
| with: | |
| report_paths: ./results/UnitTest/junit.xml | |
| summary: true | |
| update_check: true | |
| annotate_only: true | |
| - uses: irongut/CodeCoverageSummary@v1.3.0 | |
| with: | |
| filename: results/CodeCoverage/cobertura-coverage.xml | |
| badge: true | |
| format: markdown | |
| hide_complexity: true | |
| indicators: true | |
| output: both | |
| - run: | | |
| cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY | |
| - name: Package unit test files | |
| uses: ./.github/release-documentation/actions/package | |
| with: | |
| name: "UnitTest" | |
| type: "UnitTest" | |
| schema: "JUnit" | |
| sourcePath: ./results/UnitTest/junit.xml | |
| packagePath: ./results/Documentation/renderer | |
| - name: Package code coverage files | |
| uses: ./.github/release-documentation/actions/package | |
| with: | |
| name: "CodeCoverage" | |
| type: "CodeCoverage" | |
| schema: "Cobertura" | |
| sourcePath: results/CodeCoverage | |
| packagePath: results/Documentation/renderer | |
| - name: Upload test results as artifacts | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: "test-results-unit-tests" | |
| path: | | |
| results/Documentation/renderer/* | |
| get-app-name: | |
| runs-on: ubuntu-22.04 | |
| name: Get App-Name | |
| outputs: | |
| app_name: ${{ steps.export-app-name.outputs.app_name }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Get app-name | |
| id: export-app-name | |
| run: | | |
| NAME=$(cat ./app/AppManifest.json | jq -r '.name') | |
| echo "app_name=$NAME" >> $GITHUB_OUTPUT | |
| build-image-amd64: | |
| uses: ./.github/workflows/build-docker-image.yml | |
| needs: [get-app-name] | |
| with: | |
| platform: amd64 | |
| app_name: ${{ needs.get-app-name.outputs.app_name }} | |
| run-integration-tests: | |
| name: Run Integration Tests (${{ needs.get-app-name.outputs.app_name }}) | |
| runs-on: ubuntu-22.04 | |
| container: ghcr.io/eclipse-velocitas/devcontainer-base-images/python:v0.4 | |
| needs: [get-app-name, build-image-amd64] | |
| env: | |
| APP_NAME: ${{ needs.get-app-name.outputs.app_name }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - uses: de-vri-es/setup-git-credentials@v2 | |
| with: | |
| credentials: https://user:${{ secrets.GITHUB_TOKEN }}@github.com/ | |
| - name: Ensure Velocitas CLI version | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| desired=$(python3 -c "import json; print(json.load(open('.velocitas.json'))['cliVersion'])") | |
| echo "Desired Velocitas CLI: ${desired}" | |
| url="https://github.com/eclipse-velocitas/cli/releases/download/${desired}/velocitas-linux-x64" | |
| echo "Downloading ${url}" | |
| curl -fsSL "${url}" -o /usr/local/bin/velocitas | |
| chmod +x /usr/local/bin/velocitas | |
| velocitas --version | |
| - name: Init velocitas project | |
| id: velocitas_init | |
| continue-on-error: true | |
| shell: bash | |
| run: | | |
| set +e | |
| velocitas --version | |
| velocitas init | |
| code=$? | |
| echo "exit_code=$code" >> "$GITHUB_OUTPUT" | |
| if [ $code -ne 0 ]; then | |
| echo "::group::Velocitas init diagnostics (integration-tests)" | |
| echo "pwd=$(pwd)" | |
| ls -la | |
| echo "--- .velocitas.json ---" | |
| cat .velocitas.json || true | |
| echo "--- app/AppManifest.json ---" | |
| cat app/AppManifest.json || true | |
| echo "--- gen/ ---" | |
| ls -la gen || true | |
| ls -la gen/vehicle_model || true | |
| echo "--- find logs / vspec / generated model ---" | |
| find . -maxdepth 6 -type f \( -iname "*.log" -o -iname "*vspec*" -o -iname "vss*.json" -o -iname "*vehicle_model*" -o -path "*/.velocitas/*" \) -print | head -n 200 || true | |
| echo "--- preview first lines of vspec-like files (if any) ---" | |
| for f in $(find . -maxdepth 6 -type f \( -iname "*vspec*" -o -iname "vss*.json" \) 2>/dev/null | head -n 5); do | |
| echo "### ${f}" | |
| head -n 20 "${f}" || true | |
| done | |
| echo "::endgroup::" | |
| fi | |
| exit 0 | |
| - name: Upload velocitas debug artifacts (integration-tests) | |
| if: steps.velocitas_init.outputs.exit_code != '0' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: velocitas-debug-integration-tests | |
| path: | | |
| .velocitas/** | |
| gen/** | |
| app/AppManifest.json | |
| .velocitas.json | |
| if-no-files-found: warn | |
| - name: Fail job if velocitas init failed (integration-tests) | |
| if: steps.velocitas_init.outputs.exit_code != '0' | |
| shell: bash | |
| run: | | |
| echo "velocitas init failed with exit code ${{ steps.velocitas_init.outputs.exit_code }}" | |
| exit 1 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Install required packages | |
| run: | | |
| pip install -r ./app/requirements.txt | |
| pip install -r ./app/requirements-links.txt | |
| pip install -r ./app/tests/requirements.txt | |
| - name: Configure Kanto and start runtime containers | |
| run: velocitas exec runtime-kanto up | |
| - id: github-repository-name-case-adjusted | |
| name: Prepare repository name in lower case for docker upload. This supports repository names in mixed case | |
| uses: ASzc/change-string-case-action@v6 | |
| with: | |
| string: ${{ github.repository }} | |
| - name: Download stored image from artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: ${{ env.APP_NAME }}-amd64-docker-archive | |
| path: ./.github/scripts/ | |
| - name: Deploy image | |
| working-directory: ./.github/scripts | |
| run: | | |
| mv ${{ env.APP_NAME }}-docker-amd64.tar ${{ env.APP_NAME }}.tar | |
| ./deploy_image_from_artifact.sh | |
| - name: Run Python integration tests | |
| shell: bash | |
| env: | |
| VDB_PORT: 55555 | |
| MQTT_PORT: 1883 | |
| run: | | |
| pip install -r app/tests/requirements.txt | |
| pytest ./app/tests/integration --override-ini junit_family=xunit1 --junit-xml=./results/IntTest/junit.xml | |
| - name: Publish Test Report | |
| uses: mikepenz/action-junit-report@v4 | |
| if: always() | |
| with: | |
| report_paths: ./results/IntTest/junit.xml | |
| summary: true | |
| update_check: true | |
| annotate_only: true | |
| - name: Clone release documentation action repository | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: eclipse-velocitas/release-documentation-action | |
| path: "./.github/actions" | |
| - name: Package integration test result files | |
| uses: ./.github/actions/package | |
| with: | |
| name: "IntegrationTest" | |
| type: "UnitTest" | |
| schema: "JUnit" | |
| sourcePath: ./results/IntTest/junit.xml | |
| packagePath: ./results/Documentation/renderer | |
| - name: Upload integration test results as artifacts | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: "test-results-integration-tests" | |
| path: | | |
| results/Documentation/renderer/* | |
| merge-test-results: | |
| runs-on: ubuntu-22.04 | |
| needs: run-integration-tests | |
| steps: | |
| - name: Merge Artifacts | |
| uses: actions/upload-artifact/merge@v4 | |
| with: | |
| delete-merged: true | |
| name: test-results | |
| pattern: test-results-* |