Skip to content

Commit

Permalink
wip(ci): don't use temp directories in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
EverlastingBugstopper committed Sep 1, 2021
1 parent 68a15b7 commit 7531121
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 36 deletions.
38 changes: 22 additions & 16 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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" }}
Expand Down
2 changes: 1 addition & 1 deletion xtask/src/commands/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;

Expand Down
2 changes: 1 addition & 1 deletion xtask/src/tools/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl CargoRunner {
version: Option<&RoverVersion>,
) -> Result<Utf8PathBuf> {
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",
Expand Down
69 changes: 51 additions & 18 deletions xtask/src/tools/git.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::convert::TryFrom;
use std::{env, fs};

use crate::tools::Runner;

Expand All @@ -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<Self> {
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<Self> {
pub(crate) fn try_new(verbose: bool) -> Result<Self> {
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<Utf8PathBuf> {
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<Utf8PathBuf> {
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)],
Expand Down

0 comments on commit 7531121

Please sign in to comment.