refactor: switch to single-repo automation
This commit is contained in:
@@ -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 }}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user