chore: remove obsolete workflows and update sync process in sync-upstream.yml

This commit is contained in:
shuaiplus
2026-03-07 06:36:41 +08:00
parent 49c71039a4
commit e7d2c85de9
9 changed files with 42 additions and 356 deletions
@@ -1,59 +0,0 @@
name: Import KV ID from NodeWarden2
on:
workflow_dispatch:
permissions:
contents: write
jobs:
patch:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Import KV namespace id from NodeWarden2
env:
REPO_OWNER: ${{ github.repository_owner }}
run: |
python - <<'PY'
import os
import re
from pathlib import Path
from urllib.request import urlopen
owner = os.environ["REPO_OWNER"]
source_url = f"https://raw.githubusercontent.com/{owner}/nodewarden2/main/wrangler.toml"
with urlopen(source_url) as response:
source_text = response.read().decode("utf-8")
source_match = re.search(r'id\s*=\s*"([^"]+)"', source_text)
if not source_match:
raise SystemExit('No `id = "..."` found in nodewarden2/wrangler.toml')
kv_id = source_match.group(1)
target_path = Path("wrangler.toml")
target_text = target_path.read_text(encoding="utf-8")
target_text, count = re.subn(r'id\s*=\s*"[^"]+"', f'id = "{kv_id}"', target_text, count=1)
if count == 0:
raise SystemExit('No `id = "..."` found in current wrangler.toml')
target_path.write_text(target_text, encoding="utf-8")
PY
- name: Commit imported KV id
run: |
git add wrangler.toml
git diff --cached --quiet && exit 0
git commit -m "chore: import kv id from nodewarden2"
git push origin main
-80
View File
@@ -1,80 +0,0 @@
name: Switch to KV mode
on:
workflow_dispatch:
permissions:
contents: write
jobs:
patch:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Switch wrangler.toml to KV mode
run: |
python - <<'PY'
import re
from pathlib import Path
path = Path("wrangler.toml")
text = path.read_text(encoding="utf-8")
pattern = (
r"\[\[r2_buckets\]\]\s*"
r'binding\s*=\s*"ATTACHMENTS"\s*'
r'bucket_name\s*=\s*"nodewarden-attachments"\s*'
)
replacement = (
'[[kv_namespaces]]\n'
'binding = "ATTACHMENTS_KV"\n'
'id = "placeholder"\n'
)
new_text, count = re.subn(pattern, replacement, text, count=1)
if count == 0 and 'binding = "ATTACHMENTS_KV"' not in text:
raise SystemExit("Expected R2 block not found in wrangler.toml")
if count > 0:
path.write_text(new_text, encoding="utf-8")
PY
- name: Update deploy button link in README files
env:
REPO_SLUG: ${{ github.repository }}
run: |
python - <<'PY'
import os
import re
from pathlib import Path
repo_slug = os.environ["REPO_SLUG"]
deploy_url = f"https://deploy.workers.cloudflare.com/?url=https://github.com/{repo_slug}"
pattern = re.compile(
r'https://deploy\.workers\.cloudflare\.com/\?url=https://github\.com/[^)\s]+'
)
for file_name in ("README.md", "README_EN.md"):
path = Path(file_name)
text = path.read_text(encoding="utf-8")
new_text, count = pattern.subn(deploy_url, text, count=2)
if count > 0:
path.write_text(new_text, encoding="utf-8")
PY
- name: Commit KV mode change
run: |
git add wrangler.toml README.md README_EN.md
git diff --cached --quiet && exit 0
git commit -m "chore: switch wrangler.toml to KV mode"
git push origin main
-80
View File
@@ -1,80 +0,0 @@
name: Switch to R2 mode
on:
workflow_dispatch:
permissions:
contents: write
jobs:
patch:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Switch wrangler.toml to R2 mode
run: |
python - <<'PY'
import re
from pathlib import Path
path = Path("wrangler.toml")
text = path.read_text(encoding="utf-8")
pattern = (
r"\[\[kv_namespaces\]\]\s*"
r'binding\s*=\s*"ATTACHMENTS_KV"\s*'
r'id\s*=\s*"placeholder"\s*'
)
replacement = (
'[[r2_buckets]]\n'
'binding = "ATTACHMENTS"\n'
'bucket_name = "nodewarden-attachments"\n'
)
new_text, count = re.subn(pattern, replacement, text, count=1)
if count == 0 and 'binding = "ATTACHMENTS"' not in text:
raise SystemExit("Expected KV block not found in wrangler.toml")
if count > 0:
path.write_text(new_text, encoding="utf-8")
PY
- name: Update deploy button link in README files
env:
REPO_SLUG: ${{ github.repository }}
run: |
python - <<'PY'
import os
import re
from pathlib import Path
repo_slug = os.environ["REPO_SLUG"]
deploy_url = f"https://deploy.workers.cloudflare.com/?url=https://github.com/{repo_slug}"
pattern = re.compile(
r'https://deploy\.workers\.cloudflare\.com/\?url=https://github\.com/[^)\s]+'
)
for file_name in ("README.md", "README_EN.md"):
path = Path(file_name)
text = path.read_text(encoding="utf-8")
new_text, count = pattern.subn(deploy_url, text, count=2)
if count > 0:
path.write_text(new_text, encoding="utf-8")
PY
- name: Commit R2 mode change
run: |
git add wrangler.toml README.md README_EN.md
git diff --cached --quiet && exit 0
git commit -m "chore: switch wrangler.toml to R2 mode"
git push origin main
+3 -30
View File
@@ -22,40 +22,13 @@ jobs:
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Sync main from upstream but keep local wrangler.toml
- name: Sync main from upstream
run: |
cp wrangler.toml /tmp/nodewarden-wrangler.toml
git remote add upstream https://github.com/shuaiplus/NodeWarden.git || true
git fetch upstream
git checkout main
git reset --hard upstream/main
cp /tmp/nodewarden-wrangler.toml wrangler.toml
- name: Update deploy button links in README files
env:
REPO_SLUG: ${{ github.repository }}
run: |
python - <<'PY'
import os
import re
from pathlib import Path
repo_slug = os.environ["REPO_SLUG"]
deploy_url = f"https://deploy.workers.cloudflare.com/?url=https://github.com/{repo_slug}"
pattern = re.compile(
r'https://deploy\.workers\.cloudflare\.com/\?url=https://github\.com/[^)\s]+'
)
for file_name in ("README.md", "README_EN.md"):
path = Path(file_name)
text = path.read_text(encoding="utf-8")
new_text, _ = pattern.subn(deploy_url, text)
path.write_text(new_text, encoding="utf-8")
PY
git merge upstream/main
- name: Push synced main
run: |
git add wrangler.toml README.md README_EN.md
git diff --cached --quiet && exit 0
git commit -m "chore: sync upstream while keeping local deploy config"
git push origin main --force
git push origin main