From 453c45831346e7deda98d3b8bec1eae0086deba2 Mon Sep 17 00:00:00 2001 From: Ludovic Date: Sat, 21 Sep 2024 12:07:08 +0200 Subject: [PATCH] update to get all format --- .github/workflows/update-genshin.yml | 19 +++++++++--- scripts/workflow/update_file.ts | 46 +++++++++++++++------------- 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/.github/workflows/update-genshin.yml b/.github/workflows/update-genshin.yml index 08daddf0925..e265c2a2fa3 100644 --- a/.github/workflows/update-genshin.yml +++ b/.github/workflows/update-genshin.yml @@ -53,9 +53,13 @@ jobs: FILTERED_COMMITS=$(echo "$COMMITS" | awk -v last="$LAST_COMMIT" ' $1 == last {exit} - /^[^ ]+ feat: update .*data .*v[0-9]+\.[0-9]+$/ {print} + /feat: update .*data .*(v|version).*[0-9]+\.[0-9]+$/ { + gsub(/version[[:space:]]?/, "v"); + gsub(/v[[:space:]]?/, "v"); + print + } ') - + echo "$FILTERED_COMMITS" ALL_COMMITS="$ALL_COMMITS$FILTERED_COMMITS" if echo "$COMMITS" | grep -q "$LAST_COMMIT"; then @@ -89,11 +93,16 @@ jobs: git config user.name "GitHub Actions Bot" git config user.email "actions@github.com" git clone https://github.com/dvaJi/genshin-data.git - echo "$COMMITS" - echo "$COMMITS" | while read -r COMMIT MESSAGE; do + mapfile -t COMMITS <<< "$COMMITS" + + # Process commits in reverse order + for ((i=${#COMMITS[@]}-1; i>=0; i--)); do + COMMIT=$(echo "${COMMITS[i]}" | awk '{print $1}') + MESSAGE=$(echo "${COMMITS[i]}" | cut -d' ' -f2-) + VERSION=$(echo "$MESSAGE" | sed -n 's/.*v\([0-9]\+\.[0-9]\+\)$/\1/p') gh api "repos/dvaJi/genshin-data/git/trees/$COMMIT?recursive=1" \ - --jq '.tree[] | select(.type == "blob") | .path' > changed_files.txt + --jq '.tree[] | select(.type == "blob") | .path' > changed_files.txt bun run ./scripts/workflow/update_file.ts "$VERSION" echo "$COMMIT" > .last_processed_commit diff --git a/scripts/workflow/update_file.ts b/scripts/workflow/update_file.ts index 009974f57c9..5d735284fba 100644 --- a/scripts/workflow/update_file.ts +++ b/scripts/workflow/update_file.ts @@ -23,29 +23,33 @@ const errorFileList: Array<{ error: any; key: string; obj: any }> = []; async function processLines() { for (const line of lines) { - const [, , lang, folder, file] = line.split('/'); - const newLang = langMapping[lang]; - const newFolder = folderMapping[folder]; - - if (folder === 'domains.json' || folder === 'domains') { - const link = join(baseDir, 'genshin-data/', line); - const newPath = join(baseDir, `data/${newLang}/${folder.split('.')[0]}.json`); - const newData = await readJsonFile(link); - await writeJsonFile(newPath, newData); - continue; - } + try { + const [, , lang, folder, file] = line.split('/'); + const newLang = langMapping[lang]; + const newFolder = folderMapping[folder]; + + if (folder === 'domains.json' || folder === 'domains') { + const link = join(baseDir, 'genshin-data/', line); + const newPath = join(baseDir, `data/${newLang}/${folder.split('.')[0]}.json`); + const newData = await readJsonFile(link); + await writeJsonFile(newPath, newData); + continue; + } - const fileName = file.split('.')[0]; - let newFile = toPascalCase(fileName); - if (newFolder === 'AchievementCategory') { - newFile = replaceRomanNumeralsPascalCased(newFile); - } + const fileName = file.split('.')[0]; + let newFile = toPascalCase(fileName); + if (newFolder === 'AchievementCategory') { + newFile = replaceRomanNumeralsPascalCased(newFile); + } - const dvalinPath = join(baseDir, `data/${newLang}/${newFolder}/${newFile}.json`); - const genshinDataPath = join(baseDir, 'genshin-data/', line); - const fileContent = await handleFile(genshinDataPath); - await writeJsonFile(dvalinPath, fileContent); - updatedFileList.push(dvalinPath); + const dvalinPath = join(baseDir, `data/${newLang}/${newFolder}/${newFile}.json`); + const genshinDataPath = join(baseDir, 'genshin-data/', line); + const fileContent = await handleFile(genshinDataPath); + await writeJsonFile(dvalinPath, fileContent); + updatedFileList.push(dvalinPath); + } catch (error) { + errorFileList.push({ error, key: line, obj: error }); + } } }