Skip to content

collect

collect #6463

Workflow file for this run

name: collect
on:
push:
branches:
- develop
schedule:
- cron: "0,30 1,3 * * *"
- cron: "0 */2 * * *"
workflow_dispatch:
inputs:
source-branch:
description: '源码分支(采集器代码来源)'
default: 'develop'
type: string
target-branch:
description: '目标分支(采集结果推送目标)'
default: 'dist'
type: string
env:
SOURCE_BRANCH: ${{ github.event.inputs.source-branch || 'develop' }}
TARGET_BRANCH: ${{ github.event.inputs.target-branch || 'dist' }}
jobs:
collect:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ env.SOURCE_BRANCH }}
fetch-depth: 2
- name: Restore dist cache from dist branch
run: |
git fetch origin "$TARGET_BRANCH" 2>/dev/null || true
git restore --source="origin/$TARGET_BRANCH" -- dist/ README.md 2>/dev/null || echo "ℹ️ No $TARGET_BRANCH branch yet, starting with fresh cache"
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version-file: "pyproject.toml"
- name: Install uv
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
with:
enable-cache: true
- name: Install the project
run: cd src && uv sync --locked
- name: Collect
env:
TARGET_BRANCH: ${{ env.TARGET_BRANCH }}
run: |
cd src && uv run main.py --proxy
- name: Commit && Push to target branch
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
TMP=$(mktemp -d)
cp -a dist README.md .github "$TMP/"
git reset --hard
git switch --orphan "$TARGET_BRANCH"
find . -mindepth 1 -maxdepth 1 ! -name .git -exec rm -rf {} +
cp -a "$TMP"/. .
git add -A
git commit -m "chore: auto collect $(date -u +'%Y-%m-%d %H:%M') UTC"
git push origin "$TARGET_BRANCH" --force