Skip to content

Commit

Permalink
feature(turborepo): Port Run Summary (#5833)
Browse files Browse the repository at this point in the history
### Description

Implements the boilerplate for run summary, along with dry run text
output. Not complete, but the PR was getting a little too large.

### Testing Instructions

<!--
  Give a quick description of steps to test your changes.
-->


Closes TURBO-1278

---------

Co-authored-by: nicholaslyang <Nicholas Yang>
  • Loading branch information
NicholasLYang committed Sep 25, 2023
1 parent 8db39f2 commit 2bb8c9a
Show file tree
Hide file tree
Showing 30 changed files with 990 additions and 99 deletions.
32 changes: 32 additions & 0 deletions Cargo.lock

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

7 changes: 7 additions & 0 deletions crates/turborepo-api-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub use crate::error::{Error, Result};

mod error;
mod retry;
mod spaces;

lazy_static! {
static ref AUTHORIZATION_REGEX: Regex =
Expand All @@ -32,6 +33,12 @@ pub struct APIClient {
use_preflight: bool,
}

pub struct APIAuth {
pub team_id: String,
pub token: String,
pub team_slug: Option<String>,
}

impl APIClient {
pub async fn get_user(&self, token: &str) -> Result<UserResponse> {
let url = self.make_url("/v2/user");
Expand Down
7 changes: 7 additions & 0 deletions crates/turborepo-api-client/src/spaces.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use crate::APIClient;

impl APIClient {
async fn create_spaces_run() {

Check warning on line 4 in crates/turborepo-api-client/src/spaces.rs

View workflow job for this annotation

GitHub Actions / Build Turborepo (ubuntu, ubuntu-latest)

associated function `create_spaces_run` is never used

Check warning on line 4 in crates/turborepo-api-client/src/spaces.rs

View workflow job for this annotation

GitHub Actions / Build Turborepo (macos, macos-latest)

associated function `create_spaces_run` is never used

Check warning on line 4 in crates/turborepo-api-client/src/spaces.rs

View workflow job for this annotation

GitHub Actions / Build Turborepo (windows, windows-latest)

associated function `create_spaces_run` is never used

Check warning on line 4 in crates/turborepo-api-client/src/spaces.rs

View workflow job for this annotation

GitHub Actions / Go Unit Tests (ubuntu, ubuntu-latest)

associated function `create_spaces_run` is never used

Check warning on line 4 in crates/turborepo-api-client/src/spaces.rs

View workflow job for this annotation

GitHub Actions / Turborepo E2E Tests (ubuntu, ubuntu-latest)

associated function `create_spaces_run` is never used

Check warning on line 4 in crates/turborepo-api-client/src/spaces.rs

View workflow job for this annotation

GitHub Actions / Turborepo Examples (ubuntu, ubuntu-latest)

associated function `create_spaces_run` is never used

Check warning on line 4 in crates/turborepo-api-client/src/spaces.rs

View workflow job for this annotation

GitHub Actions / Go Unit Tests (macos, macos-latest)

associated function `create_spaces_run` is never used

Check warning on line 4 in crates/turborepo-api-client/src/spaces.rs

View workflow job for this annotation

GitHub Actions / Turborepo Examples (macos, macos-latest)

associated function `create_spaces_run` is never used

Check warning on line 4 in crates/turborepo-api-client/src/spaces.rs

View workflow job for this annotation

GitHub Actions / Turborepo E2E Tests (windows, windows-latest)

associated function `create_spaces_run` is never used

Check warning on line 4 in crates/turborepo-api-client/src/spaces.rs

View workflow job for this annotation

GitHub Actions / Go Unit Tests (windows, windows-latest)

associated function `create_spaces_run` is never used

Check warning on line 4 in crates/turborepo-api-client/src/spaces.rs

View workflow job for this annotation

GitHub Actions / Go Integration Tests (ubuntu, ubuntu-latest)

associated function `create_spaces_run` is never used

Check warning on line 4 in crates/turborepo-api-client/src/spaces.rs

View workflow job for this annotation

GitHub Actions / Turborepo E2E Tests (macos, macos-latest)

associated function `create_spaces_run` is never used
todo!()
}
}
7 changes: 3 additions & 4 deletions crates/turborepo-cache/src/async_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use std::sync::Arc;
use futures::{stream::FuturesUnordered, StreamExt};
use tokio::task::JoinHandle;
use turbopath::{AbsoluteSystemPath, AbsoluteSystemPathBuf, AnchoredSystemPathBuf};
use turborepo_api_client::APIClient;
use turborepo_api_client::{APIAuth, APIClient};

use crate::{http::APIAuth, multiplexer::CacheMultiplexer, CacheError, CacheOpts, CacheResponse};
use crate::{multiplexer::CacheMultiplexer, CacheError, CacheOpts, CacheResponse};

pub struct AsyncCache {
workers: FuturesUnordered<JoinHandle<()>>,
Expand Down Expand Up @@ -85,11 +85,10 @@ mod tests {
use futures::future::try_join_all;
use tempfile::tempdir;
use turbopath::AbsoluteSystemPathBuf;
use turborepo_api_client::APIClient;
use turborepo_api_client::{APIAuth, APIClient};
use turborepo_vercel_api_mock::start_test_server;

use crate::{
http::APIAuth,
test_cases::{get_test_cases, TestCase},
AsyncCache, CacheError, CacheOpts, CacheResponse, CacheSource, RemoteCacheOpts,
};
Expand Down
8 changes: 1 addition & 7 deletions crates/turborepo-cache/src/http.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{backtrace::Backtrace, io::Write};

use turbopath::{AbsoluteSystemPath, AbsoluteSystemPathBuf, AnchoredSystemPathBuf};
use turborepo_api_client::{APIClient, Response};
use turborepo_api_client::{APIAuth, APIClient, Response};

use crate::{
cache_archive::{CacheReader, CacheWriter},
Expand All @@ -18,12 +18,6 @@ pub struct HTTPCache {
team_slug: Option<String>,
}

pub struct APIAuth {
pub team_id: String,
pub token: String,
pub team_slug: Option<String>,
}

impl HTTPCache {
pub fn new(
client: APIClient,
Expand Down
8 changes: 2 additions & 6 deletions crates/turborepo-cache/src/multiplexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ use std::sync::atomic::{AtomicBool, Ordering};

use tracing::{debug, warn};
use turbopath::{AbsoluteSystemPath, AnchoredSystemPathBuf};
use turborepo_api_client::APIClient;
use turborepo_api_client::{APIAuth, APIClient};

use crate::{
fs::FSCache,
http::{APIAuth, HTTPCache},
CacheError, CacheOpts, CacheResponse,
};
use crate::{fs::FSCache, http::HTTPCache, CacheError, CacheOpts, CacheResponse};

pub struct CacheMultiplexer {
// We use an `AtomicBool` instead of removing the cache because that would require
Expand Down
6 changes: 3 additions & 3 deletions crates/turborepo-ci/src/vendors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ pub struct Vendor {
pub(crate) constant: &'static str,
pub(crate) env: VendorEnvs,
pub(crate) eval_env: Option<HashMap<&'static str, &'static str>>,
pub(crate) sha_env_var: Option<&'static str>,
pub(crate) branch_env_var: Option<&'static str>,
pub(crate) username_env_var: Option<&'static str>,
pub sha_env_var: Option<&'static str>,
pub branch_env_var: Option<&'static str>,
pub username_env_var: Option<&'static str>,
}

static VENDORS: OnceLock<[Vendor; 45]> = OnceLock::new();
Expand Down
2 changes: 2 additions & 0 deletions crates/turborepo-env/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ license = "MPL-2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
hex = { workspace = true }
lazy_static = { workspace = true }
regex = { workspace = true }
serde = { workspace = true }
sha2 = { workspace = true }
test-case = { workspace = true }
thiserror = { workspace = true }
29 changes: 27 additions & 2 deletions crates/turborepo-env/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::{

use regex::Regex;
use serde::Serialize;
use sha2::{Digest, Sha256};
use thiserror::Error;

const DEFAULT_ENV_VARS: [&str; 1] = ["VERCEL_ANALYTICS_ID"];
Expand All @@ -32,6 +33,10 @@ pub enum Error {
pub struct EnvironmentVariableMap(HashMap<String, String>);

impl EnvironmentVariableMap {
// Returns a deterministically sorted set of EnvironmentVariablePairs
// from an EnvironmentVariableMap.
// This is the value that is used upstream as a task hash input,
// so we need it to be deterministic
pub fn to_hashable(&self) -> EnvironmentVariablePairs {
let mut list: Vec<_> = self.iter().map(|(k, v)| format!("{}={}", k, v)).collect();
list.sort();
Expand All @@ -45,10 +50,30 @@ impl EnvironmentVariableMap {

names
}

// Returns a deterministically sorted set of EnvironmentVariablePairs
// from an EnvironmentVariableMap
// This is the value used to print out the task hash input,
// so the values are cryptographically hashed
pub fn to_secret_hashable(&self) -> EnvironmentVariablePairs {
self.iter()
.map(|(k, v)| {
if !v.is_empty() {
let mut hasher = Sha256::new();
hasher.update(v.as_bytes());
let hash = hasher.finalize();
let hexed_hash = hex::encode(hash);
format!("{}=", hexed_hash)
} else {
format!("{}=", k)
}
})
.collect()
}
}

// BySource contains a map of environment variables broken down by the source
#[derive(Debug, Serialize, Clone)]
#[derive(Debug, Default, Serialize, Clone)]
pub struct BySource {
pub explicit: EnvironmentVariableMap,
pub matching: EnvironmentVariableMap,
Expand All @@ -57,7 +82,7 @@ pub struct BySource {
// DetailedMap contains the composite and the detailed maps of environment
// variables All is used as a taskhash input (taskhash.CalculateTaskHash)
// BySource is used by dry runs and run summaries
#[derive(Debug, Serialize, Clone)]
#[derive(Debug, Default, Serialize, Clone)]
pub struct DetailedMap {
pub all: EnvironmentVariableMap,
pub by_source: BySource,
Expand Down
2 changes: 2 additions & 0 deletions crates/turborepo-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ num_cpus = "1.15.0"
owo-colors.workspace = true
rayon = "1.7.0"
regex.workspace = true
svix-ksuid = { version = "0.7.0", features = ["serde"] }
tabwriter = "1.3.0"
tracing-appender = "0.2.2"
tracing-chrome = { version = "0.7.1", optional = true }
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
Expand Down
4 changes: 4 additions & 0 deletions crates/turborepo-lib/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ impl CommandBase {
// We directly use repo_root to avoid converting back to absolute system path
&self.repo_root
}

pub fn version(&self) -> &'static str {
self.version
}
}

#[cfg(test)]
Expand Down
32 changes: 17 additions & 15 deletions crates/turborepo-lib/src/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::collections::HashMap;

use capnp::message::{Builder, HeapAllocator};
pub use traits::TurboHash;
use turborepo_env::ResolvedEnvMode;
use turborepo_env::{EnvironmentVariablePairs, ResolvedEnvMode};

use crate::{cli::EnvMode, task_graph::TaskOutputs};

Expand Down Expand Up @@ -66,11 +66,11 @@ pub struct TaskHashable<'a> {
#[derive(Debug, Clone)]
pub struct GlobalHashable<'a> {
pub global_cache_key: &'static str,
pub global_file_hash_map: HashMap<turbopath::RelativeUnixPathBuf, String>,
pub global_file_hash_map: &'a HashMap<turbopath::RelativeUnixPathBuf, String>,
// This is None in single package mode
pub root_external_dependencies_hash: Option<String>,
pub root_external_dependencies_hash: Option<&'a str>,
pub env: &'a [String],
pub resolved_env_vars: Vec<String>,
pub resolved_env_vars: EnvironmentVariablePairs,
pub pass_through_env: &'a [String],
pub env_mode: EnvMode,
pub framework_inference: bool,
Expand Down Expand Up @@ -288,7 +288,7 @@ impl From<TaskHashable<'_>> for Builder<HeapAllocator> {
}
}

impl<'a> From<GlobalHashable<'a>> for Builder<HeapAllocator> {
impl From<GlobalHashable<'_>> for Builder<HeapAllocator> {
fn from(hashable: GlobalHashable) -> Self {
let mut message =
::capnp::message::TypedBuilder::<proto_capnp::global_hashable::Owned>::new_default();
Expand All @@ -305,8 +305,8 @@ impl<'a> From<GlobalHashable<'a>> for Builder<HeapAllocator> {
// get a sorted iterator over keys and values of the hashmap
// and set the entries in the capnp message

let mut hashable: Vec<_> = hashable.global_file_hash_map.into_iter().collect();
hashable.sort_by(|a, b| a.0.cmp(&b.0));
let mut hashable: Vec<_> = hashable.global_file_hash_map.iter().collect();
hashable.sort_by(|a, b| a.0.cmp(b.0));

for (i, (key, value)) in hashable.iter().enumerate() {
let mut entry = entries.reborrow().get(i as u32);
Expand All @@ -316,7 +316,7 @@ impl<'a> From<GlobalHashable<'a>> for Builder<HeapAllocator> {
}

if let Some(root_external_dependencies_hash) = hashable.root_external_dependencies_hash {
builder.set_root_external_deps_hash(&root_external_dependencies_hash);
builder.set_root_external_deps_hash(root_external_dependencies_hash);
}

{
Expand Down Expand Up @@ -415,15 +415,17 @@ mod test {

#[test]
fn global_hashable() {
let global_file_hash_map = vec![(
turbopath::RelativeUnixPathBuf::new("global_file_hash_map").unwrap(),
"global_file_hash_map".to_string(),
)]
.into_iter()
.collect();

let global_hash = GlobalHashable {
global_cache_key: "global_cache_key",
global_file_hash_map: vec![(
turbopath::RelativeUnixPathBuf::new("global_file_hash_map").unwrap(),
"global_file_hash_map".to_string(),
)]
.into_iter()
.collect(),
root_external_dependencies_hash: Some("0000000000000000".to_string()),
global_file_hash_map: &global_file_hash_map,
root_external_dependencies_hash: Some("0000000000000000"),
env: &["env".to_string()],
resolved_env_vars: vec![],
pass_through_env: &["pass_through_env".to_string()],
Expand Down
6 changes: 3 additions & 3 deletions crates/turborepo-lib/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ pub struct RunOpts<'a> {
pub(crate) env_mode: EnvMode,
// Whether or not to infer the framework for each workspace.
pub(crate) framework_inference: bool,
profile: Option<&'a str>,
pub profile: Option<&'a str>,
continue_on_error: bool,
pub(crate) pass_through_args: &'a [String],
pub(crate) only: bool,
dry_run: bool,
pub(crate) dry_run: bool,
pub(crate) dry_run_json: bool,
pub graph: Option<GraphOpts<'a>>,
pub(crate) no_daemon: bool,
pub(crate) single_package: bool,
pub log_prefix: ResolvedLogPrefix,
pub log_order: ResolvedLogOrder,
summarize: Option<Option<bool>>,
pub summarize: Option<Option<bool>>,
pub(crate) experimental_space_id: Option<String>,
pub is_github_actions: bool,
}
Expand Down
Loading

0 comments on commit 2bb8c9a

Please sign in to comment.