mirror of
https://github.com/earthjasonlin/star-rail-warp-export.git
synced 2025-10-07 07:10:07 +08:00
ci: update idmap script and add workflow
This commit is contained in:
91
.github/workflows/idmap.yml
vendored
Normal file
91
.github/workflows/idmap.yml
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
name: Update ID Map and Version
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 0 * * *'
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
update-idmap:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
token: ${{ secrets.GH_PAT }}
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: '3.x'
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install requests opencc
|
||||
|
||||
- name: Run getIdMap.py
|
||||
run: |
|
||||
python tools/getIdMap.py
|
||||
|
||||
- name: Check if idJson.json changed
|
||||
id: check_changes
|
||||
run: |
|
||||
git add -A
|
||||
if git diff --staged --quiet -- src/idJson.json; then
|
||||
echo "changes=false" >> $GITHUB_OUTPUT
|
||||
echo "No changes detected in src/idJson.json"
|
||||
else
|
||||
echo "changes=true" >> $GITHUB_OUTPUT
|
||||
echo "Changes detected in src/idJson.json"
|
||||
fi
|
||||
|
||||
- name: Get current version from idJson
|
||||
if: steps.check_changes.outputs.changes == 'true'
|
||||
id: get_version
|
||||
run: |
|
||||
VERSION=$(python -c "import json; print(json.load(open('src/idJson.json', encoding='utf-8'))['version'])")
|
||||
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
||||
echo "Current version in idJson: $VERSION"
|
||||
|
||||
- name: Bump package.json version
|
||||
if: steps.check_changes.outputs.changes == 'true'
|
||||
id: bump_version
|
||||
run: |
|
||||
CURRENT_VERSION=$(node -p "require('./package.json').version")
|
||||
echo "Current package.json version: $CURRENT_VERSION"
|
||||
|
||||
IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION"
|
||||
MAJOR=${VERSION_PARTS[0]}
|
||||
MINOR=${VERSION_PARTS[1]}
|
||||
PATCH=${VERSION_PARTS[2]}
|
||||
|
||||
NEW_PATCH=$((PATCH + 1))
|
||||
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
|
||||
|
||||
echo "New package.json version: $NEW_VERSION"
|
||||
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
||||
|
||||
node -e "
|
||||
const fs = require('fs');
|
||||
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
|
||||
packageJson.version = '$NEW_VERSION';
|
||||
fs.writeFileSync('./package.json', JSON.stringify(packageJson, null, 2) + '\n');
|
||||
"
|
||||
|
||||
- name: Create and push tag
|
||||
if: steps.check_changes.outputs.changes == 'true'
|
||||
run: |
|
||||
git config --local user.email "action@github.com"
|
||||
git config --local user.name "GitHub Action"
|
||||
git add src/idJson.json package.json
|
||||
git commit -m "chore: update idJson to ${{ steps.get_version.outputs.version }}"
|
||||
|
||||
TAG_NAME="v${{ steps.bump_version.outputs.new_version }}"
|
||||
git tag $TAG_NAME
|
||||
|
||||
git push
|
||||
git push origin $TAG_NAME
|
||||
|
||||
echo "Created and pushed tag: $TAG_NAME"
|
@@ -3,12 +3,7 @@ import json
|
||||
from opencc import OpenCC
|
||||
|
||||
# 初始化 OpenCC 转换器
|
||||
cc = OpenCC('s2t')
|
||||
|
||||
# 获取 JSON 数据
|
||||
weapon_url = 'https://api.hakush.in/hsr/data/lightcone.json'
|
||||
character_url = 'https://api.hakush.in/hsr/data/character.json'
|
||||
version_url = 'https://api.hakush.in/hsr/new.json'
|
||||
cc = OpenCC("s2t")
|
||||
|
||||
# 语言映射配置
|
||||
language_map = {
|
||||
@@ -16,41 +11,65 @@ language_map = {
|
||||
"zh-tw": "cn", # 简体转繁体
|
||||
"en-us": "en",
|
||||
"ja-jp": "jp",
|
||||
"ko-kr": "kr"
|
||||
"ko-kr": "kr",
|
||||
}
|
||||
|
||||
# 类型映射配置
|
||||
type_map = {
|
||||
"weapon": {"zh-cn": "光锥", "zh-tw": "光錐", "en-us": "Light Cone", "ja-jp": "光円錐", "ko-kr": "무기"},
|
||||
"character": {"zh-cn": "角色", "zh-tw": "角色", "en-us": "Character", "ja-jp": "キャラ", "ko-kr": "캐릭터"}
|
||||
"weapon": {
|
||||
"zh-cn": "光锥",
|
||||
"zh-tw": "光錐",
|
||||
"en-us": "Light Cone",
|
||||
"ja-jp": "光円錐",
|
||||
"ko-kr": "무기",
|
||||
},
|
||||
"character": {
|
||||
"zh-cn": "角色",
|
||||
"zh-tw": "角色",
|
||||
"en-us": "Character",
|
||||
"ja-jp": "キャラ",
|
||||
"ko-kr": "캐릭터",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def fetch_json(url):
|
||||
response = requests.get(url)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
|
||||
def transform_data(data, item_type):
|
||||
transformed = {lang: {} for lang in language_map.keys()}
|
||||
for id, item in data.items():
|
||||
for lang, key in language_map.items():
|
||||
name = item[key] if lang != 'zh-tw' else cc.convert(item['cn'])
|
||||
name = item[key] if lang != "zh-tw" else cc.convert(item["cn"])
|
||||
transformed[lang][id] = {
|
||||
"name": name,
|
||||
"item_type": type_map[item_type][lang],
|
||||
"rank_type": item['rank'][-1]
|
||||
"rank_type": item["rank"][-1],
|
||||
}
|
||||
return transformed
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
weapon_data = fetch_json(weapon_url)
|
||||
character_data = fetch_json(character_url)
|
||||
version_url = "https://api.hakush.in/hsr/new.json"
|
||||
version_data = fetch_json(version_url)
|
||||
|
||||
latest_version = ".".join(version_data["version"].split(".")[:2])
|
||||
print(f"Latest version: {latest_version}")
|
||||
|
||||
weapon_url = f"https://api.hakush.in/hsr/{latest_version}/lightcone.json"
|
||||
character_url = f"https://api.hakush.in/hsr/{latest_version}/character.json"
|
||||
weapon_data = fetch_json(weapon_url)
|
||||
print("Fetched", len(weapon_data), "lightcones")
|
||||
character_data = fetch_json(character_url)
|
||||
print("Fetched", len(character_data), "characters")
|
||||
|
||||
transformed_data = {lang: {} for lang in language_map.keys()}
|
||||
|
||||
transformed_data["version"] = version_data["version"]
|
||||
transformed_data["version"] = latest_version
|
||||
|
||||
weapon_transformed = transform_data(weapon_data, "weapon")
|
||||
character_transformed = transform_data(character_data, "character")
|
||||
@@ -59,13 +78,12 @@ def main():
|
||||
transformed_data[lang].update(weapon_transformed[lang])
|
||||
transformed_data[lang].update(character_transformed[lang])
|
||||
|
||||
with open('./src/idJson.json', 'w', encoding='utf-8') as f:
|
||||
with open("./src/idJson.json", "w", encoding="utf-8") as f:
|
||||
json.dump(transformed_data, f, ensure_ascii=False, indent=2)
|
||||
|
||||
print("Data successfully transformed and saved")
|
||||
|
||||
except requests.RequestException as e:
|
||||
print(f"Error fetching data: {e}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Reference in New Issue
Block a user