Skip to content

Commit

Permalink
misc: update rust-toolchain file to TOML format
Browse files Browse the repository at this point in the history
1. Move rust-toolchain to rust-toolchain.toml
2. Update the parsing process of rust-toolchain in the test script.

Signed-off-by: Qinqi Qu <[email protected]>
  • Loading branch information
adamqqqplay authored and jiangliu committed Dec 12, 2023
1 parent d793aee commit a84400d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
1 change: 0 additions & 1 deletion rust-toolchain

This file was deleted.

2 changes: 2 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "1.68.2"
33 changes: 32 additions & 1 deletion tests/bats/common_tests.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
parse_toml() {
local input=$1
local key=$2

# Using sed to extract the value of a specified key from Toml content
local value
value=$(echo "$input" | sed -n 's/.*'"$key"' = "\(.*\)"/\1/p')
# Remove quote
# shellcheck disable=SC2001
value=$(echo "$value" | sed 's/"//g')

echo "$value"
}

get_rust_toolcahin() {
local base_dir=$1
local toml_file="${base_dir}/rust-toolchain.toml"
local legacy_toml_file="${base_dir}/rust-toolchain"
local version

if [ -f "$toml_file" ]; then
local toml_content
toml_content=$(cat "$toml_file")
version=$(parse_toml "$toml_content" 'channel')
else
version=$(cat "$legacy_toml_file")
fi

echo "$version"
}

repo_base_dir="${BATS_TEST_DIRNAME}/../.."
rust_toolchain=$(cat ${repo_base_dir}/rust-toolchain)
rust_toolchain=$(get_rust_toolcahin "$repo_base_dir")
compile_image="localhost/compile-image:${rust_toolchain}"
nydus_snapshotter_repo="https://github.com/containerd/nydus-snapshotter.git"

Expand Down

0 comments on commit a84400d

Please sign in to comment.