Skip to content

Commit

Permalink
build: remove workspace.json (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
domjtalbot authored Mar 5, 2023
1 parent 1cf89c0 commit 82234b5
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 98 deletions.
138 changes: 59 additions & 79 deletions .github/actions/nx-affected/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,111 +131,91 @@ runs:
with:
script: |
const { exec: nodeExec } = require('child_process');
const { readFileSync } = require('fs');
const { promisify } = require('util');
const execAsync = promisify(nodeExec);
/**
* Get Workspace file
*/
const workspaceFile = readFileSync('./workspace.json');
const workspace = JSON.parse(workspaceFile);
*
* @param {'app' | 'lib' | 'e2e'} type
* @returns string array
*/
const getProjects = async (type, affected = false) => {
let config = `--type=${type} --select=projects`;
if (type === 'e2e') {
config = `--type=app --select=projectGraph.nodes`;
}
const getProjectNames = (rootDir, workspace) => {
let names = [];
const { stdout } = await execAsync(
`npx nx print-affected ${config} --all=${!affected}`
);
if (Object.prototype.hasOwnProperty.call(workspace, 'projects')) {
Object.entries(workspace['projects']).forEach(([name, path]) => {
if (path.startsWith(rootDir)) {
names.push(name);
}
});
let all = stdout
.replace(/\n/g, ' ')
.trim()
.split(', ')
.filter((project) => project !== '');
if (type === 'e2e') {
if (affected) {
const apps = await getProjects('app', true);
let affectedE2e = [];
apps.forEach((app) => {
if (all.includes(`${app}-e2e`)) {
affectedE2e.push(`${app}-e2e`);
}
});
all = affectedE2e;
} else {
all = all.filter((node) => node.endsWith('-e2e'));
}
}
return names;
return all;
};
/**
* All apps & libs
*/
const getWorkspaceProjects = () => {
const apps = getProjectNames('apps', workspace);
const e2eApps = apps.filter((name) => name.endsWith('-e2e'));
const nonE2EApps = apps.filter((name) => !name.endsWith('-e2e'));
const libs = getProjectNames('libs', workspace);
return {
(async () => {
const apps = await getProjects('app');
const libs = await getProjects('lib');
const e2e = await getProjects('e2e');
const affectedApps = await getProjects('app', true);
const affectedLibs = await getProjects('lib', true);
const affectedE2e = await getProjects('e2e', true);
let info = {
apps: JSON.stringify(apps),
e2eApps: JSON.stringify(e2eApps),
nonE2EApps: JSON.stringify(nonE2EApps),
e2eApps: JSON.stringify(e2e),
nonE2EApps: JSON.stringify(apps),
libs: JSON.stringify(libs),
numberOfApps: apps.length,
numberOfE2eApps: e2eApps.length,
numberOfNonE2EApps: nonE2EApps.length,
numberOfE2eApps: e2e.length,
numberOfNonE2EApps: apps.length,
numberOfLibs: libs.length,
hasApps: apps.length > 0,
hasE2EApps: e2eApps.length > 0,
hasNonE2EApps: nonE2EApps.length > 0,
hasE2EApps: e2e.length > 0,
hasNonE2EApps: apps.length > 0,
hasLibs: libs.length > 0,
hasProjects: apps.length > 0 || libs.length > 0,
};
};
/**
* Affected
*/
const getAffected = async (type) => {
const { stdout } = await execAsync(`npx nx affected:${type} --plain`);
const affected = stdout
.replace(/\n/g, ' ')
.trim()
.split(' ')
.filter((name) => name != '');
return affected;
};
const getAffectedWorkspace = async () => {
const affectedApps = await getAffected('apps');
const affectedE2eApps = affectedApps.filter((name) => name.endsWith('-e2e'));
const affectedNonE2EApps = affectedApps.filter(
(name) => !name.endsWith('-e2e')
);
const affectedLibs = await getAffected('libs');
return {
affectedApps: JSON.stringify(affectedApps),
affectedE2eApps: JSON.stringify(affectedE2eApps),
affectedNonE2EApps: JSON.stringify(affectedNonE2EApps),
affectedE2eApps: JSON.stringify(affectedE2e),
affectedNonE2EApps: JSON.stringify(affectedApps),
affectedLibs: JSON.stringify(affectedLibs),
numberOfAffectedApps: affectedApps.length,
numberOfAffectedE2eApps: affectedE2eApps.length,
numberOfAffectedNonE2EApps: affectedNonE2EApps.length,
numberOfAffectedE2eApps: affectedE2e.length,
numberOfAffectedNonE2EApps: affectedApps.length,
numberOfAffectedLibs: affectedLibs.length,
hasAffectedApps: affectedApps.length > 0,
hasAffectedE2EApps: affectedE2eApps.length > 0,
hasAffectedNonE2EApps: affectedNonE2EApps.length > 0,
hasAffectedE2EApps: affectedE2e.length > 0,
hasAffectedNonE2EApps: affectedApps.length > 0,
hasAffectedLibs: affectedLibs.length > 0,
hasAffected: affectedApps.length > 0 || affectedLibs.length > 0,
};
};
/**
* Nx Data
*/
const getNxData = async () => {
const data = {
...getWorkspaceProjects(),
...(await getAffectedWorkspace()),
};
console.log(info);
Object.entries(data).forEach(([name, value]) => {
console.log(name, value);
Object.entries(info).forEach(([name, value]) => {
core.setOutput(name, value);
});
};
getNxData();
})();
19 changes: 0 additions & 19 deletions workspace.json

This file was deleted.

0 comments on commit 82234b5

Please sign in to comment.