-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(TDOPS-5707): Move lint-merge-report to scripts-core #4996
Merged
smouillour
merged 10 commits into
master
from
smouillour/test/report-lint-in-script-core
Nov 21, 2023
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
304ffe8
try
3298a7a
fix issue
88b8a4d
fix
9483a37
fix
98cd30d
fix
85be94a
remove merge-report in scripts-yarn-workspace
e89d753
add changeset, revert change used for test
a0e15c3
fix lint-merge-report, add doc
037e130
Merge branch 'master' into smouillour/test/report-lint-in-script-core
smouillour 0d905a9
Merge branch 'master' into smouillour/test/report-lint-in-script-core
smouillour File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change is there