Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdWindScholar committed Dec 3, 2023
1 parent 6151741 commit 945d878
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 0 deletions.
86 changes: 86 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: "Build Tool"
permissions:
contents: write
discussions: write
on:
push:
paths:
- "build.py"
pull_request:
workflow_dispatch:
jobs:
build:
needs: [build-win,build-linux]
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
- name: Rename Tool
run: |
cd Magisk_Patch-win
move ./Magisk_Patch-win.zip ../Magisk_Patch-${{ github.run_number }}-win.zip
cd ..
cd Magisk_Patch-linux
ls
move ./Magisk_Patch-linux.zip ../Magisk_Patch-${{ github.run_number }}-linux.zip
cd ..
- name: Upload release
uses: ncipollo/release-action@v1
with:
allowUpdates: true
omitBodyDuringUpdate: true
removeArtifacts: true
name: "Magisk_Patch-${{ github.run_number }}"
tag: "CI_BUILD_${{ github.run_number }}"
body: |
Build times: ${{ github.run_number }}
Note:If u cannot run it in linux,you may need do "chmod a+x ./*"
Minimum support: Ubuntu 20.04 (64bit),Windows Vista (32bit)
artifacts: "*.zip"

build-win:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.8.10
uses: actions/setup-python@v4
with:
# Semantic version range syntax or exact version of a Python version
python-version: '3.8.10'
# Optional - x64 or x86 architecture, defaults to x64
architecture: 'x86'
# You can test your matrix by printing the current Python version
- name: Update pip
run: python -m pip install -U --force-reinstall pip
- name: Build tool
run: |
python build.py
- name: Upload Win Build
if: success()
uses: actions/upload-artifact@v3
with:
name: Magisk_Patch-win
path: './Magisk_Patch-win.zip'
build-linux:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
# Semantic version range syntax or exact version of a Python version
python-version: '3.10'
# Optional - x64 or x86 architecture, defaults to x64
- name: Install Packages
run: |
python3 -m pip install -U --force-reinstall pip
sudo apt update -y && sudo apt install python3-tk -y
- name: Build Tool
run: |
python3 build.py
- name: Upload Linux Build
if: success()
uses: actions/upload-artifact@v3
with:
name: Magisk_Patch-linux
path: './Magisk_Patch-linux.zip'
81 changes: 81 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import os
import platform
import shutil
import zipfile


print(f'Build for {platform.system()}')
from pip._internal.cli.main import main as _main
_main(['install', 'pyinstaller'])
local = os.getcwd()
if platform.system() == 'Linux':
name = 'Magisk_Patch-linux.zip'
else:
name = 'Magisk_Patch-win.zip'


def zip_folder(folder_path):
# 获取文件夹的绝对路径和文件夹名称
abs_folder_path = os.path.abspath(folder_path)

# 创建一个同名的zip文件
zip_file_path = os.path.join(local, name)
archive = zipfile.ZipFile(zip_file_path, "w", zipfile.ZIP_DEFLATED)

# 遍历文件夹中的所有文件和子文件夹
for root, dirs, files in os.walk(abs_folder_path):
for file in files:
if file == name:
continue
file_path = os.path.join(root, file)
if ".git" in file_path:
continue
print(f"Adding: {file_path}")
# 将文件添加到zip文件中
archive.write(file_path, os.path.relpath(file_path, abs_folder_path))

# 关闭zip文件
archive.close()
print(f"Done!")


import PyInstaller.__main__

PyInstaller.__main__.run(['-F', 'patch.py', '--exclude-module=numpy'])

if os.name == 'nt':
if os.path.exists(local + os.sep + "dist" + os.sep + "patch.exe"):
shutil.move(local + os.sep + "dist" + os.sep + "patch.exe", local)
if os.path.exists(local + os.sep + "bin" + os.sep + "Linux"):
shutil.rmtree(local + os.sep + "bin" + os.sep + "Linux")
elif os.name == 'posix':
if os.path.exists(local + os.sep + "dist" + os.sep + "patch"):
shutil.move(local + os.sep + "dist" + os.sep + "patch", local)
if os.path.exists(local + os.sep + "bin" + os.sep + "Windows"):
shutil.rmtree(local + os.sep + "bin" + os.sep + "Windows")
for i in os.listdir(local + os.sep + "bin" + os.sep + "Linux"):
if i == platform.machine():
continue
shutil.rmtree(local + os.sep + "bin" + os.sep + "Linux" + os.sep + i)
for i in os.listdir(local):
if i not in ['patch', 'patch.exe', 'bin', 'LICENSE']:
print(f"Removing {i}")
if os.path.isdir(local + os.sep + i):
try:
shutil.rmtree(local + os.sep + i)
except Exception or OSError as e:
print(e)
elif os.path.isfile(local + os.sep + i):
try:
os.remove(local + os.sep + i)
except Exception or OSError as e:
print(e)
else:
print(i)
if os.name == 'posix':
for root, dirs, files in os.walk(local, topdown=True):
for i in files:
print(f"Chmod {os.path.join(root, i)}")
os.system(f"chmod a+x {os.path.join(root, i)}")

zip_folder(".")

0 comments on commit 945d878

Please sign in to comment.