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

fix: streamline build process by executing PyInstaller from project r… #10

Merged
merged 26 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
92da618
fix: streamline build process by executing PyInstaller from project r…
thelastfantasy Oct 19, 2024
4af11d8
fix: allow synchronization events for pull requests in release workflow
thelastfantasy Oct 19, 2024
0ef235b
fix: comment out condition for PR merge validation in release workflow
thelastfantasy Oct 19, 2024
595b046
fix: enhance dependency installation and compilation steps for cross-…
thelastfantasy Oct 19, 2024
fddaf8d
fix: prevent duplicate tag creation in release workflow
thelastfantasy Oct 19, 2024
e40c161
fix: add checks for existence of compiled files before moving in rele…
thelastfantasy Oct 19, 2024
820bb6f
fix: improve tag creation logic to check for local and remote existen…
thelastfantasy Oct 19, 2024
5f4511e
fix: enhance file movement logic in release workflow for better error…
thelastfantasy Oct 19, 2024
61b4650
fix: update Windows build script to use PowerShell for file handling …
thelastfantasy Oct 19, 2024
de304a4
fix: update paths in create-release workflow to use GITHUB_WORKSPACE …
thelastfantasy Oct 19, 2024
bc4f16b
fix: enhance binary handling in create-release workflow for Linux, ma…
thelastfantasy Oct 19, 2024
91db5e0
fix: improve binary discovery and movement logic in create-release wo…
thelastfantasy Oct 19, 2024
5c98e25
fix: add console hiding functionality for GUI launch on Windows
thelastfantasy Oct 19, 2024
1260377
fix: refactor create-release workflow by removing redundant compile s…
thelastfantasy Oct 19, 2024
18c19d1
fix: add GITHUB_TOKEN environment variable for create-release step
thelastfantasy Oct 19, 2024
c830878
fix: streamline create-release workflow by removing debug echoes and …
thelastfantasy Oct 19, 2024
9801564
fix: enhance release asset zipping process by iterating over assets a…
thelastfantasy Oct 19, 2024
5710390
fix: add recursive submodule checkout and list workspace files in cre…
thelastfantasy Oct 19, 2024
f32d12c
fix: update create-release workflow to use validated version from ste…
thelastfantasy Oct 19, 2024
b2e8359
fix: add GITHUB_TOKEN environment variable to create-release step
thelastfantasy Oct 19, 2024
c1df7bf
fix: replace GITHUB_TOKEN with PAT_TOKEN in create-release workflow
thelastfantasy Oct 19, 2024
c9c5cf3
fix: replace GITHUB_TOKEN with PAT_TOKEN in upload-release-asset step
thelastfantasy Oct 19, 2024
4695b45
fix: change zip command to use -j option for adding assets without path
thelastfantasy Oct 19, 2024
89913a8
fix: update create-release workflow to trigger only on closed pull re…
thelastfantasy Oct 19, 2024
938142a
docs: update README with installation instructions and compilation steps
thelastfantasy Oct 19, 2024
b53915a
fix: add check for pip installation in install_dependencies_once.bat
thelastfantasy Oct 19, 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
183 changes: 55 additions & 128 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,14 @@ jobs:
uses: actions/checkout@v3
with:
token: ${{ secrets.PAT_TOKEN }}
submodules: "recursive"

- name: Validate branch name and extract version
id: validate_title
run: |
branch_name="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}"
echo "Branch name: $branch_name"

echo '1' $GITHUB_REF
echo '2' $GITHUB_REF
echo '3' $GITHUB_REF_NAME
echo '4' $GITHUB_HEAD_REF
echo '5' $GITHUB_BASE_REF

if [[ "$branch_name" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9-]+)?$ ]]; then
version=$(echo "$branch_name" | grep -oE '^v[0-9]+\.[0-9]+\.[0-9]+')
echo "version=$version" >> "$GITHUB_OUTPUT"
Expand All @@ -50,143 +45,75 @@ jobs:
- name: Create a tag
if: ${{ steps.validate_title.outputs.version != '' }}
run: |
git tag ${{ steps.validate_title.outputs.version }}
git push origin ${{ steps.validate_title.outputs.version }}

# Job 2: Compile using matrix for different platforms
compile:
needs: validate_and_tag
if: ${{ needs.validate_and_tag.outputs.version != '' }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
include:
- os: ubuntu-latest
python-version: "3.x"
- os: windows-latest
python-version: "3.x"
architecture: "x64"
- os: macos-latest
python-version: "3.x"

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
architecture: ${{ matrix.architecture || '' }}

- name: Install Dependencies
run: |
if [ -f src/requirements.txt ]; then
pip install -r src/requirements.txt
fi

- name: Install PyInstaller
run: |
pip install pyinstaller

- name: Compile for ${{ matrix.os }}
run: |
cd src
pyinstaller --onefile sub_adjust.py
pyinstaller --onefile sub_converter.py
cd ..
if [ "${{ matrix.os }}" == "ubuntu-latest" ]; then
mkdir -p build/linux
mv src/dist/sub_adjust build/linux/
mv src/dist/sub_converter build/linux/
elif [ "${{ matrix.os }}" == "windows-latest" ]; then
mkdir -p build/windows
mv src/dist/sub_adjust.exe build/windows/
mv src/dist/sub_converter.exe build/windows/
elif [ "${{ matrix.os }}" == "macos-latest" ]; then
mkdir -p build/macos
mv src/dist/sub_adjust build/macos/
mv src/dist/sub_converter build/macos/
version=${{ steps.validate_title.outputs.version }}

# 检查本地是否存在该 Tag
tag_exists=$(git tag -l "$version")

if [ -z "$tag_exists" ]; then
# 本地不存在该 Tag,创建 Tag
git tag "$version"

# 检查远程是否存在该 Tag
remote_tag_exists=$(git ls-remote --tags origin | grep "refs/tags/$version" || true)
if [ -z "$remote_tag_exists" ]; then
# 如果远程也不存在,推送 Tag
git push origin "$version"
echo "Tag $version created and pushed successfully."
else
echo "Tag $version already exists in remote. Skipping push."
fi
else
echo "Tag $version already exists locally. Skipping tag creation and push."
fi
shell: bash

# Job 3: Create release
create_release:
needs: [validate_and_tag, compile]
if: ${{ needs.validate_and_tag.outputs.version != '' }}
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

# Tar compiled Linux binaries
- name: Tar Linux binaries
run: |
tar -czvf "sub_adjust-v${{ needs.validate_and_tag.outputs.version }}-linux-x64.tar.gz" -C build/linux .

# Tar compiled macOS binaries
- name: Tar macOS binaries
run: |
tar -czvf "sub_adjust-v${{ needs.validate_and_tag.outputs.version }}-macos-x64.tar.gz" -C build/macos .

# Zip compiled Windows binaries
- name: Zip Windows binaries
- name: List all files in the workspace
run: |
zip -r "sub_adjust-v${{ needs.validate_and_tag.outputs.version }}-win-x64.zip" build/windows
echo "Workspace directory: $GITHUB_WORKSPACE"
ls -la $GITHUB_WORKSPACE
echo "Listing all files recursively:"
find $GITHUB_WORKSPACE

# Zip source code
- name: Zip source code
- name: Create release assets archive
run: |
zip -r "sub_adjust-v${{ needs.validate_and_tag.outputs.version }}-source.zip" .
output_zip="sub-adjust_${{ steps.validate_title.outputs.version }}.zip"
assets_file="$GITHUB_WORKSPACE/.github/workflows/PackageAssets.txt"

# 创建包含指定文件的压缩包
while IFS= read -r asset; do
echo "Adding asset: $asset"
zip -j "$output_zip" "$GITHUB_WORKSPACE/$asset"
done < "$assets_file"
shell: bash

# Create GitHub release
# Create a release and upload the zip file
- name: Create GitHub release
id: create_release_step
uses: actions/create-release@v1
id: create_release
if: ${{ steps.validate_title.outputs.version != '' }}
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
with:
tag_name: ${{ needs.validate_and_tag.outputs.version }}
release_name: Release ${{ needs.validate_and_tag.outputs.version }}
tag_name: ${{ steps.validate_title.outputs.version }}
release_name: ${{ steps.validate_title.outputs.version }}
body: |
Automatically created release for version ${{ needs.validate_and_tag.outputs.version }}.
Automatically created release for version ${{ steps.validate_title.outputs.version }}.

### PR Description:
${{ github.event.pull_request.body }}
draft: false
prerelease: false
commitish: ${{ github.sha }}

# Upload Linux binaries tar.gz file to release
- name: Upload Linux binaries tar.gz file to release
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release_step.outputs.upload_url }}
asset_path: ./sub_adjust-v${{ needs.validate_and_tag.outputs.version }}-linux-x64.tar.gz
asset_name: sub_adjust-v${{ needs.validate_and_tag.outputs.version }}-linux-x64.tar.gz
asset_content_type: application/gzip

# Upload macOS binaries tar.gz file to release
- name: Upload macOS binaries tar.gz file to release
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release_step.outputs.upload_url }}
asset_path: ./sub_adjust-v${{ needs.validate_and_tag.outputs.version }}-macos-x64.tar.gz
asset_name: sub_adjust-v${{ needs.validate_and_tag.outputs.version }}-macos-x64.tar.gz
asset_content_type: application/gzip

# Upload Windows binaries zip file to release
- name: Upload Windows binaries zip file to release
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release_step.outputs.upload_url }}
asset_path: ./sub_adjust-v${{ needs.validate_and_tag.outputs.version }}-win-x64.zip
asset_name: sub_adjust-v${{ needs.validate_and_tag.outputs.version }}-win-x64.zip
asset_content_type: application/zip

# Upload source zip file to release
- name: Upload source zip file to release
# Upload the zip file as the release asset
- name: Upload zip file to release
if: ${{ steps.validate_title.outputs.version != '' }}
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
with:
upload_url: ${{ steps.create_release_step.outputs.upload_url }}
asset_path: ./sub_adjust-v${{ needs.validate_and_tag.outputs.version }}-source.zip
asset_name: sub_adjust-v${{ needs.validate_and_tag.outputs.version }}-source.zip
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./sub-adjust_${{ steps.validate_title.outputs.version }}.zip
asset_name: sub-adjust_${{ steps.validate_title.outputs.version }}.zip
asset_content_type: application/zip
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,25 @@
功能没sushi强大,但是主打一个轻巧、快速、简单。

# 说明
下载各自平台对应的版本,解压后运行可执行文件即可
解压后如果是首次运行,执行对应平台的install_dependencies_once.bat (Windows) 或 install_dependencies_once.sh (Linux & MacOS) 即可简单安装依赖工具

两款工具均只支持UTF-8编码字幕文件。
运行各个start_xxx.bat (Windows) 或 start_xxx.sh (Linux & MacOS) 即可启动对应工具的GUI版本。
sub_adjust命令行版本帮助请点击GUI界面右下角按钮查阅。

<font color="red">两款工具均只支持UTF-8编码字幕文件。</font>

sub_adjust:
调轴工具,支持srt、ass、ssa三种格式,支持批量操作(默认读取程序目录下的字幕文件,不含子目录),可双击GUI运行亦可命令行运行。
命令行版本帮助请点击GUI界面右下角。

sub_converter:
srt转ass字幕工具,支持批量操作(默认读取程序目录下的字幕文件,不含子目录),可使用自定义元数据,目前仅可GUI运行。
srt转ass字幕工具,支持批量操作(默认读取程序目录下的字幕文件,不含子目录),可使用自定义元数据,目前仅可GUI运行。

# 为什么不提供编译好的可执行文件?
编译后太大了,可以尝试自行编译

编译步骤:
1. 安装Git并克隆本项目源码
2. 执行install_dependencies_once.bat (Windows) 或 install_dependencies_once.sh (Linux & MacOS) 安装Python等依赖工具
3. 安装pyinstaller: `pip install -U pyinstaller`
4. 在项目目录下执行 `pyinstaller -w --onefile sub_adjust.py` , `pyinstaller -w --onefile sub_converter.py` 即可在`./dist`目录下生成可执行文件
7 changes: 7 additions & 0 deletions install_dependencies_once.bat
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ if %ERRORLEVEL% NEQ 0 (
exit /b 1
)

REM Check and install pip
where pip >nul 2>&1
if %ERRORLEVEL% NEQ 0 (
echo pip未安装或未正确配置环境变量,请先安装pip并确保其路径已添加到环境变量中。
exit /b 1
)

REM Try install deps from requirements.txt
pip install -r requirements.txt
if %ERRORLEVEL% NEQ 0 (
Expand Down
6 changes: 4 additions & 2 deletions sub_adjust.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import webbrowser
from docopt import docopt
from loguru import logger
from utils import center_window, custom_messagebox, display_errors
from utils import center_window, custom_messagebox, display_errors, hide_console
import queue

__version__ = 'sub_adjust v1.2.0'
Expand All @@ -17,14 +17,15 @@
sub_adjust --offset <subtitle_shift_seconds> [--layers <layer_numbers>] [INPUTS...]
sub_adjust --version
sub_adjust (-h | --help)
sub_adjust

Options:
-t --offset <subtitle_shift_seconds> 字幕偏移量(单位:秒,1s = 1000ms),支持小数、负数、正数,负数为提前,正数为延后。
--layers <layer_numbers> 可选参数,将时间调整仅应用到此处设置的Layer中。默认为 all
--version 显示版本信息
-h --help 显示帮助信息

Examples (二进制版本):
Examples (二进制版本,需自行编译):
# 将字幕提前2.5秒
sub_adjust --offset -2.5 example.ass

Expand Down Expand Up @@ -351,6 +352,7 @@ def main():

# 否则启动GUI(没有提供 --offset 时)
else:
hide_console()
logger.info("正在启动GUI...")
start_ui()

Expand Down
10 changes: 10 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
import tkinter as tk
from tkinter import scrolledtext
import chardet
import sys

def hide_console():
"""在 Windows 下隐藏控制台窗口"""
if sys.platform == "win32":
import ctypes
whnd = ctypes.windll.kernel32.GetConsoleWindow()
if whnd != 0:
ctypes.windll.user32.ShowWindow(whnd, 0)
ctypes.windll.kernel32.CloseHandle(whnd)

def detect_encoding(file_path):
with open(file_path, 'rb') as f:
Expand Down
Loading