Skip to content

Commit

Permalink
为Actions添加DEBUG模式,
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-cq committed Mar 2, 2024
1 parent aee1d3a commit 2fd10fb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 26 deletions.
21 changes: 14 additions & 7 deletions .github/workflows/alist-sync.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@ name: Alist Sync

env:
_ALIST_SYNC_NAME: "action-${{github.actor}}-${{github.run_id}}-${{github.run_number}}"
_ALIST_SYNC_DEBUG: ${{ github.event.inputs.debug }}
_ALIST_ADMIN_PASSWORD: ${{ secrets.ALIST_ADMIN_PASSWORD }}

on:
workflow_dispatch:
inputs:
reload_storage:
description: |
是否重新创建存储: true or false
默认情况下,如果存储已经存在,则不会重新创建
如果指定了true,则会删除全部的存储器,并从新载入
description: 删除现有存储库,并从配置文件或远程配置中重新创建存储器
type: boolean
required: false
default: false


debug:
description: 开启调试模式
type: boolean
required: false
default: false


jobs:
run:
Expand Down Expand Up @@ -67,13 +74,13 @@ jobs:
EOF
python3 tools/create_storage.py
- name: RUN
env:
_ALIST_ADMIN_PASSWORD: ${{ secrets.ALIST_ADMIN_PASSWORD }}
- name: RUN Alist Sync
run: |
cat > config.yaml << EOF
${{ secrets.SYNC_CONFIG }}
EOF
set -ex
export TERM=dumb
export FORCE_COLOR=true
./bootstrap.sh main test-config
./bootstrap.sh main sync
12 changes: 9 additions & 3 deletions alist_sync/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,22 @@ def t_ignore(path, match):
@app.command("sync")
def sync(
config_file: str = Option(None, "--config", "-c", help="配置文件路径"),
debug: bool = Option(False, "--debug", help="调试模式, 将以单线程启动"),
debug: bool = Option(
False,
"--debug",
envvar="ALIST_SYNC_DEBUG",
help="调试模式, 将以单线程启动",
),
):
"""同步任务"""
from alist_sync.config import create_config
from alist_sync.config import create_config, getenv
from alist_sync.d_main import main, main_debug

if config_file and Path(config_file).exists():
os.environ["ALIST_SYNC_CONFIG"] = str(Path(config_file).resolve().absolute())
os.environ["_ALIST_SYNC_CONFIG"] = str(Path(config_file).resolve().absolute())

if getenv("ALIST_SYNC_DEBUG", "false").lower() == "true":
debug = True
create_config()
if debug:
echo("调试模式启动")
Expand Down
15 changes: 6 additions & 9 deletions alist_sync/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
),
]

TrueValues = {"true", "1", "yes", "on", "y", "t", "1"}
FalseValues = {"false", "0", "no", "off", "n", "f", "0"}


def getenv(name, default=None):
"""获取环境变量"""
Expand Down Expand Up @@ -139,15 +142,7 @@ def __hash__(self):
timeout: int = Field(10)
ua: str = None

daemon: bool = getenv("ALIST_SYNC_DAEMON", "false").lower() in (
"true",
"1",
"yes",
"on",
"y",
"t",
"1",
)
daemon: bool = getenv("ALIST_SYNC_DAEMON", "false").lower() in TrueValues

name: str = getenv("ALIST_SYNC_NAME", "alist-sync")

Expand All @@ -161,6 +156,8 @@ def __hash__(self):
create_time: datetime = datetime.now()
logs: dict = None

debug: bool = getenv("ALIST_SYNC_DEBUG", "false").lower() in TrueValues

def __init__(self, **data: Any):
super().__init__(**data)
import logging.config
Expand Down
10 changes: 3 additions & 7 deletions alist_sync/d_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,7 @@ def copy_single_stream(self):
"Last-Modified": str(
int(self.source_path.stat().modified.timestamp() * 1000)
),
"File-Path": urllib.parse.quote(
str(self.target_path.as_posix())
),
"File-Path": urllib.parse.quote(str(self.target_path.as_posix())),
},
content=fs,
)
Expand Down Expand Up @@ -229,9 +227,7 @@ def run(self):
try:
if self.status in ["done", "failed"]:
return
if self.need_backup and self.status in [
"init",
]:
if self.need_backup and self.status in ["init"]:
self.backup()

if self.type == "copy" and self.status in ["init", "back-upped"]:
Expand All @@ -246,7 +242,7 @@ def run(self):
logger.error(f"worker[{self.short_id}] 出现错误: {_e}")
self.error_info = str(_e)
self.update(status="failed")
if os.getenv("ALIST_SYNC_DEBUG"):
if sync_config.debug:
raise _e


Expand Down

0 comments on commit 2fd10fb

Please sign in to comment.