-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(TDOPS-5707): Move lint-merge-report to scripts-core (#4996)
- Loading branch information
1 parent
f43609c
commit e77b32c
Showing
10 changed files
with
261 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@talend/scripts-core': minor | ||
--- | ||
|
||
Add option lint-merge-report |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@talend/scripts-yarn-workspace': major | ||
--- | ||
|
||
[BREAKING CHANGE]Remove option lint-merge-report |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,68 @@ | ||
{ | ||
"devDependencies": { | ||
"@changesets/cli": "^2.26.2", | ||
"@talend/scripts-config-babel": "^13.2.0", | ||
"@talend/scripts-config-prettier": "^12.1.0", | ||
"@talend/scripts-yarn-workspace": "^1.3.0", | ||
"cross-env": "^7.0.3", | ||
"cross-spawn": "^7.0.3", | ||
"eslint": "^8.53.0", | ||
"husky": "^8.0.3", | ||
"i18next-scanner": "^4.4.0", | ||
"lint-staged": "^13.3.0", | ||
"prettier": "^3.1.0", | ||
"rimraf": "^3.0.2", | ||
"typescript": "^5.2.2" | ||
}, | ||
"scripts": { | ||
"postinstall": "talend-yarn-workspace run build:lib", | ||
"pre-release": "talend-yarn-workspace run pre-release", | ||
"start": "yarn workspace @talend/ui-playground run start", | ||
"start-storybook": "yarn workspace @talend/ui-storybook-one run start", | ||
"release": "yarn pre-release && yarn changeset publish", | ||
"lint-staged": "lint-staged", | ||
"lint": "cross-env WORKSPACE_RUN_FAIL=no-bail talend-yarn-workspace run lint", | ||
"lint-merge-report": "talend-yarn-workspace lint-merge-report", | ||
"test": "cross-env TZ=UTC talend-yarn-workspace run test --silent", | ||
"test:update": "cross-env TZ=UTC yarn workspaces run test --silent -u", | ||
"test:cov": "cross-env TZ=UTC talend-yarn-workspace run test:cov", | ||
"test:demo": "talend-yarn-workspace run test:demo", | ||
"test:cron": "talend-yarn-workspace run test:cron", | ||
"start-components": "yarn workspace @talend/react-components run start", | ||
"start-containers": "yarn workspace @talend/react-containers run start", | ||
"start-stepper": "yarn workspace @talend/react-stepper run start", | ||
"start-forms": "yarn workspace @talend/react-forms run start", | ||
"start-theme": "yarn workspace @talend/bootstrap-theme run start", | ||
"changelog": "git log --pretty=\"format:%C(bold green)%ad%C(reset) %s\" --date=short --color", | ||
"prepare": "husky install" | ||
}, | ||
"resolutions": { | ||
"**/cypress": "^12.17.4", | ||
"**/@types/react": "^18.2.7", | ||
"**/@types/react-dom": "^18.2.7", | ||
"**/i18next-scanner-typescript/typescript": "^5.0.4", | ||
"**/browser-sync-client/typescript": "^5.0.4", | ||
"**/vinyl-fs/glob-parent": "^5.1.2", | ||
"**/fast-glob/glob-parent": "^5.1.2", | ||
"**/trim": "^1.0.1", | ||
"**/x-default-browser": "^0.5.2", | ||
"**/reactour/prop-types": "^15.7.2" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/Talend/ui.git" | ||
}, | ||
"version": "0.0.0", | ||
"private": true, | ||
"workspaces": [ | ||
"packages/*", | ||
"tools/*", | ||
"fork/*" | ||
], | ||
"lint-staged": { | ||
"*.{json,md,mdx,html,js,jsx,ts,tsx}": [ | ||
"prettier --write" | ||
] | ||
} | ||
"devDependencies": { | ||
"@changesets/cli": "^2.26.2", | ||
"@talend/scripts-config-babel": "^13.2.0", | ||
"@talend/scripts-config-prettier": "^12.1.0", | ||
"@talend/scripts-core": "^16.2.0", | ||
"@talend/scripts-yarn-workspace": "^1.3.0", | ||
"cross-env": "^7.0.3", | ||
"cross-spawn": "^7.0.3", | ||
"eslint": "^8.53.0", | ||
"husky": "^8.0.3", | ||
"i18next-scanner": "^4.4.0", | ||
"lint-staged": "^13.3.0", | ||
"prettier": "^3.1.0", | ||
"rimraf": "^3.0.2", | ||
"typescript": "^5.2.2" | ||
}, | ||
"scripts": { | ||
"postinstall": "talend-yarn-workspace run build:lib", | ||
"pre-release": "talend-yarn-workspace run pre-release", | ||
"start": "yarn workspace @talend/ui-playground run start", | ||
"start-storybook": "yarn workspace @talend/ui-storybook-one run start", | ||
"release": "yarn pre-release && yarn changeset publish", | ||
"lint-staged": "lint-staged", | ||
"lint": "cross-env WORKSPACE_RUN_FAIL=no-bail talend-yarn-workspace run lint", | ||
"lint-merge-report": "talend-scripts lint-merge-report", | ||
"test": "cross-env TZ=UTC talend-yarn-workspace run test --silent", | ||
"test:update": "cross-env TZ=UTC yarn workspaces run test --silent -u", | ||
"test:cov": "cross-env TZ=UTC talend-yarn-workspace run test:cov", | ||
"test:demo": "talend-yarn-workspace run test:demo", | ||
"test:cron": "talend-yarn-workspace run test:cron", | ||
"start-components": "yarn workspace @talend/react-components run start", | ||
"start-containers": "yarn workspace @talend/react-containers run start", | ||
"start-stepper": "yarn workspace @talend/react-stepper run start", | ||
"start-forms": "yarn workspace @talend/react-forms run start", | ||
"start-theme": "yarn workspace @talend/bootstrap-theme run start", | ||
"changelog": "git log --pretty=\"format:%C(bold green)%ad%C(reset) %s\" --date=short --color", | ||
"prepare": "husky install" | ||
}, | ||
"resolutions": { | ||
"**/cypress": "^12.17.4", | ||
"**/@types/react": "^18.2.7", | ||
"**/@types/react-dom": "^18.2.7", | ||
"**/i18next-scanner-typescript/typescript": "^5.0.4", | ||
"**/browser-sync-client/typescript": "^5.0.4", | ||
"**/vinyl-fs/glob-parent": "^5.1.2", | ||
"**/fast-glob/glob-parent": "^5.1.2", | ||
"**/trim": "^1.0.1", | ||
"**/x-default-browser": "^0.5.2", | ||
"**/reactour/prop-types": "^15.7.2" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/Talend/ui.git" | ||
}, | ||
"version": "0.0.0", | ||
"private": true, | ||
"workspaces": [ | ||
"packages/*", | ||
"tools/*", | ||
"fork/*" | ||
], | ||
"lint-staged": { | ||
"*.{json,md,mdx,html,js,jsx,ts,tsx}": [ | ||
"prettier --write" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"lintMergeReport": { | ||
"packageDirs": ["fork", "packages", "tools"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
/* eslint-disable no-console */ | ||
import { spawn } from 'child_process'; | ||
|
||
/* eslint-disable no-param-reassign */ | ||
import fs from 'fs'; | ||
|
||
import { getEnv } from '../utils/env.js'; | ||
import { getPresetApi } from '../utils/preset.js'; | ||
|
||
const reports = ['eslint-report.json', 'stylelint-report.json']; | ||
|
||
let buff = []; | ||
|
||
async function run(cmd, opts = {}) { | ||
if (opts.verbose) { | ||
console.log(`\n#### RUNNER: ${cmd.name} ${cmd.args.join(' ')}`); | ||
} | ||
const start = Date.now(); | ||
return new Promise(async (resolve, reject) => { | ||
const out = spawn(cmd.name, cmd.args); | ||
let stdout = ''; | ||
let stderr = ''; | ||
out.on('error', error => { | ||
console.error(error); | ||
reject(error); | ||
}); | ||
out.on('close', () => { | ||
resolve(stdout); | ||
}); | ||
out.on('exit', code => { | ||
if (opts.verbose && stderr) { | ||
console.error(`#### RUNNER: Child Process STDERR: ${stderr}`); | ||
} | ||
if (opts.verbose && stdout) { | ||
console.error(`#### RUNNER: Child Process STDOUT: ${stdout}`); | ||
} | ||
if (code > 0) { | ||
run.exitCode += 1; | ||
console.error(`#### RUNNER: ${cmd.name} ${cmd.args.join(' ')} exit code ${code}`); | ||
reject(`STDOUT: ${stdout}\n\nSTDERR: ${stderr}`); | ||
return; | ||
} | ||
const end = Date.now(); | ||
console.log( | ||
`#### RUNNER: ${cmd.name} ${cmd.args.join(' ')} exit code ${code} in ${ | ||
(end - start) / 1000 | ||
} seconds`, | ||
); | ||
resolve(stdout); | ||
}); | ||
out.stdout.on('data', data => { | ||
const datastr = data.toString(); | ||
if (data && datastr) { | ||
stdout += datastr; | ||
} | ||
}); | ||
|
||
out.stderr.on('data', data => { | ||
const datastr = data.toString(); | ||
if (data && datastr) { | ||
stderr += datastr; | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
function transform(item) { | ||
if (item.source && !item.filePath) { | ||
item.filePath = item.source; | ||
delete item.source; | ||
} | ||
if (item.warnings && !item.messages) { | ||
item.messages = item.warnings.map(w => ({ | ||
...w, | ||
severity: 1, | ||
message: w.text, | ||
ruleId: w.rule, | ||
})); | ||
item.warningCount = item.warnings.length; | ||
delete item.warning; | ||
} else if (item.messages) { | ||
item.messages = item.messages.map(w => ({ ...w, severity: 1 })); | ||
item.warningCount += item.errorCount; | ||
item.errorCount = 0; | ||
} | ||
return item; | ||
} | ||
|
||
function getPackages(packageDirs = []) { | ||
return packageDirs.flatMap(dir => | ||
fs.readdirSync(dir).map(subDir => ({ | ||
name: subDir, | ||
location: `${dir}/${subDir}`, | ||
})), | ||
); | ||
} | ||
|
||
export default function mergeReport(options) { | ||
// current env vars and talend scripts configuration in <project-folder>/talend-scripts.(js/json) | ||
const env = getEnv(options); | ||
env.TALEND_MODE = 'production'; | ||
console.log(`Talend scripts mode : ${env.TALEND_MODE}`); | ||
if (env.TALEND_SCRIPTS_CONFIG) { | ||
console.log('Talend scripts configuration file found and loaded'); | ||
} else { | ||
console.log('Talend scripts configuration file not found'); | ||
} | ||
const presetApi = getPresetApi(env); | ||
const rootPackageDirs = presetApi.getUserConfig('lintMergeReport', {})?.packageDirs || []; | ||
const packages = getPackages(rootPackageDirs); | ||
|
||
if (packages.length === 0) { | ||
throw new Error( | ||
'No packages has been retrieved, check if the talend-scripts.json is well configured', | ||
); | ||
} | ||
|
||
// https://stackoverflow.com/questions/65944700/how-to-run-git-diff-in-github-actions | ||
const diff = run({ | ||
name: 'git', | ||
args: ['diff', '--name-only', `origin/${options[0]}`, `origin/${options[1]}`], | ||
}) | ||
.then(out => | ||
out | ||
.split('\n') | ||
.map(str => str.trim()) | ||
.filter(Boolean), | ||
) | ||
.catch(e => console.error(e)); | ||
|
||
diff.then(files => { | ||
function onlyIfInDiff(lint) { | ||
return !!files.find(f => lint.filePath.endsWith(`/${f}`)); | ||
} | ||
|
||
packages.forEach(pkg => { | ||
reports.forEach(report => { | ||
const fpath = `${pkg.location}/${report}`; | ||
if (fs.existsSync(fpath)) { | ||
try { | ||
buff = buff.concat( | ||
JSON.parse(fs.readFileSync(fpath)).map(transform).filter(onlyIfInDiff), | ||
); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
}); | ||
}); | ||
const target = `${process.cwd()}/eslint-report.json`; | ||
|
||
// eslint-disable-next-line no-console | ||
console.log(`report merge into ${target}`); | ||
fs.writeFileSync(target, JSON.stringify(buff, null, 2)); | ||
}); | ||
} |
Oops, something went wrong.