diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 0709b52d3b7f..38cdb53bbc74 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -13,6 +13,13 @@ jobs: steps: - uses: actions/checkout@v1 + - run: yarn install + + # Update all the translation issues on a nightly basis + - run: node packages/typescriptlang-org/scripts/updateGitHubTranslationIssues.ts + env: + GITHUB_TOKEN: ${{ secrets.TS_BOT_TOKEN }} + # Setup Git - run: git config user.name "typescript-bot" - run: git config user.email "bot@typescriptlang.org" @@ -21,5 +28,5 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.TS_BOT_TOKEN }} - - run: git commit --no-edit --allow-empty + - run: git commit --allow-empty -m "Nightly Deploy" - run: git push upstream master:release -f diff --git a/packages/typescriptlang-org/scripts/makeMarkdownOfTranslations.js b/packages/typescriptlang-org/scripts/makeMarkdownOfTranslations.js index fc16871b14cc..636152a9c14a 100644 --- a/packages/typescriptlang-org/scripts/makeMarkdownOfTranslations.js +++ b/packages/typescriptlang-org/scripts/makeMarkdownOfTranslations.js @@ -2,15 +2,7 @@ const { join } = require("path") const fs = require("fs") const path = require("path") -const lang = process.argv.slice(2)[0] -if (!lang) { - console.log("You need to run this script with a language arg") - console.log( - "> node packages/typescriptlang-org/scripts/makeMarkdownOfTranslations.js jp" - ) -} - -const getAllTODOFiles = () => { +const getAllTODOFiles = lang => { const diffFolders = (root, lang) => { const en = join(root, "en") const thisLang = join(root, lang) @@ -111,5 +103,17 @@ const toMarkdown = files => { return md.join("\n") } -const files = getAllTODOFiles() -console.log(toMarkdown(files)) +if (!module.parent) { + const lang = process.argv.slice(2)[0] + if (!lang) { + console.log("You need to run this script with a language arg") + console.log( + "> node packages/typescriptlang-org/scripts/makeMarkdownOfTranslations.js jp" + ) + } + + const files = getAllTODOFiles(lang) + console.log(toMarkdown(files)) +} + +module.exports = { toMarkdown, getAllTODOFiles } diff --git a/packages/typescriptlang-org/scripts/updateGitHubTranslationIssues.ts b/packages/typescriptlang-org/scripts/updateGitHubTranslationIssues.ts new file mode 100644 index 000000000000..87868da6d9d6 --- /dev/null +++ b/packages/typescriptlang-org/scripts/updateGitHubTranslationIssues.ts @@ -0,0 +1,39 @@ +// @ts-check + +const nodeFetch = require("node-fetch").default +const { writeFileSync, readFileSync } = require("fs") +const { join } = require("path") +const { getAllTODOFiles, toMarkdown } = require("./makeMarkdownOfTranslations") +const Octokit = require("@octokit/rest") + +const languages = { + ja: 220, + pt: 233, + es: 232, +} + +const go = async () => { + const octokit = Octokit({ + auth: process.env.GITHUB_TOKEN, + userAgent: "TS Lang Issue Updater", + }) + + const langs = Object.keys(languages) + + for (let index = 0; index < langs.length; index++) { + const lang = langs[index] + const issueNumber = languages[lang] + + const files = getAllTODOFiles(lang) + const body = toMarkdown(files) + + await octokit.issues.update({ + owner: "Microsoft", + repo: "TypeScript-Website", + issue_number: issueNumber, + body, + }) + } +} + +go()