forked from open-telemetry/weaver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
88 lines (75 loc) · 3.01 KB
/
build.rs
File metadata and controls
88 lines (75 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// SPDX-License-Identifier: Apache-2.0
//! A build script to generate the gRPC OTLP receiver API (client and server stubs.
use std::{path::Path, time::SystemTime};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// The gRPC OTLP Receiver is vendored in `src/otlp_receiver/receiver` to avoid
// depending on protoc in GitHub Actions.
//
// To regenerate the gRPC API from the proto file:
// - Uncomment the following lines.
// - Run `cargo build` to regenerate the API.
// - Comment the following lines.
// - Commit the changes.
// tonic_prost_build::configure()
// .out_dir("src/registry/otlp/grpc_stubs")
// .compile_protos(
// &[
// "src/registry/otlp/proto/opentelemetry/proto/collector/logs/v1/logs_service.proto",
// "src/registry/otlp/proto/opentelemetry/proto/collector/metrics/v1/metrics_service.proto",
// "src/registry/otlp/proto/opentelemetry/proto/collector/trace/v1/trace_service.proto",
// ],
// &["src/registry/otlp/proto"],
// )?;
// Build the UI
check_ui()?;
Ok(())
}
fn timestamp(dir: walkdir::DirEntry) -> Result<SystemTime, Box<dyn std::error::Error>> {
let md = dir.metadata()?;
Ok(md.modified()?)
}
/// Helper function to determine if package-lock file is out of date.
fn is_package_lock_stale(dir: &Path) -> Result<bool, Box<dyn std::error::Error>> {
let lock_timestamp = dir.join("pnpm-lock.yaml").metadata()?.modified()?;
let package_timestamp = dir.join("package.json").metadata()?.modified()?;
if package_timestamp > lock_timestamp {
return Ok(true);
}
Ok(false)
}
/// Helper function to determine if NPM project is out of date.
fn is_ui_stale(dir: &Path) -> Result<bool, Box<dyn std::error::Error>> {
// If any output directories don't exist, rebuild.
if !dir.join("dist").exists() {
return Ok(true);
}
if !dir.join("node_modules").exists() {
return Ok(true);
}
// Now check source files. This may be a bit expensive, as we continuously check last modified.
let last_build = dir.join("dist/index.html").metadata()?.modified()?;
let lock_timestamp = dir.join("pnpm-lock.yaml").metadata()?.modified()?;
if lock_timestamp > last_build {
return Ok(true);
}
for entry in walkdir::WalkDir::new(dir.join("src")) {
if timestamp(entry?)? > last_build {
return Ok(true);
}
}
Ok(false)
}
fn check_ui() -> Result<(), Box<dyn std::error::Error>> {
let ui_dir = Path::new("ui");
// Check if UI is out of date before running.
if is_ui_stale(ui_dir)? {
println!("cargo::warning=Weaver UI is out of date. Please run `pnpm build` in the `ui` directory.");
return Ok(());
}
// Check if we need to install packages.
if is_package_lock_stale(ui_dir)? {
println!("cargo::warning=Weaver `ui/pnpm-lock.yaml` is out of date. Please run `pnpm install` in the `ui` directory.");
return Ok(());
}
Ok(())
}