Skip to content

Commit bc30368

Browse files
fix(vdev): make build vrl-docs work with released VRL version (#24877)
* fix(vdev): make build vrl-docs work with released VRL version * Format * Import bail
1 parent f2c50cb commit bc30368

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

vdev/src/commands/build/vrl_docs.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{
44
path::{Path, PathBuf},
55
};
66

7-
use anyhow::{Context, Result};
7+
use anyhow::{Context, Result, bail};
88
use serde::{Deserialize, Serialize};
99
use serde_json::Value;
1010

@@ -99,6 +99,7 @@ impl Cli {
9999
#[derive(Deserialize)]
100100
struct LockPackage {
101101
name: String,
102+
version: String,
102103
source: Option<String>,
103104
}
104105

@@ -107,7 +108,10 @@ struct CargoLock {
107108
package: Vec<LockPackage>,
108109
}
109110

110-
/// Parse `Cargo.lock` to find the git commit SHA for the `vrl` package.
111+
/// Parse `Cargo.lock` to find a git ref for the `vrl` package.
112+
///
113+
/// Returns the commit SHA for git-sourced dependencies, or a version tag (e.g. `v0.31.0`) for
114+
/// registry-sourced dependencies.
111115
fn get_vrl_commit_sha(repo_root: &Path) -> Result<String> {
112116
let lock_path = repo_root.join("Cargo.lock");
113117
let lock_text = fs::read_to_string(&lock_path)
@@ -119,22 +123,20 @@ fn get_vrl_commit_sha(repo_root: &Path) -> Result<String> {
119123
let pkg = lock
120124
.package
121125
.iter()
122-
.find(|p| {
123-
p.name == VRL_PACKAGE_NAME
124-
&& p.source
125-
.as_deref()
126-
.is_some_and(|s| s.contains("github.com/vectordotdev/vrl"))
127-
})
128-
.context("Could not find VRL package with git source in Cargo.lock")?;
129-
130-
// Source format: "git+https://github.com/vectordotdev/vrl.git?branch=doc-generation#5316c01b..."
131-
let source = pkg.source.as_deref().unwrap();
132-
let sha = source
133-
.rsplit_once('#')
134-
.map(|(_, sha)| sha)
135-
.context("Could not extract commit SHA from VRL source string")?;
136-
137-
Ok(sha.to_string())
126+
.find(|p| p.name == VRL_PACKAGE_NAME)
127+
.context("Could not find VRL package in Cargo.lock")?;
128+
129+
match pkg.source.as_deref() {
130+
// Git source: "git+https://github.com/vectordotdev/vrl.git?branch=main#5316c01b..."
131+
Some(source) if source.starts_with("git+") => source
132+
.rsplit_once('#')
133+
.map(|(_, sha)| sha.to_string())
134+
.context("Could not extract commit SHA from VRL git source string"),
135+
// Registry source (crates.io): use the version as a tag
136+
Some(source) if source.starts_with("registry+") => Ok(format!("v{}", pkg.version)),
137+
Some(source) => bail!("Unrecognized VRL package source in Cargo.lock: {source}"),
138+
None => bail!("VRL package in Cargo.lock has no source field"),
139+
}
138140
}
139141

140142
/// Read all `*.json` files from a directory into a name->value map.

vdev/src/utils/git.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ pub fn sparse_checkout_docs(sha: &str, repo_url: &str, clone_dir: &Path) -> Resu
231231
.context("Failed to write sparse-checkout config")?;
232232

233233
git(&["fetch", "--depth", "1", "origin", sha])?;
234-
git(&["checkout", sha])?;
234+
git(&["checkout", "FETCH_HEAD"])?;
235235

236236
Ok(())
237237
}

0 commit comments

Comments
 (0)