name: DouYin Spark Flow Schedule Run
on:
  workflow_dispatch: # 允许手动触发
  schedule: # 定时任务
    - cron: "0 1 * * *" # 每天 1:00 UTC（对应北京时间 9:00）
jobs:
  run-main:
    timeout-minutes: 20
    runs-on: ubuntu-latest
    environment: user-data
    steps:
    - uses: actions/checkout@v4
    - name: Set up Python
      uses: actions/setup-python@v4
      with:
        python-version: '3.11'
    - name: Test Douyin Accessibility
      run: |
        curl -I https://creator.douyin.com/
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt
    - name: Ensure browsers are installed
      run: playwright install chromium --with-deps --only-shell
    - name: Run DouYin Spark Flow
      env:
        USER_DATA: ${{ secrets.USER_DATA }}
      run: python main.py --doTask
    - uses: actions/upload-artifact@v4
      if: ${{ !cancelled() }}
      with:
        name: run-logs
        path: logs/
  workflow-keepalive:
    if: github.event_name == 'schedule'
    runs-on: ubuntu-latest
    permissions:
      actions: write
    steps:
      - uses: liskin/gh-workflow-keepalive@v1