Skip to content

Commit

Permalink
Merge branch 'main' into wip-bump-jaq-to-2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jsuereth authored Dec 17, 2024
2 parents 5c3b83a + 33bd40e commit 3341a29
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ jobs:
# run: cargo test --workspace --all-features
- name: No-default features
run: cargo test --workspace --no-default-features
- name: History check
run: cargo xtask history
msrv:
name: Check MSRV
runs-on: ubuntu-latest
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ lcov.info

# Ignore the output of the `weaver resolve` command
output.json
resolved-schema.yaml
resolved-schema.yaml

# Ignore the temporary repo dir created by `cargo xtask history` command
history-temp-repo/
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# Global owners, will be the owners for everything in the repo

* @open-telemetry/weaver-maintainers
* @open-telemetry/weaver-approvers

# Semantic conventions schema
/schemas/semconv.schema.json @open-telemetry/specs-semconv-approvers
Expand Down
14 changes: 9 additions & 5 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ publish = false
rust-version = "1.81.0"

[workspace.dependencies]
serde = { version = "1.0.215", features = ["derive"] }
serde = { version = "1.0.216", features = ["derive"] }
serde_yaml = "0.9.34"
serde_json = { version = "1.0.133"}
thiserror = "2.0.6"
Expand Down
14 changes: 12 additions & 2 deletions crates/xtask/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "xtask"
version = "0.1.0"
publish = false # xtask is not meant to be published
version = "0.1.1"
publish = false # xtask is not meant to be published
authors.workspace = true
edition.workspace = true
repository.workspace = true
Expand All @@ -10,6 +10,16 @@ rust-version.workspace = true

[dependencies]
anyhow.workspace = true
assert_cmd = "2.0.14"
gix = { version = "0.68.0", default-features = false, features = [
"comfort",
"blocking-http-transport-reqwest",
"max-performance-safe",
"worktree-mutation",
"blocking-http-transport-reqwest-rust-tls",
] }
semver = "1.0.23"
serde_json.workspace = true
toml = "0.8.19"

#[lints]
Expand Down
108 changes: 108 additions & 0 deletions crates/xtask/src/history.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// SPDX-License-Identifier: Apache-2.0

use assert_cmd::Command;
use gix::clone::PrepareFetch;
use gix::create::{self, Kind};
use gix::{open, progress, Repository};
use semver::Version;
use std::fs;
use std::sync::atomic::AtomicBool;
use std::time::Duration;

const REPO_URL: &str = "https://github.com/open-telemetry/semantic-conventions.git";
const ARCHIVE_URL: &str =
"https://github.com/open-telemetry/semantic-conventions/archive/refs/tags/";
const START_TAG: &str = "v1.22.0";
const TEMP_REPO_DIR: &str = "history-temp-repo";

/// Get the git repository, no checkout
#[cfg(not(tarpaulin_include))]
fn get_repo() -> anyhow::Result<Repository> {
let _ = fs::remove_dir_all(TEMP_REPO_DIR);
let _ = fs::create_dir(TEMP_REPO_DIR);
let mut fetch = PrepareFetch::new(
REPO_URL,
TEMP_REPO_DIR,
Kind::WithWorktree,
create::Options {
destination_must_be_empty: true,
fs_capabilities: None,
},
open::Options::isolated(),
)?;

let (repo, _) = fetch.fetch_only(progress::Discard, &AtomicBool::new(false))?;
Ok(repo)
}

/// Get the list of tags from the git repository filtered by the start version
#[cfg(not(tarpaulin_include))]
fn get_versions_from_git(repo: &Repository, start_semver: Version) -> anyhow::Result<Vec<String>> {
let tags: Vec<String> = repo
.references()?
.tags()?
.filter_map(|reference| {
let reference = reference.ok()?;
let tag = reference.name().shorten().to_string();

// Ignore tags with a lower version than the start tag
let version_str = tag.trim_start_matches(char::is_alphabetic);
if let Ok(version) = Version::parse(version_str) {
if version >= start_semver {
Some(tag)
} else {
None
}
} else {
None
}
})
.collect();
Ok(tags)
}

/// Run registry check on every semconv archive starting from start_version
#[cfg(not(tarpaulin_include))]
pub fn run(start_version: Option<String>) -> anyhow::Result<()> {
use anyhow::Context;

let start_version = start_version.unwrap_or(START_TAG.to_string());
let start_semver = Version::parse(start_version.trim_start_matches(char::is_alphabetic))
.context(format!(
"The provided version `{start_version}` is not a valid semver."
))?;
let repo = get_repo().context("Failed to fetch the semconv repo.")?;
let versions =
get_versions_from_git(&repo, start_semver).context("Failed to get the tag list.")?;
let _ = fs::remove_dir_all(TEMP_REPO_DIR);
println!("Checking versions: {:?}", versions);
let mut failed = false;
for version in versions {
let mut cmd =
Command::cargo_bin("weaver").context("Failed to create the cargo command.")?;
let output = cmd
.arg("--quiet")
.arg("registry")
.arg("check")
.arg("-r")
.arg(format!("{ARCHIVE_URL}{version}.zip[model]"))
.timeout(Duration::from_secs(60))
.output()
.context("Failed to execute the weaver process.")?;

if output.status.success() {
println!("Success for: {}", version);
} else {
failed = true;
println!("Failure for: {}", version);
println!(
"{}",
String::from_utf8(output.stdout).context("Invalid UTF-8")?
);
}
}
if failed {
anyhow::bail!("Some versions failed the registry check.");
}
Ok(())
}
4 changes: 4 additions & 0 deletions crates/xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#![allow(clippy::print_stdout)]
#![allow(clippy::print_stderr)]

mod history;
mod validate;

#[cfg(not(tarpaulin_include))]
Expand All @@ -20,6 +21,7 @@ fn main() -> anyhow::Result<()> {
None => print_help(),
Some(task) => match task.as_str() {
"validate" => validate::run(),
"history" => history::run(std::env::args().nth(2)),
"help" => print_help(),
_ => {
eprintln!("Unknown task: {}", task);
Expand All @@ -38,6 +40,8 @@ Usage: Execute the command using `cargo xtask <task>`, e.g., `cargo xtask valida
Tasks:
- validate: Validate the entire structure of the weaver project.
- history: Run registry check on semconv models within back compatibility range.
Optionally provide a start semver e.g. `history 1.29.0`.
"
);
Ok(())
Expand Down
1 change: 1 addition & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pre-push-check:
cargo clippy --workspace --all-targets -- -D warnings --allow deprecated
rm -rf crates/weaver_forge/observed_output/*
cargo nextest run --all
cargo xtask history
# [workaround] removed --all-features due to an issue in one of the dependency in Tantity (zstd-safe)
# [ToDo LQ] Re-enable --all-features once the issue is resolved
# cargo doc --workspace --all-features --no-deps --document-private-items
Expand Down

0 comments on commit 3341a29

Please sign in to comment.