Files
shunt-rules/.gitea/workflows/repo-manage-daily.yml
T
2026-04-06 14:29:22 +08:00

82 lines
2.2 KiB
YAML

name: Full Repo Management Daily
on:
workflow_dispatch:
schedule:
- cron: "5 2 * * *"
permissions:
contents: write
concurrency:
group: full-repo-management
cancel-in-progress: false
jobs:
manage:
runs-on: ubuntu-latest
steps:
- name: Checkout builder repo
uses: actions/checkout@v4
with:
fetch-depth: 0
github-server-url: https://git.halonice.com
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Prepare config
shell: bash
run: |
if [ -f config.toml ]; then
echo "Use existing config.toml"
elif [ -f config.json ]; then
echo "Use existing config.json"
elif [ -f config.example.toml ]; then
cp config.example.toml config.toml
echo "Generated config.toml from example"
else
echo "No config file found" >&2
exit 1
fi
- name: Sync upstream and generate rules
shell: bash
env:
UPSTREAM_REF: ${{ vars.UPSTREAM_REF }}
run: |
set -euo pipefail
UPSTREAM_REF="${UPSTREAM_REF:-master}"
bash scripts/sync_surge_full.sh
if [ -f config.toml ]; then
python3 main.py --config config.toml
else
python3 main.py --config config.json
fi
- name: Commit and push builder updates
shell: bash
run: |
set -euo pipefail
branch="${GITHUB_REF_NAME:-}"
if [ -z "${branch}" ]; then
branch="$(git rev-parse --abbrev-ref HEAD || true)"
fi
if [ -z "${branch}" ] || [ "${branch}" = "HEAD" ]; then
branch="main"
fi
git config user.name "gitea-actions[bot]"
git config user.email "gitea-actions@localhost"
git add -A
if git diff --cached --quiet; then
echo "No builder changes"
echo "builder_changed=false" >> "$GITHUB_ENV"
else
git commit -m "chore: daily sync and generate rules"
git push origin "HEAD:${branch}"
echo "builder_changed=true"
fi