diff --git a/.github/scripts/mods_counter.py b/.github/scripts/mods_counter.py new file mode 100644 index 00000000..daffc3a6 --- /dev/null +++ b/.github/scripts/mods_counter.py @@ -0,0 +1,42 @@ +import os +import sys +import json +from pathlib import Path + +def loadJsonFile(filePath: str): + try: + with open(filePath, "r", encoding="utf8") as f: + data = json.load(f) + return data + except (FileNotFoundError, json.JSONDecodeError) as e: + print(f"讀取 JSON 檔案時發生錯誤: {e}") + sys.exit(1) + +def list_subfolder(root_folder): + subfolders = [] + + for dir in os.listdir(root_folder): + dir_path = Path(root_folder, dir) + if os.path.isdir(dir_path): + subfolders.append(dir) + + return subfolders + +def main(versions_dict): + mods = set() + for platform in versions_dict["supported_platform"]: + for version in versions_dict["versions"]: + dir_path = Path("MultiVersions", platform, version["dir_path"]) + if os.path.isdir(dir_path): + mods.update(list_subfolder(dir_path)) + + # 移除 Sodium & Sodium Extra,這些來自 Crowdin + mods.remove("sodium") + mods.remove("sodium-extra") + + return len(mods) + +if __name__ == "__main__": + versions_dict = loadJsonFile(".github/configs/versions.json") + mod_number = main(versions_dict) + print(mod_number) diff --git a/.github/workflows/CI-ModsCounter.yml b/.github/workflows/CI-ModsCounter.yml new file mode 100644 index 00000000..8f0b34db --- /dev/null +++ b/.github/workflows/CI-ModsCounter.yml @@ -0,0 +1,58 @@ +name: CI | Mods Counter + +on: + workflow_dispatch: {} + push: + branches: + - "main" + +permissions: + contents: write + pull-requests: write + +jobs: + mods-counter: + name: Mods Counter Update + runs-on: ubuntu-latest + if: | + github.repository == 'xMikux/ModsTranslationPack' + + steps: + - name: Checking Repository + uses: actions/checkout@v3 + + - name: Count Mods + id: mods + run: | + NUMBER=$(python .github/scripts/mods_counter.py) + echo "number=$NUMBER" >> "$GITHUB_OUTPUT" + + - name: Update Readme + run: | + python .github/scripts/content_replacer.py + env: + FILE_PATH: "README.md" + MULTILINE_MODE: False + START_TAG: "" + END_TAG: "" + CONTENT: "${{ steps.mods.outputs.number }}" + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v5 + with: + committer: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> + author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> + title: "docs(Readme): 更新模組數量" + commit-message: "docs(Readme): 更新模組數量" + branch: docs/mod-counter-readme + labels: | + 📃 文件 + add-paths: README.md + body: | + 自動化 [GitHub Action][github-action] 工作流程! + + ------ + 由 [create-pull-request][cpr] 自動產生 + + [cpr]: https://github.com/peter-evans/create-pull-request + [github-action]: https://github.com/features/actions diff --git a/README.md b/README.md index 8e2eccc5..d7511fc2 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ [![Stars][repo-stars]][github]

一個包含了各式各樣的模組翻譯的資源包~

-

目前已收錄 320 款模組

+

目前已收錄 320 款模組