From 0eeb7a00929f988bfe4e86bdda9a05a2da62d9b4 Mon Sep 17 00:00:00 2001 From: dennismeister93 Date: Tue, 7 May 2024 12:01:26 +0200 Subject: [PATCH] Add velocitas config update action (#55) * Add velocitas config update action * Update for slim project config --------- Signed-off-by: Dennis Meister --- .../actions/update-velocitas-json/action.yml | 39 +++++++++++++++++++ .github/workflows/ci.yml | 11 +++--- test/cpp/.velocitas.json | 17 ++++---- test/python/.velocitas.json | 16 ++++---- 4 files changed, 59 insertions(+), 24 deletions(-) create mode 100644 .github/actions/update-velocitas-json/action.yml diff --git a/.github/actions/update-velocitas-json/action.yml b/.github/actions/update-velocitas-json/action.yml new file mode 100644 index 0000000..320efa9 --- /dev/null +++ b/.github/actions/update-velocitas-json/action.yml @@ -0,0 +1,39 @@ +# Copyright (c) 2023-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: update-velocitas-json +description: Update the project's velocitas JSON. +inputs: + project_dir: + description: Directory containing the Velocitas project + required: true + template_file: + description: JSON file which will replace the .velocitas.json file. + default: None +runs: + using: composite + steps: + - name: Set commit id + shell: bash + env: + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} + BRANCH_NAME_PREFIX: "@" + run: | + if [ "${{ inputs.template_file }}" != "None" ]; then + echo "Copying template file..." + cp -f ${{ inputs.template_file }} ${{ inputs.project_dir }}/.velocitas.json + fi + + NEW_CONFIG="$(jq --arg BRANCH "$BRANCH_NAME_PREFIX$BRANCH_NAME" '.packages |= . + { (. | keys_unsorted[0]): $BRANCH }' ${{ inputs.project_dir }}/.velocitas.json)" + echo "${NEW_CONFIG}" > ${{ inputs.project_dir }}/.velocitas.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dd50466..06bd7cc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,12 +47,11 @@ jobs: repository: eclipse-velocitas/vehicle-app-${{ matrix.language }}-template path: test/${{ matrix.language }}/repo - - name: Prepare .velocitas.json for integration test - env: - BRANCH_NAME: ${{ github.head_ref || github.ref_name }} - run: | - NEW_CONFIG="$(jq --arg BRANCH "$BRANCH_NAME" '.packages[0].version |= $BRANCH' test/${{ matrix.language }}/.velocitas.json)" - echo "${NEW_CONFIG}" > test/${{ matrix.language }}/repo/.velocitas.json + - name: Update Velocitas JSON with correct version + uses: ./.github/actions/update-velocitas-json + with: + project_dir: test/${{ matrix.language }}/repo + template_file: test/${{ matrix.language }}/.velocitas.json - name: Init velocitas project run: | diff --git a/test/cpp/.velocitas.json b/test/cpp/.velocitas.json index 959a909..669d7b0 100644 --- a/test/cpp/.velocitas.json +++ b/test/cpp/.velocitas.json @@ -1,15 +1,14 @@ { - "packages": [ - { - "name": "devenv-github-workflows", - "version": "hash_id" - } - ], + "packages": { + "devenv-github-workflows": "hash_id" + }, "variables": { - "appManifestPath": "app/AppManifest.json", "language": "cpp", "repoType": "app", + "appManifestPath": "app/AppManifest.json", "githubRepoId": "eclipse-velocitas/vehicle-app-cpp-template", - "appExecutionPlatforms": "linux/amd64" - } + "appExecutionPlatforms": "linux/amd64", + "generatedModelPath": "./app/vehicle_model" + }, + "cliVersion": "v0.9.0" } diff --git a/test/python/.velocitas.json b/test/python/.velocitas.json index bed0952..92b7461 100644 --- a/test/python/.velocitas.json +++ b/test/python/.velocitas.json @@ -1,15 +1,13 @@ { - "packages": [ - { - "name": "devenv-github-workflows", - "version": "hash_id" - } - ], + "packages": { + "devenv-github-workflows": "hash_id" + }, "variables": { - "appManifestPath": "app/AppManifest.json", "language": "python", "repoType": "app", + "appManifestPath": "app/AppManifest.json", "githubRepoId": "eclipse-velocitas/vehicle-app-python-template", - "appExecutionPlatforms": "linux/amd64" - } + "generatedModelPath": "./gen/vehicle_model" + }, + "cliVersion": "v0.9.0" }