Skip to content
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

Emit commit details on contract instantiation #183

Merged
merged 1 commit into from
Jun 28, 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
3 changes: 3 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ wasm = "run --package xtask -- wasm"
wasm-opt = "run --package xtask -- wasm-opt"
xtask = "run --package xtask --"
tally-data-req-fixture = "run --package xtask -- tally-data-req-fixture"

[env]
GIT_REVISION = "unknown"
5 changes: 4 additions & 1 deletion contract/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::{
// version info for migration info
const CONTRACT_NAME: &str = "staking";
pub const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
pub const GIT_REVISION: &str = env!("GIT_REVISION");

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
Expand All @@ -42,7 +43,9 @@ pub fn instantiate(
CONFIG.save(deps.storage, &init_config)?;
crate::msgs::data_requests::state::init_data_requests(deps.storage)?;

Ok(Response::new().add_attribute("method", "instantiate"))
Ok(Response::new()
.add_attribute("method", "instantiate")
.add_attribute("git_revision", GIT_REVISION))
}

#[cfg_attr(not(feature = "library"), entry_point)]
Expand Down
14 changes: 14 additions & 0 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ fn wasm(sh: &Shell) -> Result<()> {
"cargo build -p seda-contract --release --lib --target wasm32-unknown-unknown --locked"
)
.env("RUSTFLAGS", "-C link-arg=-s")
.env("GIT_REVISION", get_git_version()?)
.run()?;
Ok(())
}
Expand Down Expand Up @@ -161,3 +162,16 @@ fn tally_data_req_fixture(_sh: &Shell) -> Result<()> {

Ok(())
}

fn get_git_version() -> Result<String> {
let git_version = Command::new("git")
.args(["describe", "--always", "--dirty=-modified", "--tags"])
.output()
.context("Invoking git describe")?;
if !git_version.status.success() {
return Ok("unknown".to_string());
}

let version = String::from_utf8(git_version.stdout)?;
Ok(version)
}