Skip to content

Commit

Permalink
ci: 新增模組數更新工作流程
Browse files Browse the repository at this point in the history
  • Loading branch information
xMikux committed Aug 25, 2023
1 parent 32324e9 commit 835c853
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 1 deletion.
42 changes: 42 additions & 0 deletions .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)
58 changes: 58 additions & 0 deletions .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: "<!-- 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
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -15,7 +15,7 @@
[![Stars][repo-stars]][github]

<h3>一個包含了各式各樣的模組翻譯的資源包~</h3>
<h3>目前已收錄 <code>320</code> 款模組</h3>
<h3>目前已收錄 <code><!-- MODS_NUMBER_CI_START -->320<!-- MODS_NUMBER_CI_END --></code> 款模組</h3>

</div>

Expand Down

0 comments on commit 835c853

Please sign in to comment.