-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): atomizer with nx:atomizer executor -- WIP
- Loading branch information
Showing
16 changed files
with
192 additions
and
294 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "atomizer", | ||
"implementation": "/packages/nx/src/executors/atomizer/atomizer.impl.ts", | ||
"schema": { | ||
"version": 2, | ||
"title": "Atomizer", | ||
"description": "An executor that is used as the root task for atomized tasks. Ensures it's being run in distribution and otherwise does nothing.", | ||
"type": "object", | ||
"cli": "nx", | ||
"outputCapture": "pipe", | ||
"properties": {}, | ||
"additionalProperties": true, | ||
"presets": [] | ||
}, | ||
"description": "An executor that is used as the root task for atomized tasks. Ensures it's being run in distribution and otherwise does nothing.", | ||
"aliases": [], | ||
"hidden": false, | ||
"path": "/packages/nx/src/executors/atomizer/schema.json", | ||
"type": "executor" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import '../../internal-testing-utils/mock-fs'; | ||
|
||
import { vol } from 'memfs'; | ||
import { ExecutorContext } from '../../config/misc-interfaces'; | ||
import atomize from './atomizer.impl'; | ||
import * as fs from 'fs'; | ||
import { join } from 'path'; | ||
|
||
const context = { | ||
root: '/root', | ||
projectName: 'proj', | ||
targetName: 'e2e-ci', | ||
} as ExecutorContext; | ||
|
||
describe('nx:atomizer', () => { | ||
let mockProcessExit: jest.SpyInstance; | ||
let env: NodeJS.ProcessEnv; | ||
|
||
beforeEach(() => { | ||
env = process.env; | ||
process.env = {}; | ||
|
||
jest.mock('fs'); | ||
}); | ||
|
||
afterEach(() => { | ||
process.env = env; | ||
vol.reset(); | ||
}); | ||
|
||
it('should fail if atomized task is present but no DTE', async () => { | ||
const result = await atomize({}, context); | ||
expect(result).toEqual(expect.objectContaining({ success: false })); | ||
}); | ||
|
||
it('should do nothing if atomized task is present in Nx Agents', async () => { | ||
process.env['NX_AGENT_NAME'] = '123'; | ||
const result = await atomize({}, context); | ||
expect(result).toEqual(expect.objectContaining({ success: true })); | ||
}); | ||
|
||
it('should do nothing if atomized task is present in DTE', async () => { | ||
process.env['NX_CLOUD_DISTRIBUTED_EXECUTION_ID'] = '123'; | ||
const result = await atomize({}, context); | ||
expect(result).toEqual(expect.objectContaining({ success: true })); | ||
}); | ||
|
||
it('should do nothing if atomized task is present and dte marker file exists', async () => { | ||
vol.fromJSON( | ||
{ | ||
'node_modules/.cache/nx/NX_CLOUD_DISTRIBUTED_EXECUTION': 'true', | ||
}, | ||
context.root | ||
); | ||
|
||
const result = await atomize({}, context); | ||
expect(result).toEqual(expect.objectContaining({ success: true })); | ||
}); | ||
|
||
it('should do nothing if atomized task is present and dte marker file exists in NX_CACHE_DIRECTORY', async () => { | ||
const cacheDirectory = join('node_modules', 'my-cache-dir'); | ||
process.env['NX_CACHE_DIRECTORY'] = cacheDirectory; | ||
|
||
vol.fromJSON( | ||
{ | ||
'node_modules/my-cache-dir/NX_CLOUD_DISTRIBUTED_EXECUTION': 'true', | ||
}, | ||
context.root | ||
); | ||
|
||
const result = await atomize({}, context); | ||
expect(result).toEqual(expect.objectContaining({ success: true })); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { join } from 'path'; | ||
import { ExecutorContext } from '../../config/misc-interfaces'; | ||
import { existsSync, readFileSync } from 'fs'; | ||
import { output } from '../../utils/output'; | ||
import { serializeTarget } from '../../utils/serialize-target'; | ||
|
||
export default async function (_: any, context: ExecutorContext) { | ||
if (isInDTE(context.root)) { | ||
return { success: true }; | ||
} else { | ||
output.error({ | ||
title: `The ${serializeTarget( | ||
context.projectName, | ||
context.targetName, | ||
context.configurationName | ||
)} task uses the atomizer and should only be run with Nx Cloud distribution.`, | ||
bodyLines: [ | ||
'Learn more at https://nx.dev/ci/features/split-e2e-tasks#use-atomizer-only-with-nx-cloud-distribution', | ||
], | ||
}); | ||
return { success: false }; | ||
} | ||
} | ||
|
||
function isInDTE(workspaceRoot: string): boolean { | ||
if ( | ||
process.env['NX_CLOUD_DISTRIBUTED_EXECUTION_ID'] || | ||
process.env['NX_AGENT_NAME'] | ||
) { | ||
return true; | ||
} | ||
|
||
// checks for DTE marker file - needed so we can check for DTE on the main nx job | ||
const nxCacheDirectory = process.env.NX_CACHE_DIRECTORY | ||
? [process.env['NX_CACHE_DIRECTORY']] | ||
: ['node_modules', '.cache', 'nx']; | ||
const dir = join(workspaceRoot, ...nxCacheDirectory); | ||
const dteMarker = join(dir, 'NX_CLOUD_DISTRIBUTED_EXECUTION'); | ||
|
||
if (existsSync(dteMarker) && readFileSync(dteMarker, 'utf-8') === 'true') { | ||
return true; | ||
} | ||
|
||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"version": 2, | ||
"title": "Atomizer", | ||
"description": "An executor that is used as the root task for atomized tasks. Ensures it's being run in distribution and otherwise does nothing.", | ||
"type": "object", | ||
"cli": "nx", | ||
"outputCapture": "pipe", | ||
"properties": {}, | ||
"additionalProperties": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.