rustyhorde / vergen

Generate cargo instructions at compile time in build scripts for use with the env! or option_env! macros
Apache License 2.0
392 stars 56 forks source link

"Error: object not found - no match for id" in case of a shallow clone #250

Closed artemyarulin closed 9 months ago

artemyarulin commented 1 year ago

vergen fails to get git information in case of git shallow clone is used. As far as I've understood most recent Github Actions actions/checkout@v4 uses shallow clone by default, so vergen starts to fail after upgrade with en error. When fail_on_error is set:

error: failed to run custom build command for `qqself-api-sync v0.0.0 (/home/runner/work/qqself/qqself/api-sync)`
Caused by:
  process didn't exit successfully: `/home/runner/work/qqself/qqself/target/release/build/qqself-api-sync-156c4bcf22177982/build-script-build` (exit status: 1)
  --- stderr
  Error: object not found - no match for id (845128e58eb8985fdb10d015c4ea80a35b248f8d); class=Odb (9); code=NotFound (-3)

and with default settings when fail_on_error is not set:

warning: object not found - no match for id (845128e58eb8985fdb10d015c4ea80a35b248f8d); class=Odb (9); code=NotFound (-3)
warning: VERGEN_GIT_BRANCH set to default
warning: VERGEN_GIT_COMMIT_AUTHOR_EMAIL set to default
warning: VERGEN_GIT_COMMIT_AUTHOR_NAME set to default
warning: VERGEN_GIT_COMMIT_COUNT set to default
warning: VERGEN_GIT_COMMIT_DATE set to default
warning: VERGEN_GIT_COMMIT_MESSAGE set to default
warning: VERGEN_GIT_COMMIT_TIMESTAMP set to default
warning: VERGEN_GIT_DESCRIBE set to default
warning: VERGEN_GIT_SHA set to default

cargo.toml

[build-dependencies]
vergen = { version = "8.2.4", features = ["build", "cargo", "git", "git2", "rustc"] }

and build.rs

use std::error::Error;
use vergen::EmitBuilder;

fn main() -> Result<(), Box<dyn Error>> {
    EmitBuilder::builder()
        .all_build()
        .all_cargo()
        .all_git()
        .all_rustc()
        .fail_on_error()
        .emit()?;
    Ok(())
}

I don't think it's a vergen error and probably coming from inside of git dependencies, but just wanted to create an issue here for the visibility just in case someone else encounter the same. With Github Actions solutions is make a full clone

- uses: actions/checkout@v4
  with:
      fetch-depth: 0 # vergen fails in case of a default shallow clone
CraZySacX commented 12 months ago

Yeah this isn't strictly a vergen issue. There could be some preemptive checking for git tree states that vergen can't handle possible (shallow clones, submodules, and worktrees come to mind).

artemyarulin commented 12 months ago

Yeah, feel free to close it, just made the issue for the visibility