mirror of
https://github.com/denglihong2007/CRSim-PluginRepository
synced 2026-05-12 22:22:11 +08:00
Add MakePackage and PostPackage scripts for plugin management
- Implement MakePackage.py to package plugins and their icons into a zip file and generate a JSON manifest. - Create PostPackage.py to upload the generated zip file to a specified server using an API. - Clean up old icons and JSON files before packaging. - Use environment variables for deployment URL and token.
This commit is contained in:
26
.github/workflows/post.yml
vendored
Normal file
26
.github/workflows/post.yml
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
name: Deploy
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: '3.10'
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
pip install requests
|
||||
pip install pyyaml
|
||||
- name: Run deploy script
|
||||
env:
|
||||
DEPLOY_URL: ${{ secrets.DEPLOY_URL }}
|
||||
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
|
||||
run: |
|
||||
python tools/MakePackage.py
|
||||
python tools/PostPackage.py
|
||||
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
output.zip
|
||||
BIN
plugins/CRSim.ExamplePlugin.crsp
Normal file
BIN
plugins/CRSim.ExamplePlugin.crsp
Normal file
Binary file not shown.
64
tools/MakePackage.py
Normal file
64
tools/MakePackage.py
Normal file
@@ -0,0 +1,64 @@
|
||||
import os
|
||||
import zipfile
|
||||
import shutil
|
||||
import json
|
||||
import yaml
|
||||
|
||||
def main():
|
||||
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
plugins_dir = os.path.join(base_dir, "plugins")
|
||||
icons_dir = os.path.join(base_dir, "icons")
|
||||
output_json = os.path.join(base_dir, "plugins.json")
|
||||
output_zip = os.path.join(base_dir, "output.zip")
|
||||
|
||||
# 清理旧icons目录和json
|
||||
if os.path.exists(icons_dir):
|
||||
shutil.rmtree(icons_dir)
|
||||
os.makedirs(icons_dir, exist_ok=True)
|
||||
if os.path.exists(output_json):
|
||||
os.remove(output_json)
|
||||
if os.path.exists(output_zip):
|
||||
os.remove(output_zip)
|
||||
|
||||
manifests = []
|
||||
for fname in os.listdir(plugins_dir):
|
||||
if fname.endswith(".crsp"):
|
||||
crsp_path = os.path.join(plugins_dir, fname)
|
||||
with zipfile.ZipFile(crsp_path, "r") as zf:
|
||||
# 读取manifest.yml
|
||||
with zf.open("manifest.yml") as mf:
|
||||
manifest = yaml.safe_load(mf)
|
||||
manifests.append(manifest)
|
||||
# 提取icon.png
|
||||
icon_name = os.path.splitext(fname)[0] + ".png"
|
||||
icon_out_path = os.path.join(icons_dir, icon_name)
|
||||
with zf.open("icon.png") as iconf, open(icon_out_path, "wb") as outf:
|
||||
shutil.copyfileobj(iconf, outf)
|
||||
|
||||
# 保存json
|
||||
with open(output_json, "w", encoding="utf-8") as jf:
|
||||
json.dump(manifests, jf, ensure_ascii=False, indent=2)
|
||||
|
||||
# 打包output.zip
|
||||
with zipfile.ZipFile(output_zip, "w", zipfile.ZIP_DEFLATED) as zf:
|
||||
# plugins目录
|
||||
for root, _, files in os.walk(plugins_dir):
|
||||
for file in files:
|
||||
fpath = os.path.join(root, file)
|
||||
arcname = os.path.relpath(fpath, base_dir)
|
||||
zf.write(fpath, arcname)
|
||||
# icons目录
|
||||
for root, _, files in os.walk(icons_dir):
|
||||
for file in files:
|
||||
fpath = os.path.join(root, file)
|
||||
arcname = os.path.relpath(fpath, base_dir)
|
||||
zf.write(fpath, arcname)
|
||||
# plugins.json
|
||||
zf.write(output_json, os.path.basename(output_json))
|
||||
|
||||
# 删除icons目录和json
|
||||
shutil.rmtree(icons_dir)
|
||||
os.remove(output_json)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
18
tools/PostPackage.py
Normal file
18
tools/PostPackage.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import requests
|
||||
import os
|
||||
|
||||
parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
zip_path = os.path.join(parent_dir, 'output.zip')
|
||||
|
||||
url = os.environ['DEPLOY_URL']
|
||||
token = os.environ.get('DEPLOY_TOKEN', '')
|
||||
|
||||
with open(zip_path, 'rb') as f:
|
||||
r = requests.post(
|
||||
url,
|
||||
files={'file': f},
|
||||
headers={'Authorization': f'Bearer {token}'}
|
||||
)
|
||||
|
||||
print(f"Server responded with status: {r.status_code}")
|
||||
print(r.text)
|
||||
Reference in New Issue
Block a user