Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

工作流:Release流程中MarkDown转为PDF后打包 #72

Merged
merged 36 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
259004a
Update BuildHelper.py
ACaiCat May 1, 2024
e738e70
Update dotnet.yml
ACaiCat May 1, 2024
d9b75b0
Update dotnet.yml
ACaiCat May 1, 2024
f53d66b
Update dotnet.yml
ACaiCat May 1, 2024
57ca24d
Update dotnet.yml
ACaiCat May 1, 2024
e31982d
Update dotnet.yml
ACaiCat May 1, 2024
53f01d4
Update dotnet.yml
ACaiCat May 1, 2024
657953e
Update dotnet.yml
ACaiCat May 1, 2024
1552325
Update BuildHelper.py
ACaiCat May 1, 2024
b3d3e94
Update BuildHelper.py
ACaiCat May 1, 2024
8f3f6aa
Update dotnet.yml
ACaiCat May 1, 2024
8b7b29d
Update BuildHelper.py
ACaiCat May 1, 2024
ffeb61b
Update dotnet.yml
ACaiCat May 1, 2024
081527f
Update BuildHelper.py
ACaiCat May 1, 2024
0b7d604
Update dotnet.yml
ACaiCat May 1, 2024
f764a55
Update BuildHelper.py
ACaiCat May 1, 2024
64ed8a0
Update dotnet.yml
ACaiCat May 1, 2024
912ae5d
Update BuildHelper.py
ACaiCat May 1, 2024
721baa4
Update BuildHelper.py
ACaiCat May 1, 2024
02aeb6f
Update BuildHelper.py
ACaiCat May 1, 2024
4bdefa8
Update BuildHelper.py
ACaiCat May 1, 2024
a6f848a
Update BuildHelper.py
ACaiCat May 1, 2024
af12148
Update BuildHelper.py
ACaiCat May 1, 2024
58c0d13
Update BuildHelper.py
ACaiCat May 1, 2024
35d00fd
Update dotnet.yml
ACaiCat May 1, 2024
33c3ae9
Update BuildHelper.py
ACaiCat May 1, 2024
a19e6c2
Update BuildHelper.py
ACaiCat May 1, 2024
8a1ae13
Update BuildHelper.py
ACaiCat May 1, 2024
d712833
Update BuildHelper.py
ACaiCat May 1, 2024
1d98468
Update BuildHelper.py
ACaiCat May 1, 2024
f8adce4
Update BuildHelper.py
ACaiCat May 1, 2024
0ef3269
Update BuildHelper.py
ACaiCat May 1, 2024
e7f1b6a
Update BuildHelper.py
ACaiCat May 1, 2024
85afa45
Update dotnet.yml
ACaiCat May 1, 2024
c28ac53
Update BuildHelper.py
ACaiCat May 1, 2024
9979f59
Update BuildHelper.py
ACaiCat May 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,19 @@ jobs:
with:
python-version: '3.x'

- name: Install Pandoc
run:
sudo apt-get install pandoc
env:
PYTHONIOENCODING: 'utf-8'

- name: Install TeX Live
run: |
sudo apt-get install -y texlive-xetex

- name: Package
run: python BuildHelper.py Release
run:
sudo python BuildHelper.py Release
env:
PYTHONIOENCODING: 'utf-8'

Expand Down
90 changes: 47 additions & 43 deletions BuildHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,60 @@
import shutil
import sys
import zipfile
print(f"😋😋😋打包脚本By Cai...")

build_type = sys.argv[1]
import urllib.request

def zip_files_in_folder(folder_path, zip_file_path):
# Create a ZipFile object in write mode
with zipfile.ZipFile(zip_file_path, 'w') as zipf:
# Iterate over each file in the folder
for foldername, subfolders, filenames in os.walk(folder_path):
for filename in filenames:
# Create the complete filepath by concatenating the folder and filename
file_path = os.path.join(foldername, filename)
# Add file to the zip file
# The arcname parameter is used to store the file without any folder structure
zipf.write(file_path, arcname=os.path.basename(file_path))
print(f"生成压缩包: {zip_file_path}")
print(f"📦 压缩包已生成: {zip_file_path}")

def md_to_pdf(file_name):
os.system(f"pandoc --pdf-engine=xelatex -V mainfont=LXGWWenKaiMono-Regular.ttf -V geometry:margin=0.5in --template eisvogel.tex {file_name} -o {file_name.replace('.md', '.pdf')}")

if __name__ == '__main__':
print(f"🚀 开始执行打包脚本...(By Cai 😋)")
build_type = sys.argv[1]
print(f"🗑️ 开始删除json文件...")
for file in glob.glob(os.path.join(f"out/{build_type}/", "*.json")):
os.remove(file)
print(f"✅ 已删除文件: {file}")
print("✅ json文件删除成功!")

print(f"😋开始删除json文件")
for file in glob.glob(os.path.join(f"out/{build_type}/", "*.json")):
os.remove(file)
print(f"删除文件: {file}")
print("(删除json文件成功~")
print("📝 开始移动README.md...")
cwd = os.getcwd()
for dir_name in os.listdir(cwd):
dir_path = os.path.join(cwd, dir_name)
if os.path.isdir(dir_path):
for file_name in os.listdir(dir_path):
try:
if file_name.endswith('.csproj'):
source_path = os.path.join(dir_path, 'README.md')
destination_path = os.path.join(cwd, 'out', f'{build_type}', file_name.replace('.csproj', '.md'))
shutil.copyfile(source_path, destination_path)
print(f"🔍 找到README.md({destination_path})")
except:
print(f"⚠️ README移动失败({file_name})")
print("✅ README.md移动成功!")

# Get the current working directory
print("😋开始移动README.md")
cwd = os.getcwd()
shutil.copyfile("README.md",f"out/{build_type}/README.md")
# Iterate over all directories in the current working directory
for dir_name in os.listdir(cwd):
dir_path = os.path.join(cwd, dir_name)
# Check if it is a directory
if os.path.isdir(dir_path):
# Iterate over all files in the directory
for file_name in os.listdir(dir_path):
# Check if the file is a .csproj file
try:
if file_name.endswith('.csproj'):
# Construct the source path of the README.md file
source_path = os.path.join(dir_path, 'README.md')
# Construct the destination path in the out/{build_type} directory with the same name as the .csproj file
destination_path = os.path.join(cwd, 'out', f'{build_type}', file_name.replace('.csproj', '.md'))
# Copy the README.md file to the destination path
shutil.copyfile(source_path, destination_path)
print(f"找到README.md({destination_path})")
except:
print(f"README移动失败({file_name})")
print("移动README.md成功~")
if build_type == "Release":
print("🔄 准备转换PDF...")
urllib.request.urlretrieve("https://raw.githubusercontent.com/lxgw/LxgwWenKai/main/fonts/TTF/LXGWWenKaiMono-Regular.ttf", "LXGWWenKaiMono-Regular.ttf")
urllib.request.urlretrieve("https://raw.githubusercontent.com/Wandmalfarbe/pandoc-latex-template/master/eisvogel.tex", "eisvogel.tex")
directory = '/usr/share/texmf/fonts/opentype/public/lm/'
specified_file = 'LXGWWenKaiMono-Regular.ttf'
for filename in os.listdir(directory):
if os.path.isfile(os.path.join(directory, filename)):
shutil.copy2(specified_file, os.path.join(directory, filename))
for file_name in os.listdir(f"out/{build_type}"):
if file_name.endswith('.md'):
md_to_pdf(f"{cwd}/out/{build_type}/{file_name}")
os.remove(f"{cwd}/out/{build_type}/{file_name}")
print(f"✅ {file_name}转换成功...")
print("✅ PDF转换完成!")

# 调用函数来压缩文件夹中的所有文件
# 注意:这里需要替换为实际的文件夹路径和zip文件路径
print("😋准备打包插件")
zip_files_in_folder("out", "Plugins.zip")
print("😋😋😋插件打包成功~")
print("📦 准备打包插件...")
zip_files_in_folder("out", "Plugins.zip")
print("🎉 插件打包成功!")
Loading