|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright (c) 2025 Elektrobit Automotive GmbH |
| 4 | +# |
| 5 | +# This program and the accompanying materials are made available under the |
| 6 | +# terms of the Apache License, Version 2.0 which is available at |
| 7 | +# https://www.apache.org/licenses/LICENSE-2.0. |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | +# License for the specific language governing permissions and limitations |
| 13 | +# under the License. |
| 14 | +# |
| 15 | +# SPDX-License-Identifier: Apache-2.0 |
| 16 | + |
| 17 | +set -e |
| 18 | + |
| 19 | +script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) |
| 20 | +base_dir="$script_dir" |
| 21 | +sdk_version="" |
| 22 | +ankaios_version="" |
| 23 | +api_version="" |
| 24 | + |
| 25 | +usage() { |
| 26 | + echo "Usage: $0 [--sdk <VERSION>] [--ank <VERSION>] [--api <VERSION>] [--help]" |
| 27 | + echo "Update the SDK, Ankaios and API versions." |
| 28 | + echo "You can update all of them at once or one by one." |
| 29 | + echo " --sdk <VERSION> The new version of the SDK." |
| 30 | + echo " --ank <VERSION> The new version of Ankaios." |
| 31 | + echo " --api <VERSION> The new version for the supported API." |
| 32 | + echo " --help Display this help message and exit." |
| 33 | + echo "" |
| 34 | + echo "Example:" |
| 35 | + echo " $0 --sdk 0.1.0 --ank 0.1.0 --api v0.1" |
| 36 | + exit 1 |
| 37 | +} |
| 38 | + |
| 39 | +parse_arguments() { |
| 40 | + while [ "$#" -gt 0 ]; do |
| 41 | + case "$1" in |
| 42 | + --sdk) |
| 43 | + shift |
| 44 | + sdk_version="$1" |
| 45 | + ;; |
| 46 | + --ank) |
| 47 | + shift |
| 48 | + ankaios_version="$1" |
| 49 | + ;; |
| 50 | + --api) |
| 51 | + shift |
| 52 | + api_version="$1" |
| 53 | + ;; |
| 54 | + --help|-h) |
| 55 | + usage |
| 56 | + ;; |
| 57 | + *) |
| 58 | + echo "Unknown argument: $1" |
| 59 | + usage |
| 60 | + ;; |
| 61 | + esac |
| 62 | + shift |
| 63 | + done |
| 64 | +} |
| 65 | + |
| 66 | +if [ "$#" -eq 0 ]; then |
| 67 | + usage |
| 68 | +fi |
| 69 | + |
| 70 | +parse_arguments "$@" |
| 71 | + |
| 72 | +if [ -z "$sdk_version" ] && [ -z "$ankaios_version" ] && [ -z "$api_version" ]; then |
| 73 | + echo "You must specify at least one version to update." |
| 74 | + usage |
| 75 | +fi |
| 76 | + |
| 77 | +if [ -n "$sdk_version" ]; then |
| 78 | + echo "Updating SDK version to $sdk_version" |
| 79 | + sed -i "s|^version = .*|version = \"$sdk_version\"|" "$base_dir"/Cargo.toml |
| 80 | + sed -i "s|documentation = \"https://docs.rs/ankaios-sdk/.*|documentation = \"https://docs.rs/ankaios-sdk/$sdk_version\"|" "$base_dir"/Cargo.toml |
| 81 | + |
| 82 | + sed -i "s|\(\[!\[Docs\.rs\](https://img\.shields\.io/badge/docs\.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs\.rs)\](https://docs\.rs/ankaios-sdk/\)[^)]*|\1$sdk_version|" "$base_dir"/README.md |
| 83 | + sed -i "s|\* \[Rust SDK documentation\](https://docs\.rs/ankaios-sdk/[^)]*)|* [Rust SDK documentation](https://docs.rs/ankaios-sdk/$sdk_version)|" "$base_dir"/README.md |
| 84 | + sed -i "s|ankaios_sdk = \"[^\"]*\"|ankaios_sdk = \"$sdk_version\"|" "$base_dir"/README.md |
| 85 | + |
| 86 | + sed -i "s|#!\[doc(html_root_url = \"https://docs\.rs/ankaios_sdk/[^\"]*\")\]|#![doc(html_root_url = \"https://docs.rs/ankaios_sdk/$sdk_version\")]|" "$base_dir"/src/lib.rs |
| 87 | + sed -i "s|//! \[!\[docs-rs\]\](https://docs\.rs/ankaios-sdk/[^)]*)|//! [![docs-rs]](https://docs.rs/ankaios-sdk/$sdk_version)|" "$base_dir"/src/lib.rs |
| 88 | + sed -i "s|//! ankaios_sdk = \"[^\"]*\"|//! ankaios_sdk = \"$sdk_version\"|" "$base_dir"/src/lib.rs |
| 89 | + sed -i "s|//! \* \[Rust SDK documentation\](https://docs\.rs/ankaios-sdk/[^)]*)|//! * [Rust SDK documentation](https://docs.rs/ankaios-sdk/$sdk_version)|" "$base_dir"/src/lib.rs |
| 90 | + |
| 91 | + echo "Please remember to update the SDK versions in the compatibility tables from README.md and src/lib.rs!" |
| 92 | +fi |
| 93 | + |
| 94 | +if [ -n "$ankaios_version" ]; then |
| 95 | + echo "Updating Ankaios version to $ankaios_version" |
| 96 | + sed -i "s/^ENV ANKAIOS_VERSION=.*/ENV ANKAIOS_VERSION=$ankaios_version/" "$base_dir"/examples/app/Dockerfile |
| 97 | + sed -i "s/const ANKAIOS_VERSION: &str = .*/const ANKAIOS_VERSION: \&str = \"$ankaios_version\";/" "$base_dir"/src/components/control_interface.rs |
| 98 | +fi |
| 99 | + |
| 100 | +if [ -n "$api_version" ]; then |
| 101 | + echo "Updating API version to $api_version" |
| 102 | + sed -i "s/const SUPPORTED_API_VERSION: &str = .*/const SUPPORTED_API_VERSION: \&str = \"$api_version\";/" "$base_dir"/src/components/complete_state.rs |
| 103 | + sed -i "s/^apiVersion: .*/apiVersion: $api_version/" "$base_dir"/examples/manifest.yaml |
| 104 | + sed -i "s/^\/\/\/ let manifest = Manifest::from_string(\"apiVersion: .*/\/\/\/ let manifest = Manifest::from_string(\"apiVersion: $api_version\").unwrap();/" "$base_dir"/src/components/manifest.rs |
| 105 | +fi |
0 commit comments