Skip to content
Open
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
18 changes: 18 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,24 @@ jobs:
exit 1
fi

check-outdated-api-hashes:
needs: changed-files
if: needs.changed-files.outputs.should-run == 'true'
runs-on: ubuntu-latest
timeout-minutes: 15

steps:
- uses: actions/checkout@v6.0.2
- uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Check for outdated api-hashes.json
run: |
if ! diff linera-version/api-hashes.json <(cargo run --locked -p linera-version)
then
echo '`linera-version/api-hashes.json` differs from the computed API hashes'
echo 'Run `cargo run -p linera-version > linera-version/api-hashes.json` to update it.'
exit 1
fi

benchmark-test:
needs: changed-files
if: needs.changed-files.outputs.should-run == 'true'
Expand Down
3 changes: 3 additions & 0 deletions linera-version/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ sha3.workspace = true
thiserror.workspace = true
tracing.workspace = true

[dev-dependencies]
serde_json.workspace = true

[build-dependencies]
base64.workspace = true
cargo_metadata.workspace = true
Expand Down
6 changes: 3 additions & 3 deletions linera-version/api-hashes.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"rpc": "K9p3m/MsIPZL32CYddAqlG6PHKprJvMjei5cIiqFgDY",
"graphql": "RmwcE5swpH/HkjbetY/YyD6ebNQFS9oeU6ayEAvDjEQ",
"wit": "0X+I4jeHCdpD2M0R+OVodI4pH+dF9rt0K/iHENVcnug"
"rpc": "R+hOHa12w3uYcIYh7AW+JXwo97bEOH1Nm0IoAqZshvs",
"graphql": "u/1mosg1Nwe2EyvhMVpFVSy7lVNYuKecArYcNK80nw8",
"wit": "LBDK3ZORkwFJX1WI+P0neR3xZNtvhufYjvfROgBR3QM"
}
1 change: 1 addition & 0 deletions linera-version/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use linera_version::VersionInfo;

fn main() -> anyhow::Result<()> {
serde_json::to_writer_pretty(std::io::stdout(), &VersionInfo::get()?.api_hashes())?;
println!();

Ok(())
}
33 changes: 24 additions & 9 deletions linera-version/src/version_info/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,29 +233,44 @@ impl VersionInfo {
}
.into();

let api_hashes: ApiHashes = serde_json::from_reader(fs_err::File::open(api_hashes_path)?)?;

let rpc_hash = get_hash(
paths,
&metadata,
"linera-rpc",
"tests/snapshots/format__format.yaml.snap",
)
.unwrap_or(api_hashes.rpc)
.into();
.ok();

let graphql_hash = get_hash(
paths,
&metadata,
"linera-service-graphql-client",
"gql/*.graphql",
)
.unwrap_or(api_hashes.graphql)
.into();
.ok();

let wit_hash = get_hash(paths, &metadata, "linera-sdk", "wit/*.wit").ok();

// The cache is a stand-in for the API source files, which a published crate does not
// ship; reading it only when a hash is missing keeps it writable from its own output.
let (rpc_hash, graphql_hash, wit_hash) = match (rpc_hash, graphql_hash, wit_hash) {
(Some(rpc_hash), Some(graphql_hash), Some(wit_hash)) => {
(rpc_hash, graphql_hash, wit_hash)
}
(rpc_hash, graphql_hash, wit_hash) => {
let api_hashes: ApiHashes =
serde_json::from_reader(fs_err::File::open(api_hashes_path)?)?;
(
rpc_hash.unwrap_or(api_hashes.rpc),
graphql_hash.unwrap_or(api_hashes.graphql),
wit_hash.unwrap_or(api_hashes.wit),
)
}
};

let wit_hash = get_hash(paths, &metadata, "linera-sdk", "wit/*.wit")
.unwrap_or(api_hashes.wit)
.into();
let rpc_hash = rpc_hash.into();
let graphql_hash = graphql_hash.into();
let wit_hash = wit_hash.into();

Ok(Self {
crate_version,
Expand Down
15 changes: 13 additions & 2 deletions linera-version/tests/up_to_date.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
// Copyright (c) Zefchain Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use linera_version::VersionInfo;
use linera_version::{ApiHashes, VersionInfo};

/// Checks the committed hash cache against the hashes computed from the API source files.
///
/// The cache is only read when those files cannot be located, which is the case for a
/// published crate but not within this repository.
#[test]
fn up_to_date() {
let cached_path = concat!(env!("CARGO_MANIFEST_DIR"), "/api-hashes.json");
let cached: ApiHashes = serde_json::from_str(
&std::fs::read_to_string(cached_path)
.unwrap_or_else(|error| panic!("failed to read `{cached_path}`: {error}")),
)
.unwrap_or_else(|error| panic!("failed to parse `{cached_path}`: {error}"));

assert_eq!(
VersionInfo::get().unwrap().api_hashes(),
VersionInfo::default().api_hashes(),
cached,
"`linera-version` API hash cache out of date.\n\
Please update `linera-version/api-hashes.json` by running:\n\
$ cargo run -p linera-version > linera-version/api-hashes.json"
Expand Down
Loading