Skip to content

Commit

Permalink
Merge pull request #14153 from ethereum/crowdin-ci-debug
Browse files Browse the repository at this point in the history
fix: crowdin-ci workflow
  • Loading branch information
corwintines authored Oct 10, 2024
2 parents 5f6163a + 517bf11 commit 521952b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 41 deletions.
6 changes: 1 addition & 5 deletions src/scripts/crowdin/translations/getTranslations.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import fs from "fs"

import { checkMarkdown } from "../../markdownChecker"
import crowdin from "../api-client/crowdinClient"
import crowdinImport from "../import/main"
import type { BucketsList } from "../import/types"

import { BUCKETS_PATH, DOT_CROWDIN, FILE_PATH, SUMMARY_PATH } from "./constants"
import { BUCKETS_PATH, DOT_CROWDIN, FILE_PATH } from "./constants"
import getApprovedBuckets from "./getApprovedBuckets"
import { decompressFile, downloadFile } from "./utils"

Expand Down Expand Up @@ -43,9 +42,6 @@ async function main() {

// Run Crowdin import script with buckets from Notion
crowdinImport(buckets)

// Check markdown
checkMarkdown(SUMMARY_PATH)
} catch (error: unknown) {
console.error((error as Error).message)
}
Expand Down
53 changes: 17 additions & 36 deletions src/scripts/crowdin/translations/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { execSync } from "child_process"
import fs, { readFileSync, unlinkSync, writeFileSync } from "fs"
import fs, { unlinkSync, writeFileSync } from "fs"
import path from "path"
import { Readable } from "stream"
import { finished } from "stream/promises"
Expand All @@ -9,9 +9,6 @@ import decompress from "decompress"

import { INTL_JSON_DIR, TRANSLATIONS_DIR } from "../../../lib/constants"

import { SUMMARY_PATH } from "./constants"
import { QASummary } from "./types"

export const downloadFile = async (url: string, writePath: string) => {
// Get directory from writePath and ensure it exists
const dir = writePath.substring(0, writePath.lastIndexOf("/"))
Expand Down Expand Up @@ -40,33 +37,6 @@ export const decompressFile = async (filePath: string, targetDir: string) => {
console.log("✅ Decompression complete.")
}

const getQAMessage = (locale: string) => {
console.log("Checking summary path:", SUMMARY_PATH)
if (!fs.existsSync(SUMMARY_PATH)) {
console.error("Could not find summary path:", SUMMARY_PATH)
throw new Error("No summary file found.")
}

const summaryJson: QASummary = JSON.parse(readFileSync(SUMMARY_PATH, "utf-8"))
const qaResults = summaryJson[locale]
? summaryJson[locale].map((s) => "- " + s).join("\n")
: null

if (!qaResults) return "No QA issues found"
return `
\`\`\`shell
yarn markdown-checker
\`\`\`
<details><summary>Unfold for ${summaryJson[locale].length} result(s)</summary>
${qaResults}
</details>
@coderabbitai review
`
}

export const createLocaleTranslationPR = (
locale: string,
buckets: number[]
Expand All @@ -88,8 +58,22 @@ export const createLocaleTranslationPR = (
}).trim()
execSync(`git checkout -b ${branchName}`)
execSync("git reset .")
execSync(`git add ${TRANSLATIONS_DIR}/${locale}`)
execSync(`git add ${INTL_JSON_DIR}/${locale}`)

// Check if the translations directory exists and contains files
const translationsDir = path.join(TRANSLATIONS_DIR, locale)
if (
fs.existsSync(translationsDir) &&
fs.readdirSync(translationsDir).length > 0
) {
execSync(`git add ${translationsDir}`)
}

// Check if the intl JSON directory exists and contains files
const intlJsonDir = path.join(INTL_JSON_DIR, locale)
if (fs.existsSync(intlJsonDir) && fs.readdirSync(intlJsonDir).length > 0) {
execSync(`git add ${intlJsonDir}`)
}

execSync(`git commit -m "${message}"`)
execSync(`git push origin ${branchName}`)

Expand All @@ -101,9 +85,6 @@ export const createLocaleTranslationPR = (
## Content buckets imported
${buckets.sort((a, b) => a - b).join(", ")}
## Markdown QA checker alerts
${getQAMessage(locale)}
`

const bodyWritePath = path.resolve(process.cwd(), "body.txt")
Expand Down

0 comments on commit 521952b

Please sign in to comment.