add test
parent
06a7bb13f7
commit
2926056794
|
|
@ -9,7 +9,7 @@ on:
|
|||
- closed
|
||||
|
||||
jobs:
|
||||
build:
|
||||
merge:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout repo content
|
||||
|
|
@ -23,7 +23,35 @@ jobs:
|
|||
|
||||
- name: merge translation
|
||||
run: python './tools/merge.py'
|
||||
|
||||
- name: commit files
|
||||
run: |
|
||||
if git diff-index --quiet HEAD --; then
|
||||
echo "No changes detected"
|
||||
exit 0
|
||||
else
|
||||
git config --local user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git config --local user.name "github-actions[bot]"
|
||||
git add -A
|
||||
git commit -m "Merge i18n/l10n"
|
||||
fi
|
||||
- name: push changes
|
||||
uses: ad-m/github-push-action@master
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
branch: main
|
||||
|
||||
jobs:
|
||||
progress_update:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout repo content
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: "3.10"
|
||||
|
||||
- name: run crowdin tool.py
|
||||
env:
|
||||
crowdin_api_token : ${{ secrets.CROWDIN_PROGRESS_CHECKER_API_KEY }}
|
||||
|
|
@ -38,7 +66,7 @@ jobs:
|
|||
git config --local user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git config --local user.name "github-actions[bot]"
|
||||
git add -A
|
||||
git commit -m "Merge i18n/l10n & Update README📃"
|
||||
git commit -m "Update Progress📃"
|
||||
fi
|
||||
- name: push changes
|
||||
uses: ad-m/github-push-action@master
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
name: Pull Request Test
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
merge-test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repo content
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.head.sha }}
|
||||
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: "3.10"
|
||||
- run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r ./tools/requirements.txt
|
||||
|
||||
- name: run tests
|
||||
run: python -m unittest discover -s tests -p './tools/*_test.py'
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
import unittest
|
||||
|
||||
class TestMerge(unittest.TestCase):
|
||||
def test_merge(self):
|
||||
import json
|
||||
import os
|
||||
import glob
|
||||
from collections import defaultdict
|
||||
|
||||
TEMPLATE_FOLDER = './template'
|
||||
LOCALIZATIONS_FOLDER = './localizations'
|
||||
REPORT_FILE = os.path.join(os.getcwd(), 'tools', 'report', 'report.txt')
|
||||
|
||||
|
||||
def merge_json_files(lang_folder):
|
||||
# Get all JSON files in the folder
|
||||
json_files = glob.glob(os.path.join(lang_folder, '*.json'))
|
||||
extensions_folder = os.path.join(lang_folder, 'extensions')
|
||||
if os.path.exists(extensions_folder):
|
||||
json_files += glob.glob(os.path.join(extensions_folder, '*.json'))
|
||||
|
||||
# Put StableDiffusion.json as the first element in the list
|
||||
stable_diffusion_file = os.path.join(lang_folder, 'StableDiffusion.json')
|
||||
if stable_diffusion_file in json_files:
|
||||
json_files.remove(stable_diffusion_file)
|
||||
json_files.insert(0, stable_diffusion_file)
|
||||
|
||||
# Merge all JSON files
|
||||
merged = defaultdict(dict)
|
||||
duplicate_keys = defaultdict(list)
|
||||
for file in json_files:
|
||||
with open(file, 'r', encoding='utf-8') as f:
|
||||
data = json.load(f)
|
||||
for key, value in data.items():
|
||||
if isinstance(value, dict):
|
||||
# Key already exists, recursively merge subkeys
|
||||
merged[key].update(value)
|
||||
elif key in merged:
|
||||
# Key already exists, add to list of duplicate keys
|
||||
duplicate_keys[key].append(file)
|
||||
else:
|
||||
merged[key] = value
|
||||
|
||||
# Write merged JSON file
|
||||
lang_code = os.path.basename(lang_folder)
|
||||
merged_file = os.path.join('localizations', f'{lang_code}.json')
|
||||
with open(merged_file, 'w', encoding='utf-8') as f:
|
||||
json.dump(merged, f, ensure_ascii=False, indent=4)
|
||||
|
||||
# Write report file
|
||||
report_file = os.path.join('tools', 'report', f'report-{lang_code}.txt')
|
||||
with open(report_file, 'w', encoding='utf-8') as f:
|
||||
if len(duplicate_keys) > 0:
|
||||
f.write('重複したkeyがあります: \n')
|
||||
for key, files in duplicate_keys.items():
|
||||
f.write(f'\n"{key}"\n')
|
||||
for file in files:
|
||||
# Get the value for the key in the file
|
||||
with open(file, 'r', encoding='utf-8') as f2:
|
||||
data = json.load(f2)
|
||||
value = data.get(key)
|
||||
# Write the value for the key in the file
|
||||
f.write(f'"{file}" - "{value}".\n')
|
||||
else:
|
||||
f.write('重複したkeyはありません')
|
||||
|
||||
|
||||
|
||||
def merge_all_languages():
|
||||
# Create localizations folder if it does not exist
|
||||
if not os.path.exists(LOCALIZATIONS_FOLDER):
|
||||
os.mkdir(LOCALIZATIONS_FOLDER)
|
||||
|
||||
# Merge all languages
|
||||
for lang_folder in glob.glob(os.path.join(TEMPLATE_FOLDER, '*_*')):
|
||||
merge_json_files(lang_folder)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
merge_all_languages()
|
||||
|
||||
self.assertTrue(True) # 例として、必ず成功するテストケースを追加
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Loading…
Reference in New Issue