Skip to content

Commit

Permalink
update to get all format
Browse files Browse the repository at this point in the history
  • Loading branch information
LudovicMalot committed Sep 21, 2024
1 parent 445689c commit 453c458
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 26 deletions.
19 changes: 14 additions & 5 deletions .github/workflows/update-genshin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -89,11 +93,16 @@ jobs:
git config user.name "GitHub Actions Bot"
git config user.email "[email protected]"
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
Expand Down
46 changes: 25 additions & 21 deletions scripts/workflow/update_file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}
}

Expand Down

0 comments on commit 453c458

Please sign in to comment.