Skip to content

Fix/get action to work #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Minimum Supported Rust

on:
pull_request:
branches:
- main
workflow_dispatch:

jobs:
find-smallest-rust:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
path: itself
- uses: actions/checkout@v4
with:
repository: NethermindEth/juno
path: juno
ref: 153e651f156fd579a9e4e6676fe3ca9b881b05c2
- name: Find smallest supported Rust version
id: current
uses: ./itself
with:
paths: juno/core/rust/,juno/vm/rust/,juno/starknet/rust/

- name: Compare versions
run: |
set -euo pipefail

expected_msrv="1.80.1"
current_msrv="${{ steps.current.outputs.highest-msrv }}"
if [[ "$expected_msrv" != "$current_msrv" ]]; then
echo "Minimum supported Rust version is $current_msrv, expected $expected_msrv"
exit 1
else
echo "Minimum supported Rust version is $current_msrv as expected"
fi
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v4
uses: actions/checkout@v4

- name: Detect Rust Minimum Version
uses: derrix060/detect-rust-minimum-version@v1
with: repo/my-path1,repo/my-path2
id: rust-version
uses: derrix060/detect-rust-minimum-version@v1
with:
repos: repo/my-path1,repo/my-path2

- name:
- name: Print version
run: echo "Minimum rust version is ${{ steps.rust-version.outputs.highest-msrv }}"
```

## Inputs
Expand Down
34 changes: 21 additions & 13 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ runs:
- name: Setup Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: cargo-msrv
components: cargo

- name: Install cargo-msrv
shell: bash
run: cargo install cargo-msrv

- name: Setup jq
uses: dcarbone/install-jq-action@v2.1.0
Expand All @@ -32,6 +36,8 @@ runs:
id: cargo-msrv
shell: bash
run: |
set -euxo pipefail

# Split the input paths by commas
IFS=',' read -r -a paths <<< "${{ inputs.paths }}"

Expand All @@ -40,36 +46,38 @@ runs:

# Function to compare versions
compare_versions() {
if [ "$1" == "$2" ]; then
return 0
elif [[ "$1" == "$(echo -e "$1\n$2" | sort -V | head -n1)" ]]; then
return 1
if [[ "$1" == "$2" ]]; then
echo 0
elif [[ "$1" == "$(echo -e "$1\n$2" | sort -Vr | head -n1)" ]]; then
echo 1
else
return 2
echo 2
fi
}

# Loop through all paths and run cargo-msrv
for path in "${paths[@]}"; do
echo "Running cargo-msrv for $path"
version=$(cargo msrv --path "$path" --output-format json | jq -r '.msrv')

if [ "$version" == "null" ]; then
rm -f logs
cargo msrv --path $path --output-format json --no-log > logs
version=$(cat logs | grep "msrv-complete" | jq -r '.msrv')
if [[ "$version" == "null" ]]; then
echo "Could not find MSRV for $path"
cat logs
exit 1
fi

echo "Found MSRV $version for $path"

# Compare and store the highest version
compare_versions $highest_msrv $version
result=$?
if [ "$result" -eq 2 ]; then
result=$(compare_versions $highest_msrv $version)
if [[ "$result" -eq "2" ]]; then
echo "Found higher MSRV $version than $highest_msrv"
highest_msrv=$version
fi
done

echo "The highest MSRV is $highest_msrv"

# Set output
echo "::set-output name=highest-msrv::$highest_msrv"
echo "highest-msrv=$highest_msrv" >> $GITHUB_OUTPUT