Skip to content

Commit 0dd4f6c

Browse files
committed
build: implement GitHub Actions workflow for building and releasing
- Add GitHub Actions workflow file for automated builds and releases - Create build script to compile the project using PyInstaller - Update project files to support the new build process - Modify requirements to include pywin32 - Refactor maa_runner.py to use threads instead of multiprocessing - Update main.py to use a dictionary for mode selection - Simplify model.py by removing multiprocessing-related code
1 parent 02113c1 commit 0dd4f6c

8 files changed

Lines changed: 141 additions & 8 deletions

File tree

.github/workflows/build.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Build and Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
workflow_dispatch:
8+
9+
jobs:
10+
build:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
os: [windows-2022]
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v2
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v4
24+
with:
25+
python-version: "3.11"
26+
cache: "pip"
27+
28+
- name: Install dependencies
29+
run: |
30+
python -m pip install --upgrade pip
31+
pip install -r requirements.txt
32+
33+
- name: Run build script
34+
run: |
35+
pip install pyinstaller
36+
python build.py --os ${{ runner.os }} --arch ${{ runner.arch }}
37+
38+
- name: Generate Changelog
39+
run: |
40+
python -m pip install evative7-changeloggen
41+
changelog .
42+
43+
- name: Create Release
44+
uses: softprops/action-gh-release@v2
45+
if: startsWith(github.ref, 'refs/tags/')
46+
with:
47+
body_path: CHANGELOG.md
48+
files: |
49+
dist/**

build.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# EvATive7 forked from github.com/TanyaShue/MaaYYs
2+
# Copyright: TanyaShue
3+
4+
import argparse
5+
import os
6+
import shutil
7+
import sys
8+
import zipfile
9+
10+
import PyInstaller.__main__
11+
12+
parser = argparse.ArgumentParser()
13+
# parser.add_argument( "--version", type=str, help="Specify the version of the script", default="none")
14+
parser.add_argument(
15+
"--os",
16+
type=str,
17+
help="Specify the operating system on which the building is running",
18+
default="none",
19+
)
20+
parser.add_argument(
21+
"--arch",
22+
type=str,
23+
help="Specify the arch on which the building is running",
24+
default="none",
25+
)
26+
args = parser.parse_args()
27+
ZIP_FILENAME = f"akhcli_{args.os}_{args.arch}.zip"
28+
29+
30+
# 获取当前工作目录
31+
current_dir = os.getcwd()
32+
33+
34+
# 复制 assets 文件夹到 dist 目录
35+
dist_dir = os.path.join(current_dir, "dist")
36+
37+
# 如果目标路径存在,先删除它
38+
if os.path.exists(dist_dir):
39+
shutil.rmtree(dist_dir)
40+
41+
# 运行 PyInstaller 打包命令
42+
command = [
43+
"src/main.py",
44+
"--onefile",
45+
"--name=akhcli.exe",
46+
# "--clean",
47+
]
48+
if sys.platform == "win32":
49+
command.append(
50+
f'--add-binary={os.path.join(current_dir, "misc", "windows", "dll", "msvcp140.dll")}{os.pathsep}.'
51+
)
52+
command.append(
53+
f'--add-binary={os.path.join(current_dir, "misc", "windows", "dll", "vcruntime140.dll")}{os.pathsep}.'
54+
)
55+
56+
print(" ".join(command))
57+
PyInstaller.__main__.run(command)
58+
59+
60+
# 压缩 dist 文件夹为 zip 文件,并保存在 dist 目录中
61+
zip_filepath = os.path.join(dist_dir, ZIP_FILENAME)
62+
63+
with zipfile.ZipFile(zip_filepath, "w", zipfile.ZIP_DEFLATED) as zipf:
64+
for root, dirs, files in os.walk(dist_dir):
65+
for file in files:
66+
# 获取文件的绝对路径并相对路径
67+
file_path = os.path.join(root, file)
68+
# 跳过刚生成的压缩包
69+
if file == ZIP_FILENAME:
70+
continue
71+
arcname = os.path.relpath(file_path, dist_dir)
72+
zipf.write(file_path, arcname)
73+
74+
# 删除 dist 文件夹中的所有文件和文件夹,保留压缩包
75+
for root, dirs, files in os.walk(dist_dir):
76+
for file in files:
77+
file_path = os.path.join(root, file)
78+
# 不删除生成的压缩包
79+
if file != ZIP_FILENAME:
80+
os.remove(file_path)
81+
for dir in dirs:
82+
shutil.rmtree(os.path.join(root, dir), ignore_errors=True)
83+
84+
print(f"Packaging and compression completed: {zip_filepath}")

misc/windows/dll/msvcp140.dll

562 KB
Binary file not shown.

misc/windows/dll/vcruntime140.dll

127 KB
Binary file not shown.

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ indent-concluder>=1.1.3
88
fake-useragent
99
easywebhooker
1010
bs4
11-
pre-commit
11+
pre-commit
12+
pywin32

src/maa_runner.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import copy
22
import logging
3-
import multiprocessing
43
import time
54
from dataclasses import dataclass
5+
from threading import Thread
66

77
import easywebhooker
88
from indent_concluder import Item as ConcluderItem
@@ -64,7 +64,7 @@ def run():
6464
@dataclass
6565
class DeviceStatus:
6666
device: Device
67-
process: multiprocessing.Process | None
67+
process: Thread | None
6868
process_static_params: dict | None
6969
process_shared_status: dict | None
7070
finished: bool
@@ -148,8 +148,8 @@ def no_task():
148148
"task": distribute_task,
149149
"device": status.device,
150150
}
151-
process_shared_status = multiprocessing.Manager().dict()
152-
process = multiprocessing.Process(
151+
process_shared_status = {}
152+
process = threading.Thread(
153153
target=start_task_process,
154154
args=(
155155
process_static_params,

src/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
logging.debug(f"With personal config {var.personal_configs}")
1414

1515
try:
16-
entrance = locals()[mode]
16+
entrance = {m.__name__: m for m in [run, test]}[mode]
1717
if var.verbose and False:
1818
run_with_LineProfiler(entrance)
1919
else:

src/model.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import json
22
import logging
3-
import multiprocessing
43
import os
54
import pathlib
65
import threading
@@ -83,7 +82,7 @@ def __init__(self, dev_config) -> None:
8382
self.kill_after_end = dev_config.get("kill_after_end", True)
8483
self._process = dev_config.get("process")
8584
self.logger = logging.getLogger(str(self))
86-
self.current_status = multiprocessing.Manager().dict()
85+
self.current_status = {}
8786
self.current_status["server"] = None
8887
self.adb = ADB(self.addr)
8988

0 commit comments

Comments
 (0)