diff --git a/.circleci/config.yml b/.circleci/config.yml index bf92df70d..fe47cc981 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,15 +8,15 @@ workflows: matrix: parameters: platform: [ubuntu_gnu] - rust_version: [stable] + rust_channel: [stable] command: [lint] test: jobs: - xtask: matrix: parameters: - platform: [ubuntu_gnu, ubuntu_musl] - rust_version: [stable, nightly] + platform: [ubuntu_gnu, ubuntu_musl, macos] + rust_channel: [stable, nightly] command: [test] executors: @@ -25,12 +25,16 @@ executors: - image: cimg/base:stable environment: XTASK_TARGET: "x86_64-unknown-linux-gnu" - TMPDIR: "/home/circleci/test_tmp" ubuntu_musl: &ubuntu_musl_executor docker: - image: cimg/base:stable environment: XTASK_TARGET: "x86_64-unknown-linux-musl" + macos: &macos_executor + macos: + xcode: "12.5" + environment: + XTASK_TARGET: "x86_64-apple-darwin" # reusable command snippets can be referred to in any `steps` object commands: @@ -39,26 +43,26 @@ commands: - node/install: node-version: "16" npm-version: "7" - ubuntu_setup_tmp: + ubuntu_setup: steps: - run: - name: Create tmp directory - command: mkdir $TMPDIR - ubuntu_gnu_install_deps: + name: Update apt repository + command: sudo apt-get update + ubuntu_install_openssl: steps: - run: name: Install OpenSSL - command: sudo apt-get update && sudo apt-get install -y libssl-dev - ubuntu_musl_install_deps: + command: sudo apt-get install -y libssl-dev + ubuntu_install_musl_tools: steps: - run: name: Install musl-tools - command: sudo apt-get update && sudo apt-get install -y musl-tools + command: sudo apt-get install -y musl-tools jobs: xtask: parameters: - rust_version: + rust_channel: type: enum enum: ["stable", "nightly"] default: stable @@ -74,16 +78,18 @@ jobs: condition: equal: [ *ubuntu_gnu_executor, << parameters.platform >> ] steps: - - ubuntu_gnu_install_deps - - ubuntu_setup_tmp + - ubuntu_setup + - ubuntu_install_openssl - when: condition: equal: [ *ubuntu_musl_executor, << parameters.platform >> ] steps: - - ubuntu_musl_install_deps + - ubuntu_setup + - ubuntu_install_openssl + - ubuntu_install_musl_tools - install_node - rust/install: - version: << parameters.rust_version >> + version: << parameters.rust_channel >> - restore_cache: keys: - rust-target-v1-<< parameters.platform >>-{{ checksum "Cargo.lock" }} diff --git a/xtask/src/commands/test.rs b/xtask/src/commands/test.rs index 81a482d21..757076a88 100644 --- a/xtask/src/commands/test.rs +++ b/xtask/src/commands/test.rs @@ -15,7 +15,7 @@ impl Test { pub fn run(&self, verbose: bool) -> Result<()> { let release = false; let mut cargo_runner = CargoRunner::new(verbose)?; - let git_runner = GitRunner::new(verbose)?; + let git_runner = GitRunner::try_new(verbose)?; cargo_runner.test(&self.target)?; diff --git a/xtask/src/tools/cargo.rs b/xtask/src/tools/cargo.rs index d26efbe3d..abc6d2845 100644 --- a/xtask/src/tools/cargo.rs +++ b/xtask/src/tools/cargo.rs @@ -47,7 +47,7 @@ impl CargoRunner { version: Option<&RoverVersion>, ) -> Result { if let Some(version) = version { - let git_runner = GitRunner::new(self.runner.verbose)?; + let git_runner = GitRunner::try_new(self.runner.verbose)?; let repo_path = git_runner.checkout_rover_version(version.to_string().as_str())?; let versioned_schema_url = format!( "https://github.com/apollographql/rover/releases/download/{0}/rover-{0}-schema.graphql", diff --git a/xtask/src/tools/git.rs b/xtask/src/tools/git.rs index e9279125c..5b2ee8895 100644 --- a/xtask/src/tools/git.rs +++ b/xtask/src/tools/git.rs @@ -1,4 +1,5 @@ use std::convert::TryFrom; +use std::{env, fs}; use crate::tools::Runner; @@ -7,44 +8,76 @@ use assert_fs::TempDir; use camino::Utf8PathBuf; pub(crate) struct GitRunner { - temp_dir_path: Utf8PathBuf, + repo: GitRepo, runner: Runner, +} + +enum GitRepo { + TempDir { + temp_dir_path: Utf8PathBuf, + + // we store _temp_dir here since its Drop implementation deletes the directory + _temp_dir: TempDir, + }, + CiDir { + ci_dir_path: Utf8PathBuf, + }, +} + +impl GitRepo { + fn try_new() -> Result { + Ok(if env::var_os("CI").is_some() { + let ci_dir_path = Utf8PathBuf::try_from(env::current_dir()?)?.join("test_tmp"); + fs::create_dir_all(&ci_dir_path)?; + GitRepo::CiDir { ci_dir_path } + } else { + let temp_dir = TempDir::new().with_context(|| "Could not create temp directory")?; + let temp_dir_path = Utf8PathBuf::try_from(temp_dir.path().to_path_buf()) + .with_context(|| "Temp directory was not valid Utf-8")?; + GitRepo::TempDir { + temp_dir_path, + _temp_dir: temp_dir, + } + }) + } - // we store _temp_dir here since its Drop implementation deletes the directory - _temp_dir: TempDir, + fn get_path(&self) -> &Utf8PathBuf { + match self { + GitRepo::TempDir { + temp_dir_path, + _temp_dir: _, + } => temp_dir_path, + GitRepo::CiDir { ci_dir_path } => ci_dir_path, + } + } } impl GitRunner { - pub(crate) fn new(verbose: bool) -> Result { + pub(crate) fn try_new(verbose: bool) -> Result { let runner = Runner::new("git", verbose)?; - let temp_dir = TempDir::new().with_context(|| "Could not create temp directory")?; - let temp_dir_path = Utf8PathBuf::try_from(temp_dir.path().to_path_buf()) - .with_context(|| "Temp directory was not valid Utf-8")?; - - Ok(GitRunner { - runner, - temp_dir_path, - _temp_dir: temp_dir, - }) + + let repo = GitRepo::try_new()?; + + Ok(GitRunner { runner, repo }) } pub(crate) fn clone_supergraph_demo(&self) -> Result { let repo_name = "supergraph-demo"; let repo_url = format!("https://github.com/apollographql/{}", repo_name); self.runner - .exec(&["clone", &repo_url], &self.temp_dir_path, None)?; + .exec(&["clone", &repo_url], self.repo.get_path(), None)?; - let repo_path = self.temp_dir_path.join(repo_name); + let repo_path = self.repo.get_path().join(repo_name); Ok(repo_path) } pub(crate) fn checkout_rover_version(&self, rover_version: &str) -> Result { let repo_name = "rover"; let repo_url = format!("https://github.com/apollographql/{}", repo_name); - self.runner - .exec(&["clone", &repo_url], &self.temp_dir_path, None)?; + let repo_path = self.repo.get_path(); + self.runner.exec(&["clone", &repo_url], repo_path, None)?; - let repo_path = self.temp_dir_path.join(repo_name); + let repo_path = repo_path.join(repo_name); self.runner.exec( &["checkout", &format!("tags/{}", rover_version)],