Crowdin merge helper scripts (#18684)
This commit is contained in:
30
script/lint-translation-files.js
Executable file
30
script/lint-translation-files.js
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const { execSync } = require('child_process')
|
||||
|
||||
// [start-readme]
|
||||
//
|
||||
// Use this script as part of the Crowdin merge process to output a list of parsing and rendering
|
||||
// errors in translated files and run script/reset-translated-file.js on them.
|
||||
//
|
||||
// [end-readme]
|
||||
|
||||
const parsingErrorsLog = '~/docs-translation-parsing-error.txt'
|
||||
const renderErrorsLog = '~/docs-translation-rendering-error.txt'
|
||||
|
||||
// 1. Check for parsing errors and output to file. Note this one must be run FIRST.
|
||||
execSync(`TEST_TRANSLATION=true npx jest content/lint-files > ${parsingErrorsLog}`)
|
||||
|
||||
// 2. Check for rendering errors and output to file. Note this one must be run SECOND.
|
||||
execSync(`script/test-render-translation.js > ${renderErrorsLog}`)
|
||||
|
||||
// Reset the broken files.
|
||||
execSync(`cat ${parsingErrorsLog} ${renderErrorsLog} | egrep "^translations/.*/(.+.md|.+.yml)$" | uniq | xargs -L1 script/reset-translated-file.js --prefer-main`)
|
||||
|
||||
// Print a message with next steps.
|
||||
console.log(`Success!
|
||||
|
||||
Verify changes with git status and then run:
|
||||
|
||||
git commit --no-verify -m "Reverted translated files with parsing and rendering errors"
|
||||
`)
|
||||
55
script/reset-known-broken-translation-files.js
Executable file
55
script/reset-known-broken-translation-files.js
Executable file
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
require('dotenv').config()
|
||||
const github = require('./helpers/github')()
|
||||
const { promisify } = require('util')
|
||||
const exec = promisify(require('child_process').exec)
|
||||
|
||||
// Check for required PAT
|
||||
if (!process.env.GITHUB_TOKEN) {
|
||||
console.error('Error! You must have a GITHUB_TOKEN set in an .env file to run this script.')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
// [start-readme]
|
||||
//
|
||||
// Use this script as part of the Crowdin merge process to get the list of known broken
|
||||
// files and run script/reset-translated-file.js on them.
|
||||
//
|
||||
// [end-readme]
|
||||
|
||||
main()
|
||||
|
||||
async function main () {
|
||||
// Get body text of OP from https://github.com/github/localization-support/issues/489.
|
||||
const { data: { body } } = await github.issues.get({
|
||||
owner: 'github',
|
||||
repo: 'localization-support',
|
||||
issue_number: '489'
|
||||
})
|
||||
|
||||
// Get the list of broken files from the body text.
|
||||
const brokenFiles = body
|
||||
.replace(/^[\s\S]*?## List of Broken Translations/m, '')
|
||||
.trim()
|
||||
|
||||
// Turn it into a simple array of files.
|
||||
const brokenFilesArray = brokenFiles
|
||||
.split('\n')
|
||||
.map(line => line.replace('- [ ] ', '').trim())
|
||||
|
||||
// Run the script to revert them.
|
||||
await Promise.all(brokenFilesArray.map(async (file) => {
|
||||
console.log(`resetting ${file}`)
|
||||
await exec(`script/reset-translated-file.js --prefer-main ${file}`)
|
||||
}))
|
||||
|
||||
// Print a message with next steps.
|
||||
console.log(`
|
||||
Success!
|
||||
|
||||
Verify changes with git status and then run:
|
||||
|
||||
git commit --no-verify -m "Reset broken translated files to English"
|
||||
`)
|
||||
}
|
||||
108
script/update-crowdin-issue.js
Executable file
108
script/update-crowdin-issue.js
Executable file
@@ -0,0 +1,108 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
require('dotenv').config()
|
||||
const github = require('./helpers/github')()
|
||||
const { execSync } = require('child_process')
|
||||
|
||||
// Check for required PAT
|
||||
if (!process.env.GITHUB_TOKEN) {
|
||||
console.error('Error! You must have a GITHUB_TOKEN set in an .env file to run this script.')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
// [start-readme]
|
||||
//
|
||||
// Use this script as the last step of the Crowdin merge process to:
|
||||
// 1. Add newly found broken translated files to the localization-support issue OP.
|
||||
// 2. Add a comment on the issue with more details.
|
||||
//
|
||||
// [end-readme]
|
||||
|
||||
const fixableErrorsLog = '~/docs-translation-errors-fixable.txt'
|
||||
const parsingErrorsLog = '~/docs-translation-parsing-error.txt'
|
||||
const renderingErrorsLog = '~/docs-translation-rendering-error.txt'
|
||||
|
||||
// Get just the fixable files:
|
||||
const fixable = execSync(`cat ${fixableErrorsLog} | egrep "^translations/.*/(.+.md|.+.yml)$" | sed -e 's/^/- [ ] /' | uniq`).toString()
|
||||
|
||||
// Get a list of files to be added to the body of the issue
|
||||
const filesToAdd = execSync(`cat ${parsingErrorsLog} ${renderingErrorsLog} | egrep "^translations/.*/(.+.md|.+.yml)$" | sed -e 's/^/- [ ] /' | uniq`).toString()
|
||||
|
||||
// Cat the three error logs together
|
||||
const allErrors = execSync('cat ~/docs-*').toString()
|
||||
|
||||
const comment = `
|
||||
Did a fresh merge today!
|
||||
|
||||
<details>
|
||||
<summary>In addition to the files in the PR body, these files also have errors, but can be fixed programmatically:</summary>
|
||||
|
||||
${fixable}
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Here are the <b>new</b> errors:</summary>
|
||||
|
||||
\`\`\`
|
||||
|
||||
${allErrors}
|
||||
|
||||
\`\`\`
|
||||
|
||||
</details>
|
||||
`
|
||||
|
||||
const owner = 'github'
|
||||
const repo = 'localization-support'
|
||||
const issueNumber = '489'
|
||||
|
||||
main()
|
||||
|
||||
async function main () {
|
||||
await updateIssueBody()
|
||||
await addNewComment()
|
||||
|
||||
console.log('Success! You can safely delete the temporary logfiles under ~/docs-*.')
|
||||
}
|
||||
|
||||
async function updateIssueBody () {
|
||||
// Get current body text of OP from https://github.com/github/localization-support/issues/489.
|
||||
const { data: { body } } = await github.issues.get({
|
||||
owner,
|
||||
repo,
|
||||
issue_number: issueNumber
|
||||
})
|
||||
|
||||
// Update the body with the list of newly broken files
|
||||
const newBody = body + '\n' + filesToAdd
|
||||
|
||||
// Update the issue
|
||||
try {
|
||||
await github.issues.update({
|
||||
owner,
|
||||
repo,
|
||||
issue_number: issueNumber,
|
||||
body: newBody
|
||||
})
|
||||
|
||||
console.log('Added newly found broken files to OP of https://github.com/github/localization-support/issues/489!\n')
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
|
||||
async function addNewComment () {
|
||||
try {
|
||||
await github.issues.createComment({
|
||||
owner,
|
||||
repo,
|
||||
issue_number: issueNumber,
|
||||
body: comment
|
||||
})
|
||||
|
||||
console.log('Added comment to the end of https://github.com/github/localization-support/issues/489!\n')
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
@@ -199,10 +199,12 @@ if (!process.env.TEST_TRANSLATION) {
|
||||
const ghesReleaseNotesYamlRelPaths = ghesReleaseNotesYamlAbsPaths.map(p => path.relative(rootDir, p))
|
||||
releaseNotesToLint = zip(ghesReleaseNotesYamlRelPaths, ghesReleaseNotesYamlAbsPaths)
|
||||
} else {
|
||||
console.log('testing translations.')
|
||||
|
||||
// get all translated markdown or yaml files by comparing files changed to main branch
|
||||
const changedFilesRelPaths = execSync('git diff --name-only origin/main | egrep "^translations/.*/.+.(yml|md)$"', { maxBuffer: 1024 * 1024 * 100 }).toString().split('\n')
|
||||
if (changedFilesRelPaths === '') process.exit(0)
|
||||
|
||||
console.log('testing translations.')
|
||||
|
||||
console.log(`Found ${changedFilesRelPaths.length} translated files.`)
|
||||
|
||||
const { mdRelPaths = [], ymlRelPaths = [], releaseNotesRelPaths = [] } = groupBy(changedFilesRelPaths, (path) => {
|
||||
|
||||
@@ -32,7 +32,8 @@ const ALLOW_LIST = new Set([
|
||||
'smimesign',
|
||||
'tweetsodium',
|
||||
'choosealicense.com',
|
||||
'renaming'
|
||||
'renaming',
|
||||
'localization-support'
|
||||
])
|
||||
|
||||
describe('check for repository references', () => {
|
||||
|
||||
Reference in New Issue
Block a user