Skip to content

Commit 0cbde6d

Browse files
committed
add plugin smoke validation workflow
1 parent 9d77e1d commit 0cbde6d

5 files changed

Lines changed: 862 additions & 0 deletions

File tree

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: Validate Plugin Smoke
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "plugins.json"
7+
- "scripts/validate_plugins/**"
8+
- ".github/workflows/validate-plugin-smoke.yml"
9+
workflow_dispatch:
10+
inputs:
11+
plugin_names:
12+
description: "Comma-separated plugin keys from plugins.json"
13+
required: false
14+
default: ""
15+
plugin_limit:
16+
description: "Validate the first N plugins when plugin_names is empty"
17+
required: false
18+
default: "20"
19+
astrbot_ref:
20+
description: "AstrBot git ref to validate against"
21+
required: false
22+
default: "master"
23+
24+
jobs:
25+
validate-plugin-smoke:
26+
runs-on: ubuntu-latest
27+
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0
33+
34+
- name: Set manual validation inputs
35+
if: github.event_name == 'workflow_dispatch'
36+
run: |
37+
echo "ASTRBOT_REF=${{ inputs.astrbot_ref }}" >> "$GITHUB_ENV"
38+
echo "PLUGIN_NAME_LIST=${{ inputs.plugin_names }}" >> "$GITHUB_ENV"
39+
echo "PLUGIN_LIMIT=${{ inputs.plugin_limit }}" >> "$GITHUB_ENV"
40+
echo "SHOULD_VALIDATE=true" >> "$GITHUB_ENV"
41+
42+
- name: Detect changed plugins from pull request
43+
if: github.event_name == 'pull_request'
44+
run: |
45+
python - <<'PY'
46+
import json
47+
import os
48+
import subprocess
49+
from pathlib import Path
50+
51+
base_ref = os.environ["GITHUB_BASE_REF"]
52+
subprocess.run(["git", "fetch", "origin", base_ref, "--depth", "1"], check=True)
53+
base = json.loads(
54+
subprocess.check_output(
55+
["git", "show", f"origin/{base_ref}:plugins.json"],
56+
text=True,
57+
)
58+
)
59+
head = json.loads(Path("plugins.json").read_text(encoding="utf-8"))
60+
61+
changed = [
62+
name
63+
for name, payload in head.items()
64+
if base.get(name) != payload
65+
]
66+
67+
with open(os.environ["GITHUB_ENV"], "a", encoding="utf-8") as handle:
68+
handle.write("ASTRBOT_REF=master\n")
69+
handle.write(f"PLUGIN_NAME_LIST={','.join(changed)}\n")
70+
handle.write("PLUGIN_LIMIT=\n")
71+
handle.write(f"SHOULD_VALIDATE={'true' if changed else 'false'}\n")
72+
PY
73+
74+
- name: Show PR diff selection
75+
if: github.event_name == 'pull_request'
76+
run: |
77+
if [ "$SHOULD_VALIDATE" != "true" ]; then
78+
printf '%s\n' "No plugin entries changed in plugins.json; skipping smoke validation."
79+
else
80+
printf 'Selected plugins: %s\n' "$PLUGIN_NAME_LIST"
81+
fi
82+
83+
- name: Set up Python
84+
if: env.SHOULD_VALIDATE == 'true'
85+
uses: actions/setup-python@v5
86+
with:
87+
python-version: "3.12"
88+
89+
- name: Install validator dependencies
90+
if: env.SHOULD_VALIDATE == 'true'
91+
run: python -m pip install --upgrade pip pyyaml
92+
93+
- name: Clone AstrBot
94+
if: env.SHOULD_VALIDATE == 'true'
95+
run: git clone --depth 1 --branch "$ASTRBOT_REF" "https://github.com/AstrBotDevs/AstrBot" ".cache/AstrBot"
96+
97+
- name: Install AstrBot dependencies
98+
if: env.SHOULD_VALIDATE == 'true'
99+
run: python -m pip install -r ".cache/AstrBot/requirements.txt"
100+
101+
- name: Run plugin smoke validator
102+
if: env.SHOULD_VALIDATE == 'true'
103+
run: |
104+
args=(
105+
--astrbot-path ".cache/AstrBot"
106+
--report-path "validation-report.json"
107+
)
108+
109+
if [ -n "${PLUGIN_NAME_LIST:-}" ]; then
110+
args+=(--plugin-name-list "$PLUGIN_NAME_LIST")
111+
fi
112+
113+
if [ -n "${PLUGIN_LIMIT:-}" ]; then
114+
args+=(--limit "$PLUGIN_LIMIT")
115+
fi
116+
117+
python scripts/validate_plugins/run.py "${args[@]}"
118+
119+
- name: Upload validation report
120+
if: always()
121+
uses: actions/upload-artifact@v4
122+
with:
123+
name: validation-report
124+
path: validation-report.json
125+
if-no-files-found: warn

scripts/validate_plugins/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)