From 63eb8cc6e9833242a5c71ba73267a67cfe2ebe32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Acid=20Chicken=20=28=E7=A1=AB=E9=85=B8=E9=B6=8F=29?= Date: Tue, 21 May 2024 06:07:07 +0900 Subject: [PATCH 1/3] ci: verify locale data --- .github/workflows/lint.yml | 18 +++++++++++++ locales/verify.js | 53 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 locales/verify.js diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 76616ec5a71a..cc6aec866b91 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -86,3 +86,21 @@ jobs: - run: pnpm --filter misskey-reversi run build if: ${{ matrix.workspace == 'backend' }} - run: pnpm --filter ${{ matrix.workspace }} run typecheck + + locale_verify: + needs: [pnpm_install] + runs-on: ubuntu-latest + continue-on-error: true + steps: + - uses: actions/checkout@v4.1.1 + with: + fetch-depth: 0 + submodules: true + - uses: pnpm/action-setup@v4 + - uses: actions/setup-node@v4.0.2 + with: + node-version-file: '.node-version' + cache: 'pnpm' + - run: corepack enable + - run: pnpm i --frozen-lockfile + - run: cd locales && node verify.js diff --git a/locales/verify.js b/locales/verify.js new file mode 100644 index 000000000000..a8e9875d6eda --- /dev/null +++ b/locales/verify.js @@ -0,0 +1,53 @@ +import locales from './index.js'; + +let valid = true; + +function writeError(type, lang, tree, data) { + process.stderr.write(JSON.stringify({ type, lang, tree, data })); + process.stderr.write('\n'); + valid = false; +} + +function verify(expected, actual, lang, trace) { + for (let key in expected) { + if (!Object.prototype.hasOwnProperty.call(actual, key)) { + continue; + } + if (typeof expected[key] === 'object') { + if (typeof actual[key] !== 'object') { + writeError('mismatched_type', lang, trace ? `${trace}.${key}` : key, { expected: 'object', actual: typeof actual[key] }); + continue; + } + verify(expected[key], actual[key], lang, trace ? `${trace}.${key}` : key); + } else if (typeof expected[key] === 'string') { + switch (typeof actual[key]) { + case 'object': + writeError('mismatched_type', lang, trace ? `${trace}.${key}` : key, { expected: 'string', actual: 'object' }); + break; + case 'undefined': + continue; + case 'string': + const expectedParameters = new Set(expected[key].match(/\{[^}]+\}/g)?.map((s) => s.slice(1, -1))); + const actualParameters = new Set(actual[key].match(/\{[^}]+\}/g)?.map((s) => s.slice(1, -1))); + for (let parameter of expectedParameters) { + if (!actualParameters.has(parameter)) { + writeError('missing_parameter', lang, trace ? `${trace}.${key}` : key, { parameter }); + } + } + } + } + } +} + +const { ['ja-JP']: original, ...verifiees } = locales; + +for (let lang in verifiees) { + if (!Object.prototype.hasOwnProperty.call(locales, lang)) { + continue; + } + verify(original, verifiees[lang], lang); +} + +if (!valid) { + process.exit(1); +} From 7ed2f3e655d3770d6f44698cece8707a78924fd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Acid=20Chicken=20=28=E7=A1=AB=E9=85=B8=E9=B6=8F=29?= Date: Tue, 21 May 2024 06:11:14 +0900 Subject: [PATCH 2/3] ci: separate workflows --- .github/workflows/lint.yml | 18 ------------------ .github/workflows/locale.yml | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/locale.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index cc6aec866b91..76616ec5a71a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -86,21 +86,3 @@ jobs: - run: pnpm --filter misskey-reversi run build if: ${{ matrix.workspace == 'backend' }} - run: pnpm --filter ${{ matrix.workspace }} run typecheck - - locale_verify: - needs: [pnpm_install] - runs-on: ubuntu-latest - continue-on-error: true - steps: - - uses: actions/checkout@v4.1.1 - with: - fetch-depth: 0 - submodules: true - - uses: pnpm/action-setup@v4 - - uses: actions/setup-node@v4.0.2 - with: - node-version-file: '.node-version' - cache: 'pnpm' - - run: corepack enable - - run: pnpm i --frozen-lockfile - - run: cd locales && node verify.js diff --git a/.github/workflows/locale.yml b/.github/workflows/locale.yml new file mode 100644 index 000000000000..8a4042bd99a0 --- /dev/null +++ b/.github/workflows/locale.yml @@ -0,0 +1,25 @@ +name: Lint + +on: + push: + paths: + - locales/** + pull_request: + paths: + - locales/** + +jobs: + locale_verify: + runs-on: ubuntu-latest + continue-on-error: true + steps: + - uses: actions/checkout@v4.1.1 + with: + fetch-depth: 0 + submodules: true + - uses: pnpm/action-setup@v4 + - uses: actions/setup-node@v4.0.2 + with: + node-version-file: '.node-version' + cache: 'pnpm' + - run: cd locales && node verify.js From f8fc37d6678a5b0095418d3040b8d00c08fa1dc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Acid=20Chicken=20=28=E7=A1=AB=E9=85=B8=E9=B6=8F=29?= Date: Tue, 21 May 2024 06:12:37 +0900 Subject: [PATCH 3/3] ci: missing installation --- .github/workflows/locale.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/locale.yml b/.github/workflows/locale.yml index 8a4042bd99a0..de2247e77277 100644 --- a/.github/workflows/locale.yml +++ b/.github/workflows/locale.yml @@ -22,4 +22,6 @@ jobs: with: node-version-file: '.node-version' cache: 'pnpm' + - run: corepack enable + - run: pnpm i --frozen-lockfile - run: cd locales && node verify.js