This commit is contained in:
恍兮惚兮 2024-04-26 17:18:10 +08:00
parent 0506e28711
commit 0479f53859
3 changed files with 71 additions and 58 deletions

View File

@ -9,7 +9,14 @@ on:
jobs: jobs:
build: build:
runs-on: windows-latest runs-on: windows-latest
if: startsWith(github.ref, 'refs/tags/v') != true strategy:
# 矩阵配置
matrix:
include:
- architecture: x86
fname: LunaTranslator_x86.zip
- architecture: x64
fname: LunaTranslator.zip
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
@ -17,30 +24,24 @@ jobs:
uses: GuillaumeFalourd/setup-windows10-sdk-action@v2 uses: GuillaumeFalourd/setup-windows10-sdk-action@v2
with: with:
sdk-version: 22621 sdk-version: 22621
- name: Install Python 3.7.9 x86 - name: Install Python 3.7.9
uses: actions/setup-python@v5 uses: actions/setup-python@v5
with: with:
python-version: '3.7.9' python-version: '3.7.9'
architecture: x86 architecture: ${{ matrix.architecture }}
- name: Install Python 3.7.9 x64 - name: Install Python 3.11
uses: actions/setup-python@v5 uses: actions/setup-python@v5
with: with:
python-version: '3.7.9' python-version: '3.11'
architecture: x64 architecture: x64
- name: Install Python 3.11.7 - name: Install Python 3.11 req
uses: actions/setup-python@v5 run: |
with: pip install --upgrade pip
python-version: '3.11.7' pip install cmake pefile requests
- name: Run build script - name: Run build script
run: | run: |
python build.py --github-actions python build.py --github-actions --arch ${{ matrix.architecture }}
- name: Upload LunaTranslator artifact x86 - uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v4
with: with:
name: LunaTranslator_x86 name: ${{ matrix.fname }}
path: build/LunaTranslator_x86.zip path: build/${{ matrix.fname }}
- name: Upload LunaTranslator artifact x64
uses: actions/upload-artifact@v4
with:
name: LunaTranslator
path: build/LunaTranslator.zip

View File

@ -11,6 +11,14 @@ on:
jobs: jobs:
build: build:
runs-on: windows-latest runs-on: windows-latest
strategy:
# 矩阵配置
matrix:
include:
- architecture: x86
fname: LunaTranslator_x86.zip
- architecture: x64
fname: LunaTranslator.zip
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
@ -18,30 +26,32 @@ jobs:
uses: GuillaumeFalourd/setup-windows10-sdk-action@v2 uses: GuillaumeFalourd/setup-windows10-sdk-action@v2
with: with:
sdk-version: 22621 sdk-version: 22621
- name: Install Python 3.7.9 x86 - name: Install Python 3.7.9
uses: actions/setup-python@v5 uses: actions/setup-python@v5
with: with:
python-version: '3.7.9' python-version: '3.7.9'
architecture: x86 architecture: ${{ matrix.architecture }}
- name: Install Python 3.7.9 x64 - name: Install Python 3.11
uses: actions/setup-python@v5 uses: actions/setup-python@v5
with: with:
python-version: '3.7.9' python-version: '3.11'
architecture: x64
- name: Install Python 3.11.7
uses: actions/setup-python@v5
with:
python-version: '3.11.7'
architecture: x64 architecture: x64
- name: Install Python 3.11 req
run: |
pip install --upgrade pip
pip install cmake pefile requests
- name: Run build script - name: Run build script
run: | run: |
python build.py --github-actions python build.py --github-actions --arch ${{ matrix.architecture }}
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.fname }}
path: build/${{ matrix.fname }}
- name: Release LunaTranslator - name: Release LunaTranslator
uses: softprops/action-gh-release@v2 uses: softprops/action-gh-release@v2
with: with:
tag_name: ${{ github.event.inputs.create_release }} tag_name: ${{ github.event.inputs.create_release }}
files: | files: build/${{ matrix.fname }}
build/LunaTranslator_x86.zip
build/LunaTranslator.zip
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -2,16 +2,13 @@ import argparse
import os import os
import shutil,json import shutil,json
import subprocess import subprocess
import requests
py37Path32 = os.path.join( py37Path32 = os.path.join(
os.environ["LOCALAPPDATA"], "Programs\\Python\\Python37-32\\python.exe" os.environ["LOCALAPPDATA"], "Programs\\Python\\Python37-32\\python.exe"
) )
py37Path64 = os.path.join( py37Path64 = os.path.join(
os.environ["LOCALAPPDATA"], "Programs\\Python\\Python37\\python.exe" os.environ["LOCALAPPDATA"], "Programs\\Python\\Python37\\python.exe"
) )
py311Path = os.path.join(
os.environ["LOCALAPPDATA"], "Programs\\Python\\Python311\\python.exe"
)
msbuildPath = "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\MSBuild\\Current\\Bin\\MSBuild.exe" msbuildPath = "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\MSBuild\\Current\\Bin\\MSBuild.exe"
vcvars32Path = "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Auxiliary\\Build\\vcvars32.bat" vcvars32Path = "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Auxiliary\\Build\\vcvars32.bat"
vcvars64Path = "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Auxiliary\\Build\\vcvars64.bat" vcvars64Path = "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Auxiliary\\Build\\vcvars64.bat"
@ -53,16 +50,18 @@ def createPluginDirs():
os.mkdir(pluginDir) os.mkdir(pluginDir)
def installDependencies(): def installDependencies(arch):
os.chdir(rootDir) os.chdir(rootDir)
subprocess.run(f"{py37Path32} -m pip install --upgrade pip") if arch=='x86':
subprocess.run(f"{py37Path64} -m pip install --upgrade pip") subprocess.run(f"{py37Path32} -m pip install --upgrade pip")
subprocess.run(f"{py311Path} -m pip install --upgrade pip") else:
subprocess.run(f"{py37Path64} -m pip install --upgrade pip")
os.chdir(rootDir + "\\LunaTranslator") os.chdir(rootDir + "\\LunaTranslator")
subprocess.run(f"{py37Path32} -m pip install -r requirements.txt") if arch=='x86':
subprocess.run(f"{py37Path64} -m pip install -r requirements.txt") subprocess.run(f"{py37Path32} -m pip install -r requirements.txt")
subprocess.run(f"{py311Path} -m pip install cmake pefile") else:
subprocess.run(f"{py37Path64} -m pip install -r requirements.txt")
def installVCLTL(): def installVCLTL():
@ -173,7 +172,7 @@ def downloadOCRModel(locale):
def buildLunaHook(): def buildLunaHook():
for ass in json.loads(subprocess.run('curl -s https://api.github.com/repos/HIllya51/LunaHook/releases/latest',stdout=subprocess.PIPE).stdout.decode('utf8'))['assets']: for ass in requests.get('https://api.github.com/repos/HIllya51/LunaHook/releases/latest').json()['assets']:
if ass['name']=='Release_English.zip': if ass['name']=='Release_English.zip':
os.chdir(rootDir + "\\temp") os.chdir(rootDir + "\\temp")
subprocess.run(f"curl -LO {ass['browser_download_url']}") subprocess.run(f"curl -LO {ass['browser_download_url']}")
@ -213,16 +212,18 @@ def buildPlugins():
subprocess.run(f"python copytarget.py 0") subprocess.run(f"python copytarget.py 0")
def buildLunaTranslator(): def buildLunaTranslator(arch):
os.chdir(rootDir + "\\LunaTranslator") os.chdir(rootDir + "\\LunaTranslator")
subprocess.run( if arch=='x86':
f"{py37Path32} -m nuitka --standalone --assume-yes-for-downloads --windows-disable-console --plugin-enable=pyqt5 --output-dir=..\\build\\x86 LunaTranslator\\LunaTranslator_main.py --windows-icon-from-ico=..\\plugins\\exec\\luna.ico" subprocess.run(
) f"{py37Path32} -m nuitka --standalone --assume-yes-for-downloads --windows-disable-console --plugin-enable=pyqt5 --output-dir=..\\build\\x86 LunaTranslator\\LunaTranslator_main.py --windows-icon-from-ico=..\\plugins\\exec\\luna.ico"
subprocess.run( )
f"{py37Path64} -m nuitka --standalone --assume-yes-for-downloads --windows-disable-console --plugin-enable=pyqt5 --output-dir=..\\build\\x64 LunaTranslator\\LunaTranslator_main.py --windows-icon-from-ico=..\\plugins\\exec\\luna.ico" subprocess.run(f"cmd /c pack32.cmd")
) else:
subprocess.run(f"cmd /c pack32.cmd") subprocess.run(
subprocess.run(f"cmd /c pack64.cmd") f"{py37Path64} -m nuitka --standalone --assume-yes-for-downloads --windows-disable-console --plugin-enable=pyqt5 --output-dir=..\\build\\x64 LunaTranslator\\LunaTranslator_main.py --windows-icon-from-ico=..\\plugins\\exec\\luna.ico"
)
subprocess.run(f"cmd /c pack64.cmd")
if __name__ == "__main__": if __name__ == "__main__":
@ -266,6 +267,9 @@ if __name__ == "__main__":
default=False, default=False,
help="Specify if running in a GitHub Actions environment", help="Specify if running in a GitHub Actions environment",
) )
parser.add_argument(
"--arch",
)
args = parser.parse_args() args = parser.parse_args()
@ -283,11 +287,9 @@ if __name__ == "__main__":
if args.github_actions: if args.github_actions:
py37Path32 = "C:\\hostedtoolcache\\windows\\Python\\3.7.9\\x86\\python.exe" py37Path32 = "C:\\hostedtoolcache\\windows\\Python\\3.7.9\\x86\\python.exe"
py37Path64 = "C:\\hostedtoolcache\\windows\\Python\\3.7.9\\x64\\python.exe" py37Path64 = "C:\\hostedtoolcache\\windows\\Python\\3.7.9\\x64\\python.exe"
py311Path = "C:\\hostedtoolcache\\windows\\Python\\3.11.7\\x64\\python.exe"
if not args.skip_python_dependencies: if not args.skip_python_dependencies:
installDependencies() installDependencies(args.arch)
if not args.skip_download: if not args.skip_download:
downloadBrotli() downloadBrotli()
downloadLocaleEmulator() downloadLocaleEmulator()
@ -300,4 +302,4 @@ if __name__ == "__main__":
if not args.skip_vc_ltl: if not args.skip_vc_ltl:
installVCLTL() installVCLTL()
buildPlugins() buildPlugins()
buildLunaTranslator() buildLunaTranslator(args.arch)