Skip to content

Commit

Permalink
feat(source-scan): git checks, git metadata (#159)
Browse files Browse the repository at this point in the history
Summary of changes:
- `git dirty` check copied to `cargo near build` flow, it produces a
warning, unlike the error in `cargo near deploy` flow
- added `source_code_git_url` field to reproducible build metadata
- `git pushed to remote` check logic reworked
- repo is opened and `HEAD` is determined
- relative path of contract within repo is determined
- `CARGO_NEAR_SOURCE_CODE_SNAPSHOT` (adapted from
[cargo::core::SourceId](https://docs.rs/cargo/latest/cargo/core/struct.SourceId.html))
and `CARGO_NEAR_CONTRACT_PATH` are exported into container
- [x] github, package in root of a repo:
https://github.com/dj8yfo/sample_no_workspace/tree/6c5ae44150ce51349a95e1605ba053c4fe53cf28
- [x] github, package in subpath in repo :
https://github.com/dj8yfo/sample_workspace/tree/b2d5580037c84fd4038b467564a9be9e520611de/self-updates/update
- [x] github, package in submodule in repo :
https://github.com/dj8yfo/sample_workspace_with_submodules/tree/3d87c81517e1e23a5716c300fe4789b1aafc4c6f/self-updates
- [x] bitbucket, package in root of a repo:
https://bitbucket.org/dj8yfomule/scratch_check_git/src/master/


![Screenshot_20240503_204916](https://github.com/near/cargo-near/assets/26653921/046dca51-accb-4838-9eb0-5ae531cf4a59)
  • Loading branch information
dj8yfo committed May 10, 2024
1 parent 7585514 commit bf8696b
Show file tree
Hide file tree
Showing 15 changed files with 959 additions and 304 deletions.
82 changes: 29 additions & 53 deletions Cargo.lock

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

6 changes: 4 additions & 2 deletions cargo-near/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ near-cli-rs = { version = "0.9.0", default-features = false }
dunce = "1"
tempfile = "3.10.1"
git2 = "0.18"
cargo_toml = "0.19.1"
reqwest = "0.11.24"
home = "0.5.9"
pathdiff = { version = "0.2.1", features = ["camino"]}
unix_path = "1.0.1"
url = { version = "2.5.0", features = ["serde"]}

[target.'cfg(unix)'.dependencies]
nix = { version = "0.28.0", features = ["user", "process"] }
Expand Down
21 changes: 19 additions & 2 deletions cargo-near/src/commands/build_command/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use near_abi::BuildInfo;
use sha2::{Digest, Sha256};

use crate::commands::abi_command::abi::{AbiCompression, AbiFormat, AbiResult};
use crate::commands::build_command::BUILD_CMD_ENV_KEY;
use crate::commands::build_command::{
BUILD_CMD_ENV_KEY, CONTRACT_PATH_ENV_KEY, SOURCE_CODE_SNAPSHOT_ENV_KEY,
};
use crate::common::ColorPreference;
use crate::types::manifest::MANIFEST_FILE_NAME;
use crate::types::{manifest::CargoManifestPath, metadata::CrateMetadata};
Expand All @@ -22,6 +24,7 @@ pub(super) fn run(
color.apply();

export_nep_330_build_command();
print_nep_330_env();

util::handle_step("Checking the host environment...", || {
if !wasm32_target_libdir_exists() {
Expand Down Expand Up @@ -139,5 +142,19 @@ fn export_nep_330_build_command() {
let cmd = cmd.join(" ");

std::env::set_var(BUILD_CMD_ENV_KEY, cmd.clone());
log::info!("exported: {}='{}'", BUILD_CMD_ENV_KEY, cmd);
}

fn print_nep_330_env() {
log::info!("Variables, relevant for reproducible builds:");
for key in [
INSIDE_DOCKER_ENV_KEY,
BUILD_CMD_ENV_KEY,
CONTRACT_PATH_ENV_KEY,
SOURCE_CODE_SNAPSHOT_ENV_KEY,
] {
let value = std::env::var(key)
.map(|val| format!("'{}'", val))
.unwrap_or("unset".to_string());
log::info!("{}={}", key, value);
}
}

0 comments on commit bf8696b

Please sign in to comment.