generated from MaaXYZ/MaaPracticeBoilerplate
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from Night-stars-1/main
feat: 添加资源包构建
- Loading branch information
Showing
4 changed files
with
81 additions
and
0 deletions.
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,33 @@ | ||
name: res_build | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
update: | ||
name: Update Map | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@master | ||
|
||
- name: Setup python | ||
uses: actions/setup-python@v5.2.0 | ||
with: | ||
python-version: 3.9 | ||
|
||
- name: RES ZIP | ||
run: | | ||
python res_zip.py | ||
- name: Commit changes | ||
uses: EndBug/add-and-commit@v9.1.3 | ||
with: | ||
author_name: github-actions[bot] | ||
author_email: github-actions[bot]@users.noreply.github.com | ||
message: ':wrench: 自动构建资源包' | ||
add: | | ||
'res.zip' | ||
'version.txt' |
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,47 @@ | ||
import os | ||
import subprocess | ||
import zipfile | ||
|
||
# 压缩包名称 | ||
zip_filename = 'res.zip' | ||
|
||
def add_folder_to_zip(zipf: zipfile.ZipFile, folder_path: str): | ||
""" | ||
将指定文件夹添加到 ZIP 文件中,同时保持目录结构 | ||
:param zipf: zipfile.ZipFile 对象 | ||
:param folder_path: 要添加到 ZIP 文件中的文件夹路径 | ||
""" | ||
for foldername, subfolders, filenames in os.walk(folder_path): | ||
for filename in filenames: | ||
file_path = os.path.join(foldername, filename) | ||
# 在 ZIP 文件中创建相对路径 | ||
relative_path = file_path.replace(r"assets\resource\base", "") | ||
zipf.write(file_path, relative_path) | ||
|
||
def get_git_commit_count(): | ||
""" | ||
获取仓库的提交总数 | ||
:param repo_path: 仓库路径,默认为当前路径 | ||
:return: 提交总数,如果获取失败则返回空字符串 | ||
""" | ||
try: | ||
# 执行 Git 命令获取提交总数 | ||
result = subprocess.run( | ||
['git', 'rev-list', '--count', 'HEAD'], | ||
text=True, | ||
capture_output=True, | ||
check=True | ||
) | ||
# 返回提交总数 | ||
return result.stdout.strip() | ||
except subprocess.CalledProcessError as e: | ||
print(f"获取提交数失败: {e}") | ||
return '' | ||
|
||
# 创建压缩包并添加文件 | ||
with zipfile.ZipFile(zip_filename, 'w', zipfile.ZIP_DEFLATED) as zipf: | ||
add_folder_to_zip(zipf, r'assets\resource\base\pipeline') | ||
add_folder_to_zip(zipf, r'assets\resource\base\image') | ||
|
||
with open('version.txt', 'w', encoding='utf-8') as f: | ||
f.write(get_git_commit_count()) |
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 @@ | ||
1 |