|
12 | 12 |
|
13 | 13 | # Check exit status for error handling |
14 | 14 | if [ $? -eq 0 ]; then |
15 | | - echo "Installed Kani $VERSION successfully" |
| 15 | + echo "Installed Kani $1 successfully" |
16 | 16 | else |
17 | 17 | echo "::error::Could not install Kani. Please check if the provided version is correct" |
18 | 18 | exit 1 |
|
21 | 21 | # Setup kani in ci |
22 | 22 | cargo-kani setup; |
23 | 23 |
|
24 | | -# Get the current installed version of kani and check it against the latest version |
25 | | -installed_version=$(kani --version | awk '{print $2}') |
| 24 | +# Get the current installed version of kani and check it against the latest version. |
| 25 | +# Two output formats have to be supported, since this action can install any |
| 26 | +# published version: |
| 27 | +# - Kani 0.68.0 and later print `Kani Rust Verifier <version> (<invocation>)`, |
| 28 | +# followed by a `CBMC <version>` line. |
| 29 | +# - Kani 0.67.0 and earlier used clap's default flag, printing `kani <version>`. |
| 30 | +installed_version=$( |
| 31 | + kani --version | |
| 32 | + sed -nE 's/^(Kani Rust Verifier|kani) ([^[:space:]]+).*/\2/p' | |
| 33 | + head -1 |
| 34 | +) |
26 | 35 |
|
27 | | -if [ $? -eq 0 ]; then |
28 | | - if [ "$1" == "latest" ]; then |
29 | | - # Cargo search returns version number as string |
30 | | - requested_version=$(cargo search kani-verifier | grep -m 1 "kani-verifier" | awk '{print $3}' | tr -d '"') |
31 | | - else |
32 | | - requested_version=$1 |
33 | | - fi |
| 36 | +if [ -z "$installed_version" ]; then |
| 37 | + echo "::error::Could not determine installed Kani version from \`kani --version\`" |
| 38 | + exit 1 |
| 39 | +fi |
34 | 40 |
|
35 | | - if [ "$installed_version" != "$requested_version" ]; then |
36 | | - echo "::error::The version of Kani installed was different than the one requested" |
| 41 | +if [ "$1" == "latest" ]; then |
| 42 | + # Cargo search returns version number as string. Force color off: the Rust |
| 43 | + # toolchain action exports CARGO_TERM_COLOR=always, and the escape codes it |
| 44 | + # adds would otherwise defeat the anchor below. |
| 45 | + requested_version=$(CARGO_TERM_COLOR=never cargo search kani-verifier | grep -m 1 "^kani-verifier " | awk '{print $3}' | tr -d '"') |
| 46 | + if [ -z "$requested_version" ]; then |
| 47 | + echo "::error::Could not determine the latest Kani version from \`cargo search\`" |
37 | 48 | exit 1 |
38 | 49 | fi |
| 50 | +else |
| 51 | + requested_version=$1 |
| 52 | +fi |
| 53 | + |
| 54 | +if [ "$installed_version" != "$requested_version" ]; then |
| 55 | + echo "::error::The version of Kani installed ($installed_version) was different than the one requested ($requested_version)" |
| 56 | + exit 1 |
39 | 57 | fi |
0 commit comments