Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: "<!-- MODS_NUMBER_CI_START -->" | ||
END_TAG: "<!-- MODS_NUMBER_CI_END -->" | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters