Skip to content

Commit

Permalink
ci: warn on outdated top level dependencies (#757)
Browse files Browse the repository at this point in the history
* mark: 0xaatif/outdated

* run: cargo init scripts

* feat: cargo xtask outdated

* ci: lint outdated

* chore: update description

* fix(ci): pin kurtosis version
  • Loading branch information
0xaatif authored Oct 31, 2024
1 parent 0aad2a7 commit 2b6abb5
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
# https://github.com/rust-lang/rust/pull/124129
# https://github.com/dtolnay/linkme/pull/88
rustflags = ["-Z", "linker-features=-lld"]

[alias]
xtask = ["run", "--package=xtask", "--"]
2 changes: 1 addition & 1 deletion .github/workflows/jerigon-native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
run: |
echo "deb [trusted=yes] https://apt.fury.io/kurtosis-tech/ /" | sudo tee /etc/apt/sources.list.d/kurtosis.list
sudo apt update
sudo apt install kurtosis-cli
sudo apt install kurtosis-cli=1.3.1
#It is much easier to use cast tool in scripts so install foundry
- name: Install Foundry
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/jerigon-zero.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
run: |
echo "deb [trusted=yes] https://apt.fury.io/kurtosis-tech/ /" | sudo tee /etc/apt/sources.list.d/kurtosis.list
sudo apt update
sudo apt install kurtosis-cli
sudo apt install kurtosis-cli=1.3.1
#It is much easier to use cast tool in scripts so install foundry
- name: Install Foundry
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,13 @@ jobs:
with:
tool: taplo-cli
- run: taplo fmt --check
outdated:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/rust
- uses: taiki-e/install-action@v2
with:
tool: cargo-outdated
- run: cargo xtask outdated
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"evm_arithmetization",
"mpt_trie",
"proc_macro",
"scripts",
"smt_trie",
"trace_decoder",
"zero",
Expand Down
23 changes: 23 additions & 0 deletions scripts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "xtask"
version = "0.0.0"
edition.workspace = true
license.workspace = true
repository.workspace = true
homepage.workspace = true
keywords.workspace = true
categories.workspace = true
publish = false

[dependencies]
anyhow.workspace = true
clap = { workspace = true, features = ["derive"] }
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true

[lints]
workspace = true

[[bin]]
name = "xtask"
path = "xtask.rs"
69 changes: 69 additions & 0 deletions scripts/xtask.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//! General purpose scripts for development

use std::process::{Command, Stdio};

use anyhow::{ensure, Context as _};
use clap::Parser;
use serde::Deserialize;

#[derive(Parser)]
enum Args {
/// Run `cargo-outdated`, printing warnings compatible with GitHub's CI.
///
/// If a direct dependency listed in our Cargo.lock is behind the latest
/// available on crates-io, a warning will be emitted.
///
/// Note that we only warn on our _direct_ dependencies,
/// not the entire supply chain.
Outdated,
}

#[derive(Deserialize)]
struct Outdated<'a> {
crate_name: &'a str,
dependencies: Vec<Dependency<'a>>,
}

#[derive(Deserialize)]
struct Dependency<'a> {
name: &'a str,
project: &'a str,
latest: &'a str,
}

fn main() -> anyhow::Result<()> {
match Args::parse() {
Args::Outdated => {
let output = Command::new("cargo")
.args(["outdated", "--root-deps-only", "--format=json"])
.stderr(Stdio::inherit())
.stdout(Stdio::piped())
.output()
.context("couldn't exec `cargo`")?;
ensure!(
output.status.success(),
"command failed with {}",
output.status
);
for Outdated {
crate_name,
dependencies,
} in serde_json::Deserializer::from_slice(&output.stdout)
.into_iter::<Outdated<'_>>()
.collect::<Result<Vec<_>, _>>()
.context("failed to parse output from `cargo outdated`")?
{
for Dependency {
name,
project,
latest,
} in dependencies
{
// https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-a-warning-message
println!("::warning title=outdated-dependency::dependency {name} of crate {crate_name} is at version {project}, but the latest is {latest}")
}
}
}
}
Ok(())
}

0 comments on commit 2b6abb5

Please sign in to comment.