Skip to content

Civitai Creator Sync #22

Civitai Creator Sync

Civitai Creator Sync #22

Workflow file for this run

# .github/workflows/civitai_sync.yml
name: Civitai Creator Sync
on:
# 手动触发时,仍然是针对单个作者
workflow_dispatch:
inputs:
creator_username:
description: 'Creator Username to sync'
required: true
default: 'civitai'
nsfw_level:
description: 'NSFW Level'
type: choice
required: true
default: 'X'
options: ['None', 'Soft', 'Mature', 'X']
sort_by:
description: 'Sort Order'
type: choice
required: true
default: 'Newest'
options: ['Newest', 'Most Reactions', 'Most Comments']
threads:
description: 'Download Threads (1-32)'
type: number
default: 16
# 定时触发:每天 0点 (UTC) 运行一次
schedule:
- cron: '0 0 * * *'
# --- ↓↓↓ 添加下面这两行 ↓↓↓ ---
concurrency:
group: ${{ github.workflow }}
# --- ↑↑↑ 添加上面这两行 ↑↑↑ ---
jobs:
sync-and-report:
runs-on: ubuntu-latest
permissions:
contents: write
# --- 核心改动:使用 Matrix 策略 ---
strategy:
fail-fast: false # 即使一个作者的任务失败了,其他作者的任务也会继续运行
matrix:
# 在这里列出所有你想要定时监控的作者
creator: ['SAKI88']
steps:
- name: 1. Checkout repository
uses: actions/checkout@v4
- name: 2. Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: 3. Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
# 改动:脚本的参数现在根据触发方式来决定
- name: 4. Run Sync and Report Script
# 使用 if 判断是手动触发还是定时触发
# github.event_name == 'workflow_dispatch' 表示是手动触发
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "Running manually for: ${{ github.event.inputs.creator_username }}"
python sync_and_report.py \
--username "${{ github.event.inputs.creator_username }}" \
--nsfw "${{ github.event.inputs.nsfw_level }}" \
--sort "${{ github.event.inputs.sort_by }}" \
--threads ${{ github.event.inputs.threads }} \
--output-dir "./output"
else
echo "Running scheduled job for: ${{ matrix.creator }}"
python sync_and_report.py \
--username "${{ matrix.creator }}" \
--nsfw "X" \
--sort "Newest" \
--threads 16 \
--output-dir "./output"
fi
- name: 5. Commit and Push Changes
# 提交信息也需要根据触发方式变化
run: |
if [ -n "$(git status --porcelain)" ]; then
git config --global user.name "GitHub Actions Bot"
git config --global user.email "actions@github.com"
git add output/*.json output/reports/*
# 使用不同的 commit message
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
git commit -m "ci: Manual sync for ${{ github.event.inputs.creator_username }}"
else
git commit -m "ci: Scheduled sync for ${{ matrix.creator }}"
fi
git push
else
echo "No changes to commit."
fi
- name: 6. Upload New Images Zip as Artifact
# 上传产物的名字也需要动态生成
run: |
ZIP_FILE=$(ls ./output/*.zip 2>/dev/null)
if [ -n "$ZIP_FILE" ]; then
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
ARTIFACT_NAME="new-images-${{ github.event.inputs.creator_username }}-${{ github.run_id }}"
else
ARTIFACT_NAME="new-images-${{ matrix.creator }}-${{ github.run_id }}"
fi
echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >> $GITHUB_ENV
echo "ZIP_PATH=${ZIP_FILE}" >> $GITHUB_ENV
fi
- uses: actions/upload-artifact@v4
if: env.ARTIFACT_NAME
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.ZIP_PATH }}
if-no-files-found: 'ignore'