Skip to content

Commit

Permalink
debug add nvm and rearrange repotests
Browse files Browse the repository at this point in the history
Signed-off-by: Aryan Rajoria <[email protected]>
  • Loading branch information
aryan-rajoria committed Sep 6, 2024
1 parent 432b35b commit 5e4c0eb
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 32 deletions.
40 changes: 20 additions & 20 deletions .github/workflows/repotests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,26 @@ jobs:
run: |
curl -s "https://get.sdkman.io" | bash
if: runner.os != 'Windows'
- name: repotests react-app
run: |
FETCH_LICENSE=false bin/cdxgen.js -p -t nodejs8 repotests/react-app -o bomresults/react-app.json
node bin/evinse.js -i bomresults/react-app.json -o bomresults/react-app.evinse.json -l javascript --with-data-flow -p repotests/react-app
shell: bash
- name: repotests basic-ftp
run: |
FETCH_LICENSE=false bin/cdxgen.js -p -t nodejs10 repotests/basic-ftp -o bomresults/basic-ftp.json
node bin/evinse.js -i bomresults/basic-ftp.json -o bomresults/basic-ftp.evinse.json -l javascript --with-data-flow -p repotests/basic-ftp
shell: bash
- name: repotests llama-node
run: |
FETCH_LICENSE=false bin/cdxgen.js -p -t nodejs16 repotests/llama-node -o bomresults/llama-node.json
node bin/evinse.js -i bomresults/llama-node.json -o bomresults/llama-node.evinse.json -l javascript --with-data-flow -p repotests/llama-node
shell: bash
- name: repotests RSSHub
run: |
FETCH_LICENSE=false bin/cdxgen.js -p -t nodejs22 repotests/RSSHub -o bomresults/RSSHub.json
node bin/evinse.js -i bomresults/RSSHub.json -o bomresults/RSSHub.evinse.json -l javascript --with-data-flow -p repotests/RSSHub
shell: bash
- name: repotests java-sec-code
run: |
bin/cdxgen.js -p -t java repotests/java-sec-code -o bomresults/bom-java-sec-code-1.json --include-formulation --include-crypto
Expand Down Expand Up @@ -309,26 +329,6 @@ jobs:
FETCH_LICENSE=false bin/cdxgen.js -p -t js repotests/meetingsdk-vuejs-sample -o bomresults/bom-vue.json
node bin/evinse.js -i bomresults/bom-vue.json -o bomresults/bom-vue.evinse.json -l javascript --with-data-flow -p repotests/meetingsdk-vuejs-sample
shell: bash
- name: repotests react-app
run: |
FETCH_LICENSE=false bin/cdxgen.js -p -t nodejs8 repotests/react-app -o bomresults/react-app.json
node bin/evinse.js -i bomresults/react-app.json -o bomresults/react-app.evinse.json -l javascript --with-data-flow -p repotests/react-app
shell: bash
- name: repotests basic-ftp
run: |
FETCH_LICENSE=false bin/cdxgen.js -p -t nodejs10 repotests/basic-ftp -o bomresults/basic-ftp.json
node bin/evinse.js -i bomresults/basic-ftp.json -o bomresults/basic-ftp.evinse.json -l javascript --with-data-flow -p repotests/basic-ftp
shell: bash
- name: repotests llama-node
run: |
FETCH_LICENSE=false bin/cdxgen.js -p -t nodejs16 repotests/llama-node -o bomresults/llama-node.json
node bin/evinse.js -i bomresults/llama-node.json -o bomresults/llama-node.evinse.json -l javascript --with-data-flow -p repotests/llama-node
shell: bash
- name: repotests RSSHub
run: |
FETCH_LICENSE=false bin/cdxgen.js -p -t nodejs22 repotests/RSSHub -o bomresults/RSSHub.json
node bin/evinse.js -i bomresults/RSSHub.json -o bomresults/RSSHub.evinse.json -l javascript --with-data-flow -p repotests/RSSHub
shell: bash
- name: repotests sveltejs-examples
run: |
CDXGEN_DEBUG_MODE=debug ASTGEN_IGNORE_DIRS="" FETCH_LICENSE=false bin/cdxgen.js -p -t js repotests/sveltejs-examples -o bomresults/bom-svelte.json
Expand Down
63 changes: 51 additions & 12 deletions pregen.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { spawnSync } from "node:child_process";
import { spawn, spawnSync } from "node:child_process";
import { mkdtempSync, readdirSync } from "node:fs";
import { arch, platform, tmpdir } from "node:os";
import { delimiter, join } from "node:path";
Expand Down Expand Up @@ -119,10 +119,12 @@ export function prepareNodeEnv(filePath, options) {
// custom logic to find nvmNodePath
let nvmNodePath;
const possibleNodeDir = join(process.env.NVM_DIR, "versions", "node");

// debug in circleci
console.log(readdirSync(process.env.NVM_DIR), { withFileTypes: true })
console.log(createDirectoryTree(process.env.NVM_DIR, 3, 0))

if (!tryLoadNvmAndInstallTool(nodeVersion)) {
console.log(
`Could not install Nodejs${nodeVersion}. There is a problem with loading nvm from ${process.env.NVM_DIR}`,
);
}

const nodeVersionArray = readdirSync(possibleNodeDir, {
withFileTypes: true,
Expand Down Expand Up @@ -159,6 +161,39 @@ export function prepareNodeEnv(filePath, options) {
}
}

/**
* If NVM_DIR is in path, however nvm command is not loaded.
* it is possible that required nodeVersion is not installed.
* This function loads nvm and install the nodeVersion
*
* @param {String} nodeVersion required version number
*
* @returns {Boolean} true if successful, otherwise false
*/
export function tryLoadNvmAndInstallTool(nodeVersion) {
const NVM_DIR = process.env.NVM_DIR;

const command = `
if [ -f ${NVM_DIR}/nvm.sh ]; then
. ${NVM_DIR}/nvm.sh
nvm install ${nodeVersion}
else
echo "NVM script not found at ${NVM_DIR}/nvm.sh"
exit 1
fi
`;

const spawnedShell = spawnSync(process.env.SHELL || "bash", ["-c", command], {
encoding: "utf-8",
shell: process.env.SHELL || true,
});
if (spawnedShell.status === 0) {
return true;
}

return false;
}

/**
* This method installs and create package-lock.json
*
Expand Down Expand Up @@ -206,10 +241,10 @@ export function doNpmInstall(filePath, nvmNodePath) {

/**
* Function to retrieve directories in nvm
* @param {*} directoryPath
* @param {*} maxDepth
* @param {*} currentDepth
* @returns
* @param {*} directoryPath
* @param {*} maxDepth
* @param {*} currentDepth
* @returns
*/
function createDirectoryTree(directoryPath, maxDepth = 3, currentDepth = 0) {
if (currentDepth > maxDepth) {
Expand All @@ -220,10 +255,14 @@ function createDirectoryTree(directoryPath, maxDepth = 3, currentDepth = 0) {
const entries = readdirSync(directoryPath, { withFileTypes: true });
const tree = {};

entries.forEach(entry => {
entries.forEach((entry) => {
if (entry.isDirectory()) {
const subDirPath = join(directoryPath, entry.name);
tree[entry.name] = createDirectoryTree(subDirPath, maxDepth, currentDepth + 1);
tree[entry.name] = createDirectoryTree(
subDirPath,
maxDepth,
currentDepth + 1,
);
}
});

Expand All @@ -232,4 +271,4 @@ function createDirectoryTree(directoryPath, maxDepth = 3, currentDepth = 0) {
console.error(`Error reading directory ${directoryPath}:`, err);
return null;
}
}
}

0 comments on commit 5e4c0eb

Please sign in to comment.