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..435663e7f6a 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 { 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(); + var dirsKeys = Object.keys(dirs); + console.log('dirs', 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,7 +129,7 @@ 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 if (fs.existsSync(combinedConfigPath)) { diff --git a/script/plugin_webpack_directories.js b/script/plugin_webpack_directories.js index 08d006e9c10..cecd3571879 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 = []; @@ -53,11 +66,15 @@ var getPluginDirs = stderr => var packageJsonDirs = stderr => pluginPath('package.json')(getPluginDirs(stderr)).map(path.dirname); +var packageJsonDirsObject = stderr => + 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 8e192d39bbc..f8de855e217 100644 --- a/webpack/jest.config.js +++ b/webpack/jest.config.js @@ -15,18 +15,12 @@ const vendorCorePackageJson = JSON.parse( fs.readFileSync(vendorCorePackageJsonPath, 'utf8') ); // const vendorDependencies = Object.keys(vendorCorePackageJson.dependencies); -// const customVendorDependencies = {}; -// vendorDependencies.forEach(dep => { +// const customVendorDependencies = vendorDependencies.map(dep => { // const module = foremanJsModules.find(m => m.name === dep); // if (module?.hasCustomPath) { -// console.log('module.path', module); -// customVendorDependencies[`^${dep}$`] = path.resolve( -// nodeModules, -// module.path -// ); -// } else { -// customVendorDependencies[`^${dep}$`] = path.resolve(nodeModules, dep); +// return { [`^${dep}$`]: module.path }; // } +// return { [`^${dep}$`]: path.resolve(nodeModules, dep) }; // // todo delete resolveNodeModule // }); // console.log(customVendorDependencies); 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