Skip to content

Commit abc27a8

Browse files
authored
Merge pull request #209 from data-douser/cds-compile-retry
CDS extractor : Implement retry for CDS compilation tasks
2 parents f31e5c7 + 3b58942 commit abc27a8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+6141
-3269
lines changed

.github/workflows/run-codeql-unit-tests-javascript.yml

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -77,48 +77,29 @@ jobs:
7777
run: |
7878
qlt query run install-packs
7979
80-
- name: Ensure presence of cds shell command
81-
run: |
82-
if ! command -v cds &> /dev/null
83-
then
84-
## Workaround for https://github.tools.sap/cap/issues/issues/17840
85-
npm install -g @sap/[email protected]
86-
fi
80+
- name: Setup Node.js for CDS compilation
81+
uses: actions/setup-node@v4
82+
with:
83+
node-version: '18'
84+
cache: 'npm'
85+
cache-dependency-path: 'extractors/cds/tools/package-lock.json'
8786

88-
# Compile .cds files to .cds.json files.
87+
- name: Verify Node.js and npm tools
88+
run: |
89+
echo "Node.js version: $(node --version)"
90+
echo "npm version: $(npm --version)"
91+
echo "npx version: $(npx --version)"
92+
# Verify npx can access @sap/cds-dk without installing globally
93+
echo "Testing npx access to @sap/cds-dk..."
94+
npx --yes --package @sap/cds-dk@latest cds --version || echo "CDS will be installed per-project as needed"
95+
96+
# Compile .cds files to .cds.json files using the dedicated test script
8997
- name: Compile CAP CDS files
9098
run: |
91-
for test_dir in $(find . -type f -name '*.expected' -exec dirname {} \;);
92-
do
93-
# The CDS compiler produces locations relative to the working directory
94-
# so we switch to the test directory before running the compiler.
95-
pushd $test_dir
96-
for cds_file in $(find . -type f \( -iname '*.cds' \) -print)
97-
do
98-
echo "I am compiling $cds_file"
99-
_out_path="${cds_file}.json"
100-
cds compile $cds_file \
101-
--locations \
102-
--to json \
103-
--dest "$_out_path" \
104-
2> "$cds_file.err"
105-
# Check if the output is a regular file or a (sub)directory, where
106-
# files generated in an output directory will need to have the file
107-
# extension changed from '.json' to '.cds.json', but we don't need
108-
# to rename anything if the cds compiler just generated a single
109-
# '.cds.json' file.
110-
if [ -d "$_out_path" ]
111-
then
112-
for json_file in $(find "$_out_path" -type f \( -iname '*.json' \) -print)
113-
do
114-
_new_path="${json_file%.json}.cds.json"
115-
echo "Renaming CDS compiler generated JSON file $json_file to $_new_path"
116-
mv "$json_file" "$_new_path"
117-
done
118-
fi
119-
done
120-
popd
121-
done
99+
# Use the dedicated CDS compilation script that includes proper version resolution
100+
# This script follows the same logic as the CDS extractor's resolveCdsVersions function
101+
chmod +x extractors/cds/tools/test/cds-compilation-for-actions.test.sh
102+
./extractors/cds/tools/test/cds-compilation-for-actions.test.sh
122103
123104
- name: Run test suites
124105
id: run-test-suites

extractors/cds/tools/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ node dist/cds-extractor.js /path/to/source/root
6363

6464
## Development
6565

66+
> **⚠️ IMPORTANT NOTE**: Any changes to the CDS extractor's compilation task behavior (including how and where `cds compile` commands are executed, project detection logic, or output file generation patterns) **MUST** be reflected in the `extractors/cds/tools/test/cds-compilation-for-actions.test.sh` script. The `.github/workflows/run-codeql-unit-tests-javascript.yml` workflow executes this script during the "Compile CAP CDS files" step to simulate the CDS extractor's compilation process for unit tests. If the script and extractor implementations diverge, the `CodeQL - Run Unit Tests (javascript)` workflow will fail on PRs, causing status check failures. Always review and update the test script when modifying compilation behavior to maintain consistency between local testing and CI/CD environments.
67+
6668
### Project Structure
6769

6870
```text

extractors/cds/tools/cds-extractor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
logPerformanceTrackingStop,
1818
setSourceRootDirectory,
1919
} from './src/logging';
20-
import { installDependencies } from './src/packageManager';
20+
import { cacheInstallDependencies } from './src/packageManager';
2121
import { validateArguments } from './src/utils';
2222

2323
// Validate the script arguments.
@@ -99,7 +99,7 @@ try {
9999
for (const [projectDir, project] of dependencyGraph.projects.entries()) {
100100
cdsExtractorLog(
101101
'info',
102-
`Project: ${projectDir}, Status: ${project.status}, CDS files: ${project.cdsFiles.length}, Compilations to run: ${project.cdsFilesToCompile.length}`,
102+
`Project: ${projectDir}, Status: ${project.status}, CDS files: ${project.cdsFiles.length}, Compilation targets: ${project.compilationTargets.length}`,
103103
);
104104
}
105105
} else {
@@ -151,7 +151,7 @@ try {
151151
}
152152

153153
logPerformanceTrackingStart('Dependency Installation');
154-
const projectCacheDirMap = installDependencies(dependencyGraph, sourceRoot, codeqlExePath);
154+
const projectCacheDirMap = cacheInstallDependencies(dependencyGraph, sourceRoot, codeqlExePath);
155155
logPerformanceTrackingStop('Dependency Installation');
156156

157157
// Check if dependency installation resulted in any usable project mappings

0 commit comments

Comments
 (0)