commit 92bd08a5c657afdc372392d3953f636b7562d2b7 Author: denglihong2007 <98096191+denglihong2007@users.noreply.github.com> Date: Sat Jul 19 21:40:52 2025 +0800 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. diff --git a/.github/workflows/post.yml b/.github/workflows/post.yml new file mode 100644 index 0000000..17de159 --- /dev/null +++ b/.github/workflows/post.yml @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4a363dc --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +output.zip diff --git a/plugins/CRSim.ExamplePlugin.crsp b/plugins/CRSim.ExamplePlugin.crsp new file mode 100644 index 0000000..bf84165 Binary files /dev/null and b/plugins/CRSim.ExamplePlugin.crsp differ diff --git a/tools/MakePackage.py b/tools/MakePackage.py new file mode 100644 index 0000000..36d0044 --- /dev/null +++ b/tools/MakePackage.py @@ -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() diff --git a/tools/PostPackage.py b/tools/PostPackage.py new file mode 100644 index 0000000..0e9893e --- /dev/null +++ b/tools/PostPackage.py @@ -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)