Skip to content

Commit

Permalink
debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
MariaAga committed Jul 17, 2024
1 parent 7956a2a commit f757e1d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 16 deletions.
23 changes: 20 additions & 3 deletions .github/workflows/plugins_react_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
16 changes: 10 additions & 6 deletions script/npm_test_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Check failure on line 16 in script/npm_test_plugin.js

View workflow job for this annotation

GitHub Actions / test (13, 3.0, 14)

Replace `·packageJsonDirs,·packageJsonDirsObject·` with `⏎··packageJsonDirs,⏎··packageJsonDirsObject,⏎`

Check failure on line 16 in script/npm_test_plugin.js

View workflow job for this annotation

GitHub Actions / test (13, 3.0, 14)

'packageJsonDirs' is assigned a value but never used

Check failure on line 16 in script/npm_test_plugin.js

View workflow job for this annotation

GitHub Actions / test (13, 3.0, 18)

Replace `·packageJsonDirs,·packageJsonDirsObject·` with `⏎··packageJsonDirs,⏎··packageJsonDirsObject,⏎`

Check failure on line 16 in script/npm_test_plugin.js

View workflow job for this annotation

GitHub Actions / test (13, 3.0, 18)

'packageJsonDirs' is assigned a value but never used

Check failure on line 16 in script/npm_test_plugin.js

View workflow job for this annotation

GitHub Actions / test (13, 2.7, 14)

Replace `·packageJsonDirs,·packageJsonDirsObject·` with `⏎··packageJsonDirs,⏎··packageJsonDirsObject,⏎`

Check failure on line 16 in script/npm_test_plugin.js

View workflow job for this annotation

GitHub Actions / test (13, 2.7, 14)

'packageJsonDirs' is assigned a value but never used

Check failure on line 16 in script/npm_test_plugin.js

View workflow job for this annotation

GitHub Actions / test (13, 2.7, 18)

Replace `·packageJsonDirs,·packageJsonDirsObject·` with `⏎··packageJsonDirs,⏎··packageJsonDirsObject,⏎`

Check failure on line 16 in script/npm_test_plugin.js

View workflow job for this annotation

GitHub Actions / test (13, 2.7, 18)

'packageJsonDirs' is assigned a value but never used

const passedArgs = process.argv.slice(2);
const coreConfigPath = path.resolve(__dirname, '../webpack/jest.config.js');
Expand Down Expand Up @@ -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);

Check failure on line 57 in script/npm_test_plugin.js

View workflow job for this annotation

GitHub Actions / test (13, 3.0, 14)

All 'var' declarations must be at the top of the function scope

Check failure on line 57 in script/npm_test_plugin.js

View workflow job for this annotation

GitHub Actions / test (13, 3.0, 18)

All 'var' declarations must be at the top of the function scope

Check failure on line 57 in script/npm_test_plugin.js

View workflow job for this annotation

GitHub Actions / test (13, 2.7, 14)

All 'var' declarations must be at the top of the function scope

Check failure on line 57 in script/npm_test_plugin.js

View workflow job for this annotation

GitHub Actions / test (13, 2.7, 18)

All 'var' declarations must be at the top of the function scope
function pluginDefinesLint(pluginPath) {
var packageHasNodeModules = fs.existsSync(`${pluginPath}/node_modules`); // skip gems
var packageData = JSON.parse(fs.readFileSync(`${pluginPath}/package.json`));
Expand All @@ -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) {
Expand All @@ -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'),
Expand Down Expand Up @@ -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);
}
Expand Down
28 changes: 24 additions & 4 deletions script/plugin_webpack_directories.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -47,17 +60,24 @@ var webpackedDirs = stderr => {
});
};

var getPluginDirs = stderr =>
JSON.parse(sanitizeWebpackDirs(webpackedDirs(stderr)));
var getPluginDirs = stderr => {

Check failure on line 63 in script/plugin_webpack_directories.js

View workflow job for this annotation

GitHub Actions / test (13, 3.0, 14)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`

Check failure on line 63 in script/plugin_webpack_directories.js

View workflow job for this annotation

GitHub Actions / test (13, 3.0, 18)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`

Check failure on line 63 in script/plugin_webpack_directories.js

View workflow job for this annotation

GitHub Actions / test (13, 2.7, 14)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`

Check failure on line 63 in script/plugin_webpack_directories.js

View workflow job for this annotation

GitHub Actions / test (13, 2.7, 18)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`
return JSON.parse(sanitizeWebpackDirs(webpackedDirs(stderr)));
};

var packageJsonDirs = stderr => {

Check failure on line 67 in script/plugin_webpack_directories.js

View workflow job for this annotation

GitHub Actions / test (13, 3.0, 14)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`

Check failure on line 67 in script/plugin_webpack_directories.js

View workflow job for this annotation

GitHub Actions / test (13, 3.0, 18)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`

Check failure on line 67 in script/plugin_webpack_directories.js

View workflow job for this annotation

GitHub Actions / test (13, 2.7, 14)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`

Check failure on line 67 in script/plugin_webpack_directories.js

View workflow job for this annotation

GitHub Actions / test (13, 2.7, 18)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`
return pluginPath('package.json')(getPluginDirs(stderr)).map(path.dirname);
};

var packageJsonDirs = stderr =>
pluginPath('package.json')(getPluginDirs(stderr)).map(path.dirname);
var packageJsonDirsObject = stderr => {

Check failure on line 71 in script/plugin_webpack_directories.js

View workflow job for this annotation

GitHub Actions / test (13, 3.0, 14)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`

Check failure on line 71 in script/plugin_webpack_directories.js

View workflow job for this annotation

GitHub Actions / test (13, 3.0, 18)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`

Check failure on line 71 in script/plugin_webpack_directories.js

View workflow job for this annotation

GitHub Actions / test (13, 2.7, 14)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`

Check failure on line 71 in script/plugin_webpack_directories.js

View workflow job for this annotation

GitHub Actions / test (13, 2.7, 18)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`
return pluginPathObject('package.json')(getPluginDirs(stderr));
};

module.exports = {
getPluginDirs,
pluginNodeModules: pluginPath('node_modules'),
aliasPlugins,
packageJsonDirs,
packageJsonDirsObject,
sanitizeWebpackDirs,
pluginPath,
};
4 changes: 2 additions & 2 deletions webpack/jest.config.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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 => {

Check failure on line 18 in webpack/jest.config.js

View workflow job for this annotation

GitHub Actions / test (13, 3.0, 14)

'customVendorDependencies' is assigned a value but never used

Check failure on line 18 in webpack/jest.config.js

View workflow job for this annotation

GitHub Actions / test (13, 3.0, 18)

'customVendorDependencies' is assigned a value but never used

Check failure on line 18 in webpack/jest.config.js

View workflow job for this annotation

GitHub Actions / test (13, 2.7, 14)

'customVendorDependencies' is assigned a value but never used

Check failure on line 18 in webpack/jest.config.js

View workflow job for this annotation

GitHub Actions / test (13, 2.7, 18)

'customVendorDependencies' is assigned a value but never used
const module = foremanJsModules.find(m => m.name === dep);
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion webpack/theforeman-test.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './theforeman_test_dependencies';
// todo: deprecate
// todo: deprecate

0 comments on commit f757e1d

Please sign in to comment.