Skip to content

Commit

Permalink
fix(core): do not depend on ci info crate (#28850)
Browse files Browse the repository at this point in the history
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

The way VS Code / Nx Console starts the daemon makes the ci info rust
crate believe that the daemon process is running in CI. This starts the
database using the unix dotfile... which causes issues

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

The ci info rust crate is not used, we have our own logic which is
identical to the JS logic we have.

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
  • Loading branch information
FrozenPandaz authored Nov 8, 2024
1 parent 158d343 commit 7f39dc1
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 44 deletions.
39 changes: 0 additions & 39 deletions Cargo.lock

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

23 changes: 20 additions & 3 deletions e2e/eslint/src/linter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,17 @@ describe('Linter', () => {
const newRuleName = 'e2e-test-rule-name';
runCLI(`generate @nx/eslint:workspace-rule ${newRuleName}`);

// TODO(@AgentEnder): This reset gets rid of a lockfile changed error... we should fix this in another way
runCLI(`reset`, {
env: { CI: 'false' },
});

// Ensure that the unit tests for the new rule are runnable
expect(() => runCLI(`test eslint-rules`)).not.toThrow();
expect(() =>
runCLI(`test eslint-rules`, {
env: { CI: 'false' },
})
).not.toThrow();

// Update the rule for the e2e test so that we can assert that it produces the expected lint failure when used
const knownLintErrorMessage = 'e2e test known error message';
Expand Down Expand Up @@ -603,8 +612,16 @@ describe('Linter', () => {
);

// validate that the new projects are linted successfully
expect(() => runCLI(`lint ${reactLib}`)).not.toThrow();
expect(() => runCLI(`lint ${jsLib}`)).not.toThrow();
expect(() =>
runCLI(`lint ${reactLib}`, {
env: { CI: 'false' },
})
).not.toThrow();
expect(() =>
runCLI(`lint ${jsLib}`, {
env: { CI: 'false' },
})
).not.toThrow();
});
});
});
Expand Down
1 change: 0 additions & 1 deletion packages/nx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ strip = "none"

[dependencies]
anyhow = "1.0.71"
ci_info = "0.14.14"
colored = "2"
crossbeam-channel = '0.5'
dashmap = { version = "5.5.3", features = ["rayon"] }
Expand Down
3 changes: 2 additions & 1 deletion packages/nx/src/native/db/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use rusqlite::{Connection, OpenFlags};
use std::fs::{remove_file, File};
use std::path::{Path, PathBuf};
use tracing::{debug, trace};
use crate::native::utils::ci::is_ci;

pub(super) struct LockFile {
file: File,
Expand Down Expand Up @@ -99,7 +100,7 @@ fn create_metadata_table(c: &mut NxDbConnection, nx_version: &str) -> anyhow::Re
}

fn open_database_connection(db_path: &Path) -> anyhow::Result<NxDbConnection> {
let conn = if cfg!(target_family = "unix") && ci_info::is_ci() {
let conn = if cfg!(target_family = "unix") && is_ci() {
trace!("Opening connection with unix-dotfile");
Connection::open_with_flags_and_vfs(
db_path,
Expand Down
19 changes: 19 additions & 0 deletions packages/nx/src/native/utils/ci.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use std::env;

pub fn is_ci() -> bool {
env::var("CI").is_ok_and(|s| s != "false")
|| env::var("TF_BUILD").is_ok_and(|s| s == "true")
|| env::var("GITHUB_ACTIONS").is_ok_and(|s| s == "true")
|| env::var("BUILDKITE").is_ok_and(|s| s == "true")
|| env::var("CIRCLECI").is_ok_and(|s| s == "true")
|| env::var("CIRRUS_CI").is_ok_and(|s| s == "true")
|| env::var("TRAVIS").is_ok_and(|s| s == "true")
|| env::var("bamboo.buildKey").is_ok()
|| env::var("bamboo_buildKey").is_ok()
|| env::var("CODEBUILD_BUILD_ID").is_ok()
|| env::var("GITLAB_CI").is_ok()
|| env::var("HEROKU_TEST_RUN_ID").is_ok()
|| env::var("BUILD_ID").is_ok()
|| env::var("BUILD_BUILDID").is_ok()
|| env::var("TEAMCITY_VERSION").is_ok()
}
1 change: 1 addition & 0 deletions packages/nx/src/native/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ pub use normalize_trait::Normalize;
#[cfg_attr(not(target_arch = "wasm32"), path = "atomics/default.rs")]
#[cfg_attr(target_arch = "wasm32", path = "atomics/wasm.rs")]
pub mod atomics;
pub mod ci;

pub use atomics::*;

0 comments on commit 7f39dc1

Please sign in to comment.