From 392c039122be689eab1eecd41bbd59da5b5c765f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A2=81=E9=9C=87?= Date: Mon, 6 Apr 2026 14:29:22 +0800 Subject: [PATCH] refactor: switch to single-repo automation --- .gitea/workflows/publish-rules.yml | 112 ------------------------- .gitea/workflows/repo-manage-daily.yml | 50 +---------- README.md | 29 +------ scripts/release_dist.sh | 41 --------- 4 files changed, 4 insertions(+), 228 deletions(-) delete mode 100644 .gitea/workflows/publish-rules.yml delete mode 100755 scripts/release_dist.sh diff --git a/.gitea/workflows/publish-rules.yml b/.gitea/workflows/publish-rules.yml deleted file mode 100644 index ff9a3215b..000000000 --- a/.gitea/workflows/publish-rules.yml +++ /dev/null @@ -1,112 +0,0 @@ -name: Publish Rules To External Repo - -on: - workflow_dispatch: - -permissions: - contents: read - -jobs: - publish: - runs-on: ubuntu-latest - - steps: - - name: Validate required secrets - id: preflight - shell: bash - run: | - missing=0 - for key in GITEA_BASE_URL GITEA_TOKEN TARGET_OWNER TARGET_REPO; do - if [ -z "${!key}" ]; then - echo "Missing required secret: $key" >&2 - missing=1 - fi - done - if [ "$missing" -ne 0 ]; then - echo "skip=true" >> "$GITHUB_OUTPUT" - exit 0 - fi - echo "skip=false" >> "$GITHUB_OUTPUT" - env: - GITEA_BASE_URL: ${{ secrets.GITEA_BASE_URL }} - GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} - TARGET_OWNER: ${{ secrets.TARGET_OWNER }} - TARGET_REPO: ${{ secrets.TARGET_REPO }} - - - name: Checkout generator repo - if: steps.preflight.outputs.skip != 'true' - uses: actions/checkout@v4 - with: - github-server-url: https://git.halonice.com - - - name: Setup Python - if: steps.preflight.outputs.skip != 'true' - uses: actions/setup-python@v5 - with: - python-version: "3.11" - - - name: Sync upstream Surge source - if: steps.preflight.outputs.skip != 'true' - shell: bash - run: | - UPSTREAM_REF="${UPSTREAM_REF:-master}" - bash scripts/sync_surge_full.sh - env: - UPSTREAM_REF: ${{ vars.UPSTREAM_REF }} - - - name: Generate rules - if: steps.preflight.outputs.skip != 'true' - env: - GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} - run: | - if [ -f config.toml ]; then - python3 main.py --config config.toml - else - python3 main.py --config config.json - fi - - - name: Publish dist to target repo branch - if: steps.preflight.outputs.skip != 'true' - shell: bash - run: | - set -euo pipefail - - target_branch="${TARGET_BRANCH:-main}" - base="${GITEA_BASE_URL%/}" - if [[ "$base" == https://* ]]; then - auth_url="https://${GITEA_TOKEN}@${base#https://}" - elif [[ "$base" == http://* ]]; then - auth_url="http://${GITEA_TOKEN}@${base#http://}" - else - echo "GITEA_BASE_URL must start with http:// or https://" >&2 - exit 1 - fi - remote_url="${auth_url}/${TARGET_OWNER}/${TARGET_REPO}.git" - - rm -rf /tmp/rules-publish - git clone --depth=1 --branch "$target_branch" "$remote_url" /tmp/rules-publish || { - git clone --depth=1 "$remote_url" /tmp/rules-publish - cd /tmp/rules-publish - git checkout -b "$target_branch" - cd - - } - - rsync -a --delete dist/ /tmp/rules-publish/ - - cd /tmp/rules-publish - if [ -n "$(git status --porcelain)" ]; then - git config user.name "gitea-actions[bot]" - git config user.email "gitea-actions@localhost" - git add . - git commit -m "chore: publish generated rules" - git push origin "$target_branch" - echo "Published to ${TARGET_OWNER}/${TARGET_REPO}@${target_branch}" - else - echo "No publish changes" - fi - env: - GITEA_BASE_URL: ${{ secrets.GITEA_BASE_URL }} - GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} - TARGET_OWNER: ${{ secrets.TARGET_OWNER }} - TARGET_REPO: ${{ secrets.TARGET_REPO }} - TARGET_BRANCH: ${{ vars.TARGET_BRANCH }} diff --git a/.gitea/workflows/repo-manage-daily.yml b/.gitea/workflows/repo-manage-daily.yml index 7dcda2cba..0621b2205 100644 --- a/.gitea/workflows/repo-manage-daily.yml +++ b/.gitea/workflows/repo-manage-daily.yml @@ -27,17 +27,6 @@ jobs: with: python-version: "3.11" - - name: Validate token - shell: bash - env: - GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} - run: | - if [ -z "${GITEA_TOKEN}" ]; then - echo "Warning: missing GITEA_TOKEN, release publish step will fail." - else - echo "GITEA_TOKEN exists." - fi - - name: Prepare config shell: bash run: | @@ -56,7 +45,6 @@ jobs: - name: Sync upstream and generate rules shell: bash env: - GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} UPSTREAM_REF: ${{ vars.UPSTREAM_REF }} run: | set -euo pipefail @@ -89,41 +77,5 @@ jobs: else git commit -m "chore: daily sync and generate rules" git push origin "HEAD:${branch}" - echo "builder_changed=true" >> "$GITHUB_ENV" + echo "builder_changed=true" fi - - - name: Publish dist to release repo - shell: bash - env: - GITEA_BASE_URL: ${{ vars.GITEA_BASE_URL }} - GITEA_USERNAME: ${{ vars.GITEA_USERNAME }} - GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} - TARGET_OWNER: ${{ vars.TARGET_OWNER }} - TARGET_REPO: ${{ vars.TARGET_REPO }} - TARGET_BRANCH: ${{ vars.TARGET_BRANCH }} - run: | - set -euo pipefail - if [ -z "${GITEA_TOKEN}" ]; then - echo "Missing secret GITEA_TOKEN for release publish" >&2 - exit 1 - fi - base="${GITEA_BASE_URL:-https://git.halonice.com}" - base="${base%/}" - username="${GITEA_USERNAME:-yuanzhen869}" - owner="${TARGET_OWNER:-yuanzhen869}" - repo="${TARGET_REPO:-shunt-rules-release}" - branch="${TARGET_BRANCH:-main}" - - if [[ "${base}" == https://* ]]; then - release_url="https://${username}:${GITEA_TOKEN}@${base#https://}/${owner}/${repo}.git" - elif [[ "${base}" == http://* ]]; then - release_url="http://${username}:${GITEA_TOKEN}@${base#http://}/${owner}/${repo}.git" - else - echo "GITEA_BASE_URL must start with http:// or https://" >&2 - exit 1 - fi - - RELEASE_REPO_URL="${release_url}" \ - TARGET_BRANCH="${branch}" \ - COMMIT_MESSAGE="chore: daily publish generated rules" \ - bash scripts/release_dist.sh diff --git a/README.md b/README.md index 5658014e4..0a220b3b8 100644 --- a/README.md +++ b/README.md @@ -48,12 +48,6 @@ python3 main.py --config config.json python3 main.py --config config.json --names Apple,YouTube ``` -4. 一键发布 `dist/` 到 release 仓库: - -```bash -bash scripts/release_dist.sh -``` - ## 配置说明 默认配置文件:`config.json`(已启用本地源模式)。 @@ -111,17 +105,10 @@ bash scripts/release_dist.sh - 流程: 1. 同步上游 Surge 源 2. 生成 `dist/` 规则 - 3. 自动提交并推送 builder 仓库变更 - 4. 自动发布 `dist/` 到 `shunt-rules-release` + 3. 自动提交并推送当前仓库变更 需要配置: -- `secrets.GITEA_TOKEN`(必需) -- `vars.GITEA_BASE_URL`(可选,默认 `https://git.halonice.com`) -- `vars.GITEA_USERNAME`(可选,默认 `yuanzhen869`) -- `vars.TARGET_OWNER`(可选,默认 `yuanzhen869`) -- `vars.TARGET_REPO`(可选,默认 `shunt-rules-release`) -- `vars.TARGET_BRANCH`(可选,默认 `main`) - `vars.UPSTREAM_REF`(可选,默认 `master`) ### 2) 手动生成工作流(备用) @@ -131,14 +118,6 @@ bash scripts/release_dist.sh - 触发:手动触发 - 流程:同步上游并生成规则(不自动发布) -### 3) 手动发布工作流(备用) - -文件:`.gitea/workflows/publish-rules.yml` - -- 触发:手动触发 -- 适合“生成仓库”和“发布仓库”分离 -- 将 `dist/` 同步到目标仓库分支(如 `main` / `rules`) - ## 目录结构 ```text @@ -148,8 +127,7 @@ shunt-rules-builder/ ├── config.example.toml ├── config.example.json ├── scripts/ -│ ├── sync_surge_full.sh -│ └── release_dist.sh +│ └── sync_surge_full.sh ├── upstream/ # 本地上游缓存(自动生成,默认忽略) │ └── rule/Surge/... ├── dist/ @@ -159,6 +137,5 @@ shunt-rules-builder/ │ └── mihomo/ └── .gitea/workflows/ ├── repo-manage-daily.yml - ├── generate-rules.yml - └── publish-rules.yml + └── generate-rules.yml ``` diff --git a/scripts/release_dist.sh b/scripts/release_dist.sh deleted file mode 100755 index 995ccc722..000000000 --- a/scripts/release_dist.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" -DIST_DIR="${DIST_DIR:-${REPO_ROOT}/dist}" -RELEASE_REPO_URL="${RELEASE_REPO_URL:-https://git.halonice.com/yuanzhen869/shunt-rules-release.git}" -TARGET_BRANCH="${TARGET_BRANCH:-main}" -COMMIT_MESSAGE="${COMMIT_MESSAGE:-chore: release dist}" - -if [[ ! -d "${DIST_DIR}" ]]; then - echo "dist directory not found: ${DIST_DIR}" >&2 - exit 1 -fi - -tmp_dir="$(mktemp -d)" -cleanup() { - rm -rf "${tmp_dir}" -} -trap cleanup EXIT - -work_dir="${tmp_dir}/release" -git clone --branch "${TARGET_BRANCH}" --single-branch "${RELEASE_REPO_URL}" "${work_dir}" >/dev/null - -find "${work_dir}" -mindepth 1 -maxdepth 1 ! -name '.git' -exec rm -rf {} + -if command -v rsync >/dev/null 2>&1; then - rsync -a "${DIST_DIR}/" "${work_dir}/" -else - cp -a "${DIST_DIR}/." "${work_dir}/" -fi - -cd "${work_dir}" -git add -A -if git diff --cached --quiet; then - echo "no changes in dist, skip release" - exit 0 -fi - -git -c user.name="shunt-rules-bot" -c user.email="shunt-rules-bot@local" commit -m "${COMMIT_MESSAGE}" >/dev/null -git push origin "${TARGET_BRANCH}" -echo "release pushed to ${RELEASE_REPO_URL} (${TARGET_BRANCH})"