From f757e1de1df0374fab6e7917f935d7959623a2ec Mon Sep 17 00:00:00 2001 From: MariaAga Date: Wed, 17 Jul 2024 15:23:18 +0100 Subject: [PATCH] debugging --- .github/workflows/plugins_react_tests.yml | 23 ++++++++++++++++--- script/npm_test_plugin.js | 16 ++++++++----- script/plugin_webpack_directories.js | 28 +++++++++++++++++++---- webpack/jest.config.js | 4 ++-- webpack/theforeman-test.js | 2 +- 5 files changed, 57 insertions(+), 16 deletions(-) diff --git a/.github/workflows/plugins_react_tests.yml b/.github/workflows/plugins_react_tests.yml index ecd6304f947..551b3e9c710 100644 --- a/.github/workflows/plugins_react_tests.yml +++ b/.github/workflows/plugins_react_tests.yml @@ -48,11 +48,11 @@ jobs: uses: actions/setup-node@v4 with: node-version: ${{ matrix.node }} - # We could update the postinstall action for foreman to look for an environment variable for plugin webpack dirs - # before kicking off the ruby script to find them, this would eliminate the ruby dep and running `npm install` in plugins. - - uses: ruby/setup-ruby@v1 + - name: "Set up Ruby ${{ matrix.ruby }}" + uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} + bundler-cache: true - name: Checkout Foreman uses: actions/checkout@v4 with: @@ -68,12 +68,29 @@ jobs: with: repository: ${{ matrix.plugin }} path: ${{ github.workspace }}/projects/plugin + - name: store plugin name + run: echo "PLUGIN_NAME=$(echo ${{ matrix.plugin }} | awk -F'/' '{print $NF}')" >> "${GITHUB_ENV}" + - name: Set up plugin in Foreman + run: | + echo "gemspec name: '$PLUGIN_NAME', path: '${{ github.workspace }}/projects/plugin'" > "bundler.d/$PLUGIN_NAME.local.rb" + if [ -d $PLUGIN_NAME/gemfile.d ] ; then + cat $PLUGIN_NAME/gemfile.d/*.rb >> bundler.d/$PLUGIN_NAME.local.rb + fi + working-directory: ${{ github.workspace }}/projects/foreman - name: Generate ${{ matrix.plugin }} npm dependencies package-lock run: npm install --package-lock-only --no-audit --legacy-peer-deps working-directory: ${{ github.workspace }}/projects/plugin - name: Install ${{ matrix.plugin }} npm dependencies run: npm ci --no-audit --legacy-peer-deps working-directory: ${{ github.workspace }}/projects/plugin + - run: sudo apt-get update + - run: sudo apt-get -qq -y install build-essential libcurl4-openssl-dev zlib1g-dev libpq-dev libvirt-dev + - name: Install gems + run: bundle install + working-directory: ${{ github.workspace }}/projects/foreman + - name: Run plugin webpack dir to test + run: ./script/plugin_webpack_directories.rb + working-directory: ${{ github.workspace }}/projects/foreman - name: Run ${{ matrix.plugin }} tests run: npm run test:plugins $(echo ${{ matrix.plugin }} | awk -F'/' '{print $NF}') working-directory: ${{ github.workspace }}/projects/foreman diff --git a/script/npm_test_plugin.js b/script/npm_test_plugin.js index e9c9a58cbcf..050a5802d8c 100755 --- a/script/npm_test_plugin.js +++ b/script/npm_test_plugin.js @@ -13,7 +13,7 @@ var fs = require('fs'); var path = require('path'); var lodash = require('lodash'); var childProcess = require('child_process'); -var { packageJsonDirs } = require('./plugin_webpack_directories'); +var { packageJsonDirs, packageJsonDirsObject } = require('./plugin_webpack_directories'); const passedArgs = process.argv.slice(2); const coreConfigPath = path.resolve(__dirname, '../webpack/jest.config.js'); @@ -51,7 +51,10 @@ function runChildProcess(args, pluginPath) { }); } const runTests = async () => { - var dirs = packageJsonDirs(); + // var dirs = packageJsonDirs(); + var dirs = packageJsonDirsObject(); + console.log('dirs', dirs); + var dirsKeys = Object.keys(dirs); function pluginDefinesLint(pluginPath) { var packageHasNodeModules = fs.existsSync(`${pluginPath}/node_modules`); // skip gems var packageData = JSON.parse(fs.readFileSync(`${pluginPath}/package.json`)); @@ -61,7 +64,7 @@ const runTests = async () => { ); } if (passedArgs[0] && passedArgs[0][0] !== '-') { - dirs = dirs.filter(dir => dir.endsWith(passedArgs[0])); + dirsKeys = dirsKeys.filter(dir => dir.endsWith(passedArgs[0])); passedArgs.shift(); } function customizer(objValue, srcValue) { @@ -71,7 +74,8 @@ const runTests = async () => { return undefined; } // eslint-disable-next-line no-unused-vars - for (const pluginPath of dirs) { + for (const dirsKey of dirsKeys) { + const pluginPath = dirs[dirsKey]; if (pluginDefinesLint(pluginPath)) { const testSetupFiles = [ path.resolve(__dirname, '../webpack/global_test_setup.js'), @@ -125,9 +129,9 @@ const runTests = async () => { '--color', ...passedArgs, ]; - + console.log('args', args); // eslint-disable-next-line no-await-in-loop - await runChildProcess(args, pluginPath); // Run every plugin test in a separate process + // await runChildProcess(args, pluginPath); // Run every plugin test in a separate process if (fs.existsSync(combinedConfigPath)) { fs.unlinkSync(combinedConfigPath); } diff --git a/script/plugin_webpack_directories.js b/script/plugin_webpack_directories.js index 08d006e9c10..97566139aae 100644 --- a/script/plugin_webpack_directories.js +++ b/script/plugin_webpack_directories.js @@ -15,6 +15,19 @@ var sanitizeWebpackDirs = pluginDirs => { return splitDirs.length > 2 ? splitDirs[1] : pluginDirs; }; +var pluginPathObject = file => pluginsObj => { + var paths = {}; + Object.keys(pluginsObj.plugins).forEach(entryKey => { + if (!entryKey.includes(':')) { + const pluginPath = pluginsObj.plugins[entryKey].root; + if (fs.existsSync(path.join(pluginPath, file))) { + paths[entryKey] = pluginPath; + } + } + }); + return paths; +}; + // Get paths that have a specific file or folder var pluginPath = file => pluginsObj => { var paths = []; @@ -47,17 +60,24 @@ var webpackedDirs = stderr => { }); }; -var getPluginDirs = stderr => - JSON.parse(sanitizeWebpackDirs(webpackedDirs(stderr))); +var getPluginDirs = stderr => { + return JSON.parse(sanitizeWebpackDirs(webpackedDirs(stderr))); +}; + +var packageJsonDirs = stderr => { + return pluginPath('package.json')(getPluginDirs(stderr)).map(path.dirname); +}; -var packageJsonDirs = stderr => - pluginPath('package.json')(getPluginDirs(stderr)).map(path.dirname); +var packageJsonDirsObject = stderr => { + return pluginPathObject('package.json')(getPluginDirs(stderr)); +}; module.exports = { getPluginDirs, pluginNodeModules: pluginPath('node_modules'), aliasPlugins, packageJsonDirs, + packageJsonDirsObject, sanitizeWebpackDirs, pluginPath, }; diff --git a/webpack/jest.config.js b/webpack/jest.config.js index 00a6a8b59a7..0bfb2a39fe5 100644 --- a/webpack/jest.config.js +++ b/webpack/jest.config.js @@ -1,6 +1,7 @@ /* eslint-disable spellcheck/spell-checker */ const fs = require('fs'); const path = require('path'); +const { modules: foremanJsModules } = require('@theforeman/vendor-core'); const nodeModules = path.resolve(__dirname, '..', 'node_modules'); const packageJsonPath = path.resolve(__dirname, '..', 'package.json'); @@ -13,7 +14,6 @@ const vendorCorePackageJsonPath = path.resolve( const vendorCorePackageJson = JSON.parse( fs.readFileSync(vendorCorePackageJsonPath, 'utf8') ); -const { modules: foremanJsModules } = require('@theforeman/vendor-core'); const vendorDependencies = Object.keys(vendorCorePackageJson.dependencies); const customVendorDependencies = vendorDependencies.map(dep => { const module = foremanJsModules.find(m => m.name === dep); @@ -23,7 +23,7 @@ const customVendorDependencies = vendorDependencies.map(dep => { return { [`^${dep}$`]: path.resolve(nodeModules, dep) }; // todo delete resolveNodeModule }); -console.log(customVendorDependencies); +// console.log(customVendorDependencies); const dependencies = { ...packageJson.dependencies, ...packageJson.devDependencies, diff --git a/webpack/theforeman-test.js b/webpack/theforeman-test.js index 84f574bf399..8d176a13d6e 100644 --- a/webpack/theforeman-test.js +++ b/webpack/theforeman-test.js @@ -1,2 +1,2 @@ export * from './theforeman_test_dependencies'; -// todo: deprecate \ No newline at end of file +// todo: deprecate