From fda0fa1a7cc9ead19207866f0f9b4f06a495d16e Mon Sep 17 00:00:00 2001 From: Holger Dormann Date: Mon, 19 Aug 2024 11:54:55 +0200 Subject: [PATCH] Provide a script to update version of Ankaios (#339) * Provide a script to update version of Ankaios Issue-Id: #337 * Improve logging Issue-Id: #337 * Fix review findings. Issue-Id: #337 --- doc/docs/development/ci-cd-release.md | 2 +- tools/ankaios-docker/compose.yaml | 4 -- tools/update_version.sh | 82 +++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 5 deletions(-) create mode 100755 tools/update_version.sh diff --git a/doc/docs/development/ci-cd-release.md b/doc/docs/development/ci-cd-release.md index 209d2c20e..9cf3953ae 100644 --- a/doc/docs/development/ci-cd-release.md +++ b/doc/docs/development/ci-cd-release.md @@ -117,7 +117,7 @@ The procedure uses the filters for pull request labels configured inside `.githu The following steps shall be done before the actual release build is triggered. 1. Create an isssue containing tasks for getting the main branch ready: - 1. Update the versions in the project packages (Cargo.toml files) to the new version. + 1. Update the versions in the project packages (Cargo.toml files) to the new version (use `tools/update_version.sh --release `). 2. Execute tests on the supported targets. 3. Make sure there are no security warnings of Github dependabot. 2. Finish all tasks inside the issue. diff --git a/tools/ankaios-docker/compose.yaml b/tools/ankaios-docker/compose.yaml index 0781e2ebb..3b4261958 100644 --- a/tools/ankaios-docker/compose.yaml +++ b/tools/ankaios-docker/compose.yaml @@ -2,13 +2,9 @@ services: ank-server: build: context: ./server - args: - - VERSION=v0.4.0 ports: - "25551:25551" ank-agent: build: context: ./agent - args: - - VERSION=v0.4.0 privileged: true diff --git a/tools/update_version.sh b/tools/update_version.sh new file mode 100755 index 000000000..27b2e8ad8 --- /dev/null +++ b/tools/update_version.sh @@ -0,0 +1,82 @@ +#!/bin/bash + +# Copyright (c) 2024 Elektrobit Automotive 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 + +set -e + +script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +base_dir="$script_dir/.." +workspace_config="$base_dir/Cargo.toml" + +usage() { + echo "Usage: $0 [--release] VERSION" + echo "Update Ankaios files to VERSION." + echo " --release Official release with assets for download." + exit 1 +} + +log_update() { + echo "Updating $(realpath -e --relative-base="$(pwd)" "$1")" +} + +# Initialize variables +release=0 +version="" + +# Parse arguments +while [[ "$#" -gt 0 ]]; do + case $1 in + --release) release=1; shift ;; + -h|--help) usage ;; + *) + if [[ -z "$version" ]]; then + version="$1" + else + echo "Error: Unknown parameter passed: $1" + usage + fi + shift + ;; + esac +done + +# Check if VERSION is set +if [[ -z "$version" ]]; then + echo "Error: VERSION is a mandatory argument." + usage +fi + +# Extract all packages from the workspace file +packages=$(awk '/members *= *\[/{flag=1; next} /\]/{flag=0} flag {gsub(/[" ,]/, ""); print}' "$workspace_config") + +for pkg in $packages; do + package_config="$base_dir/$pkg/Cargo.toml" + log_update "$package_config" + # Update version in Cargo.toml for a specific package + sed -i "/\[package\]/,/\[/{s/version = \"[^\"]*\"/version = \"$version\"/}" "$package_config" +done + +# Some versions must only be updated for official releases as only those provide assets for download +if [ "$release" = "1" ]; then + # ankaios-docker + for f in server agent; do + dockerfile="$base_dir/tools/ankaios-docker/$f/Dockerfile" + log_update "$dockerfile" + sed -i "s/^ARG VERSION=.*/ARG VERSION=${version}/" "$dockerfile" + done +fi + + +