Skip to content

Commit e621a98

Browse files
authored
Decouple kani version from kani-github-action version (#45)
This PR updates the action to add the parameter for kani-version which defaults to the value latest. The default value latest uses the latest version of Kani that is uploaded on crates.io unless a specific version is provided by the user, in which case that specific version of Kani will be used in the CI.
1 parent 7c99bc7 commit e621a98

File tree

4 files changed

+183
-6
lines changed

4 files changed

+183
-6
lines changed

.github/workflows/test-action.yml

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,61 @@ jobs:
1212
# you must check out the repository
1313
- name: Checkout
1414
uses: actions/checkout@v3
15-
- name: Run Kani
15+
16+
- name: Run Kani with invalid version
17+
id: set_error
18+
uses: ./
19+
with:
20+
working-directory: tests/cargo-kani/simple-lib
21+
kani-version: '0.1.10'
22+
continue-on-error: true
23+
24+
- name: Ensure "Run Kani with invalid version" fails
25+
id: get_error
26+
run: |
27+
# Check the outcome of "Run Kani with invalid version"
28+
if [[ "${{ steps.set_error.outcome }}" == "failure" ]]; then
29+
echo "Running Kani with invalid version "0.1.10" failed."
30+
else
31+
echo "::error::Running Kani with invalid version succeeded incorrectly or was skipped."
32+
exit 1
33+
fi
34+
35+
- name: Run Kani with older version
1636
uses: ./ # Uses the action in the root directory
1737
with:
1838
working-directory: tests/cargo-kani/simple-lib
39+
kani-version: '0.33.0'
40+
41+
- name: Test "Run Kani with older version"
42+
run: |
43+
installed_version=$(kani --version | awk '{print $2}')
44+
expected_version='0.33.0'
45+
46+
if [[ "$installed_version" == "$expected_version" ]]; then
47+
echo "The installed version ($installed_version) matches the expected version ($expected_version)."
48+
else
49+
echo "::error::The installed version ($installed_version) does not match the expected version ($expected_version)."
50+
exit 1
51+
fi
52+
53+
- name: Run Kani with latest version
54+
uses: ./ # Uses the action in the root directory
55+
with:
56+
working-directory: tests/cargo-kani/simple-lib
57+
58+
- name: Test "Run Kani with latest version"
59+
run: |
60+
installed_version=$(kani --version | awk '{print $2}')
61+
expected_version=$(cargo search kani-verifier | grep -m 1 "kani" | awk '{print $3}' | sed 's/"//g')
62+
63+
if [[ "$installed_version" == "$expected_version" ]]; then
64+
echo "The installed version ($installed_version) matches the latest version ($expected_version)"
65+
else
66+
echo "::error::The installed version ($installed_version) does not match the latest version ($expected_version)."
67+
exit 1
68+
fi
69+
1970
- name: Test ProfProof within Kani Action
2071
uses: ./
2172
with:

README.md

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,93 @@
22

33
This repository provides a GitHub Action for running the [Kani Rust Verifier](https://github.com/model-checking/kani) in CI.
44

5+
## Kani GitHub Action Parameters
6+
7+
The following parameters can be used to configure and customize the behavior of this GitHub Action:
8+
9+
**NOTE**: All the fields provided are optional and have default behaviors when not specified.
10+
11+
`kani-version`
12+
13+
- **Description**: The Kani version to use.
14+
- **Default**: `latest`
15+
- **Usage**: `latest` or `x.y.z` to mention which version Kani to use. [Cargo's version specific format is expected for specific versions](https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html).
16+
If omitted, the latest version of `Kani` hosted on [`Kani's crates.io page`](https://crates.io/crates/kani-verifier) will be installed and used.
17+
18+
`command`
19+
20+
- **Description**: The command to run Kani.
21+
- **Default**: `cargo-kani`
22+
- **Usage**: `cargo-kani` or `kani` or custom path to a `kani` binary. Subcommands need to be passed to the `args` field.
23+
24+
`working-directory`
25+
26+
- **Description**: The directory in which Kani should be run.
27+
- **Default**: `'.'`
28+
- **Usage**: `/path/to/project` or `.`
29+
30+
`args`
31+
32+
- **Description**: Additional arguments to pass to Kani.
33+
- **Default**: `''`
34+
- **Usage**: These arguments or subcommands will be appended to the Kani command.
35+
36+
`enable-propproof`
37+
38+
- **Description**: Experimental feature that allows Kani to verify [proptest harnesses](https://proptest-rs.github.io/proptest/proptest/index.html) using the PropProof feature.
39+
- **Default**: `false`
40+
- **Usage**: If set to `true`, Kani will enable the experimental PropProof feature for verifying proptest harnesses.
41+
42+
## Example usage in a workflow YAML file:
43+
44+
Here are a few examples of workflow YAML files for the Kani Github Action:
45+
46+
#### Example 1: Default configuration
47+
48+
Default config which uses the latest version of Kani to run `cargo-kani` on project in current directory.
49+
50+
```yaml
51+
jobs:
52+
kani:
53+
runs-on: ubuntu-latest
54+
steps:
55+
- name: Run Kani
56+
uses: model-checking/[email protected]
57+
```
58+
59+
#### Example 2: Use pinned version of Kani
60+
61+
Use a specific version of Kani, version `0.35.0`, to run `cargo-kani` on a project.
62+
63+
```yaml
64+
jobs:
65+
kani:
66+
runs-on: ubuntu-latest
67+
steps:
68+
- name: Run Kani
69+
uses: model-checking/[email protected]
70+
with:
71+
kani-version: '0.35.0'
72+
command: 'cargo-kani'
73+
working-directory: './path/to/project'
74+
```
75+
76+
#### Example 3: Run Kani with args
77+
78+
Use latest version of Kani, to run `cargo-kani --tests` on a project with `propproof` harnesses.
79+
80+
```yaml
81+
jobs:
82+
kani:
83+
runs-on: ubuntu-latest
84+
steps:
85+
- name: Run Kani
86+
uses: model-checking/[email protected]
87+
with:
88+
args: '--tests'
89+
enable-propproof: true
90+
```
91+
592
## Security
693

794
See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.
@@ -10,4 +97,3 @@ See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more inform
1097

1198
This code is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
1299
See [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT) for details.
13-

action.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ branding:
1010
color: 'orange'
1111

1212
inputs:
13+
kani-version:
14+
description: 'Kani Version number'
15+
required: false
16+
default: 'latest'
1317
command:
1418
description: 'Command to run.'
1519
required: false
@@ -34,11 +38,8 @@ runs:
3438
uses: dtolnay/rust-toolchain@stable
3539

3640
- name: Install Kani
41+
run: ${{ github.action_path }}/src/install-kani.sh ${{ inputs.kani-version }}
3742
shell: bash
38-
run: |
39-
export KANI_VERSION="0.37.0";
40-
cargo install --version $KANI_VERSION --locked kani-verifier;
41-
cargo-kani setup;
4243

4344
- name: Install PropProof
4445
if: ${{ inputs.enable-propproof == 'true' }}

src/install-kani.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
# Copyright Kani Contributors
3+
# SPDX-License-Identifier: Apache-2.0 OR MIT
4+
5+
# If version is latest, install directly from cargo
6+
if [ "$1" == "latest" ]; then
7+
cargo install --locked kani-verifier;
8+
else
9+
VERSION=$1
10+
cargo install --version $VERSION --locked kani-verifier;
11+
fi
12+
13+
# Check exit status for error handling
14+
if [ $? -eq 0 ]; then
15+
echo "Installed Kani $VERSION successfully"
16+
else
17+
echo "::error::Could not install Kani. Please check if the provided version is correct"
18+
exit 1
19+
fi
20+
21+
# Setup kani in ci
22+
cargo-kani setup;
23+
24+
# Get the current installed version of kani and check it against the latest version
25+
installed_version=$(kani --version | awk '{print $2}')
26+
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}')
31+
else
32+
requested_version=$1
33+
fi
34+
35+
if ["$installed_version" != "$requested_version"]; then
36+
echo "::error::The version of Kani installed was different than the one requested"
37+
exit 1
38+
fi
39+
fi

0 commit comments

Comments
 (0)