Skip to content

Commit 5179111

Browse files
committed
log the target
1 parent c0aa61b commit 5179111

File tree

5 files changed

+173
-1
lines changed

5 files changed

+173
-1
lines changed

.github/actions/build/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ runs:
6868
COMMERCIAL_REPO_PASSWORD: ${{ inputs.commercial-repository-password }}
6969
COMMERCIAL_REPO_USERNAME: ${{ inputs.commercial-repository-username }}
7070
COMMERCIAL_SNAPSHOT_REPO_URL: ${{ inputs.commercial-snapshot-repository-url }}
71-
run: NX_BATCH_MODE=true NX_CLOUD_DEREFERENCE_SYMLINKS=true NX_VERBOSE_LOGGING=true NX_PERF_LOGGING=true NX_CLOUD_NO_TIMEOUTS=true NX_CLOUD_VERBOSE_LOGGING=true npx nx run-many -t build-ci --parallel=8 --batch --outputStyle=stream
71+
run: NX_BATCH_MODE=true NX_CLOUD_DEREFERENCE_SYMLINKS=true NX_VERBOSE_LOGGING=true NX_PERF_LOGGING=true NX_CLOUD_NO_TIMEOUTS=true NX_CLOUD_VERBOSE_LOGGING=true npx nx run-many -t build-ci --parallel=32 --batch --outputStyle=stream
7272
# - name: Publish
7373
# id: publish
7474
# if: ${{ inputs.publish == 'true' }}

.github/workflows/build-pull-request.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ jobs:
99
steps:
1010
- name: Check Out Code
1111
uses: actions/checkout@v4
12+
- name: Remove gradle cache folder
13+
run: rm -rf ~/.gradle/caches
1214
- name: Use Node.js
1315
uses: actions/setup-node@v4
1416
with:
@@ -17,6 +19,10 @@ jobs:
1719
cache: npm
1820
- run: npm install
1921

22+
# Reset NX cache and remove gradle cache folder for clean build
23+
- name: Reset NX cache
24+
run: npx nx reset
25+
2026
# This enables task distribution via Nx Cloud
2127
# Run this command as early as possible, before dependencies are installed
2228
# Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun

nx.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
]
2222
},
2323
"targetDefaults": {
24+
"ci--*": {
25+
"executor": "@nx/gradle:gradle",
26+
"options": {
27+
"excludeDependsOn": false
28+
}
29+
},
2430
"homebrewFormula": {
2531
"executor": "@nx/gradle:gradle",
2632
"options": {

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"name": "spring-boot",
3+
"scripts": {
4+
"postinstall": "node scripts/patch-nx-executor-utils.js",
5+
"postci": "node scripts/patch-nx-executor-utils.js"
6+
},
37
"dependencies": {
48
"@nx/gradle": "21.3.0-beta.6",
59
"nx": "21.3.0-beta.6"

scripts/patch-nx-executor-utils.js

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
6+
const executorUtilsPath = path.join(__dirname, '../node_modules/nx/src/command-line/run/executor-utils.js');
7+
const taskRunnerUtilsPath = path.join(__dirname, '../node_modules/nx/src/tasks-runner/utils.js');
8+
9+
// Enhanced parseExecutor function with comprehensive logging
10+
const patchedParseExecutor = `function parseExecutor(executorString) {
11+
console.log('DEBUG: parseExecutor called with:', executorString);
12+
13+
// Capture call stack to identify which target is causing the issue
14+
const stack = new Error().stack;
15+
const caller = stack.split('\\n')[2]; // Get the calling function
16+
17+
if (!executorString) {
18+
console.error('ERROR: parseExecutor received undefined or null executorString');
19+
console.error('ERROR: Call stack:', stack);
20+
console.error('ERROR: Caller:', caller);
21+
22+
// Look for task object in arguments
23+
const args = Array.from(arguments);
24+
console.error('ERROR: Function arguments:', args);
25+
26+
throw new Error(\`parseExecutor received undefined or null executorString. Caller: \${caller}\`);
27+
}
28+
29+
if (typeof executorString !== 'string') {
30+
console.error('ERROR: parseExecutor received non-string executorString:', typeof executorString, executorString);
31+
console.error('ERROR: Call stack:', stack);
32+
console.error('ERROR: Caller:', caller);
33+
34+
throw new Error(\`parseExecutor received non-string executorString: \${typeof executorString}. Caller: \${caller}\`);
35+
}
36+
37+
const result = executorString.split(':');
38+
console.log('DEBUG: parseExecutor result:', result);
39+
return result;
40+
}`;
41+
42+
// Enhanced getExecutorForTask with better undefined handling
43+
const enhancedGetExecutorForTask = `function getExecutorForTask(task, projectGraph) {
44+
console.log('DEBUG: getExecutorForTask - task:', task.id);
45+
46+
const executor = getExecutorNameForTask(task, projectGraph);
47+
console.log('DEBUG: getExecutorForTask - executor resolved:', executor, 'for task:', task.id);
48+
49+
// Check for undefined, null, or empty string
50+
if (executor === undefined || executor === null || executor === '') {
51+
console.error('ERROR: getExecutorForTask - No executor found for task:', task.id);
52+
console.error('ERROR: Task details:', JSON.stringify(task, null, 2));
53+
console.error('ERROR: Project configuration:', JSON.stringify(projectGraph.nodes[task.target.project]?.data?.targets?.[task.target.target], null, 2));
54+
console.error('ERROR: Available targets for project:',
55+
projectGraph.nodes[task.target.project]?.data?.targets ?
56+
Object.keys(projectGraph.nodes[task.target.project].data.targets) :
57+
'No targets found');
58+
throw new Error(\`No executor found for task: \${task.id}\`);
59+
}
60+
61+
// Log the task details before calling parseExecutor to help identify which task causes the issue
62+
console.log('DEBUG: About to call parseExecutor for task:', task.id, 'with executor:', executor);
63+
console.log('DEBUG: Task target:', JSON.stringify(task.target, null, 2));
64+
65+
try {
66+
const [nodeModule, executorName] = (0, executor_utils_1.parseExecutor)(executor);
67+
return (0, executor_utils_1.getExecutorInformation)(nodeModule, executorName, workspace_root_1.workspaceRoot, (0, project_graph_1.readProjectsConfigurationFromProjectGraph)(projectGraph).projects);
68+
} catch (error) {
69+
console.error('ERROR: parseExecutor failed for task:', task.id);
70+
console.error('ERROR: Task details:', JSON.stringify(task, null, 2));
71+
console.error('ERROR: Executor value:', executor);
72+
console.error('ERROR: Original error:', error.message);
73+
throw error;
74+
}
75+
}`;
76+
77+
function patchExecutorUtils() {
78+
try {
79+
// Patch executor-utils.js
80+
if (!fs.existsSync(executorUtilsPath)) {
81+
console.error('ERROR: executor-utils.js not found at:', executorUtilsPath);
82+
process.exit(1);
83+
}
84+
85+
const originalExecutorUtilsContent = fs.readFileSync(executorUtilsPath, 'utf8');
86+
87+
// Check if already patched
88+
if (!originalExecutorUtilsContent.includes('DEBUG: parseExecutor called with:')) {
89+
// Find the parseExecutor function and replace it
90+
const parseExecutorRegex = /function parseExecutor\(executorString\) \{[^}]*\}/;
91+
92+
if (!parseExecutorRegex.test(originalExecutorUtilsContent)) {
93+
console.error('ERROR: Could not find parseExecutor function in executor-utils.js');
94+
process.exit(1);
95+
}
96+
97+
const patchedExecutorUtilsContent = originalExecutorUtilsContent.replace(parseExecutorRegex, patchedParseExecutor);
98+
99+
// Create backup
100+
const backupPath = executorUtilsPath + '.backup';
101+
if (!fs.existsSync(backupPath)) {
102+
fs.writeFileSync(backupPath, originalExecutorUtilsContent);
103+
console.log('INFO: Created backup at:', backupPath);
104+
}
105+
106+
// Write patched version
107+
fs.writeFileSync(executorUtilsPath, patchedExecutorUtilsContent);
108+
console.log('SUCCESS: Patched executor-utils.js with enhanced logging');
109+
} else {
110+
console.log('INFO: executor-utils.js already patched');
111+
}
112+
113+
// Enhanced patch for task-runner utils.js
114+
if (!fs.existsSync(taskRunnerUtilsPath)) {
115+
console.error('ERROR: task-runner utils.js not found at:', taskRunnerUtilsPath);
116+
process.exit(1);
117+
}
118+
119+
const taskRunnerUtilsContent = fs.readFileSync(taskRunnerUtilsPath, 'utf8');
120+
121+
// Check if we need to update getExecutorForTask with enhanced logging
122+
if (!taskRunnerUtilsContent.includes('DEBUG: getExecutorForTask - executor resolved:')) {
123+
// Find and replace the getExecutorForTask function with enhanced version
124+
const getExecutorForTaskRegex = /function getExecutorForTask\(task, projectGraph\) \{[\s\S]*?\}(?=\s*exports\.getExecutorForTask|\s*function|\s*$)/;
125+
126+
if (getExecutorForTaskRegex.test(taskRunnerUtilsContent)) {
127+
const enhancedTaskRunnerUtilsContent = taskRunnerUtilsContent.replace(getExecutorForTaskRegex, enhancedGetExecutorForTask);
128+
129+
// Create backup
130+
const taskRunnerBackupPath = taskRunnerUtilsPath + '.backup';
131+
if (!fs.existsSync(taskRunnerBackupPath)) {
132+
fs.writeFileSync(taskRunnerBackupPath, taskRunnerUtilsContent);
133+
console.log('INFO: Created backup at:', taskRunnerBackupPath);
134+
}
135+
136+
// Write enhanced version
137+
fs.writeFileSync(taskRunnerUtilsPath, enhancedTaskRunnerUtilsContent);
138+
console.log('SUCCESS: Enhanced task-runner utils.js with better undefined handling');
139+
} else {
140+
console.log('INFO: Could not find getExecutorForTask function to enhance');
141+
}
142+
} else {
143+
console.log('INFO: task-runner utils.js already has enhanced logging');
144+
}
145+
146+
} catch (error) {
147+
console.error('ERROR: Failed to patch NX files:', error.message);
148+
process.exit(1);
149+
}
150+
}
151+
152+
if (require.main === module) {
153+
patchExecutorUtils();
154+
}
155+
156+
module.exports = { patchExecutorUtils };

0 commit comments

Comments
 (0)