Skip to content

Commit 400c6a6

Browse files
committed
fix:调整校验脚本
1 parent bd3ecb3 commit 400c6a6

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

.github/scripts/validate_pr.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@ def check(cond, msg, is_warn=False):
1515
if not cond:
1616
(warnings if is_warn else errors).append(msg)
1717

18-
def get_valid_tags(root_yaml_path='data.yaml'):
19-
if not os.path.isfile(root_yaml_path):
20-
print(f"⚠️ 未找到根配置文件 {root_yaml_path},跳过 tags 校验")
18+
def get_valid_tags():
19+
root = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../..')
20+
yaml_path = os.path.join(root, 'tools/data.yaml')
21+
if not os.path.isfile(yaml_path):
22+
print(f"⚠️ 未找到 tools/data.yaml,跳过 tags 校验")
2123
return set()
2224
try:
23-
with open(root_yaml_path, encoding='utf-8') as f:
25+
with open(yaml_path, encoding='utf-8') as f:
2426
data = yaml.safe_load(f)
2527
tags = data.get('additionalProperties', {}).get('tags', [])
2628
return {tag['name'] for tag in tags if 'name' in tag}
2729
except yaml.YAMLError as e:
28-
print(f"⚠️ 根配置文件解析失败: {e}")
30+
print(f"⚠️ tools/data.yaml 解析失败: {e}")
2931
return set()
3032

3133
def get_changed_tool_dirs(changed_files_path):
@@ -99,11 +101,11 @@ def validate_tool_dir(tool_path, valid_tags):
99101
logo_path = os.path.join(tool_path, 'logo.png')
100102
if os.path.isfile(logo_path):
101103
size_kb = os.path.getsize(logo_path) / 1024
102-
check(size_kb <= 500, f"[{tool_name}] logo.png 文件过大 ({size_kb:.1f}KB),建议不超过 500KB", is_warn=True)
104+
check(size_kb <= 500, f"[{tool_name}] logo.png 过大 ({size_kb:.1f}KB),建议不超过 500KB", is_warn=True)
103105

104106
def main():
105107
changed_files_path = sys.argv[1]
106-
valid_tags = get_valid_tags('data.yaml')
108+
valid_tags = get_valid_tags()
107109
tool_dirs = get_changed_tool_dirs(changed_files_path)
108110

109111
if not tool_dirs:

.github/workflows/pr-validate.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ jobs:
3333

3434
- name: Run validation
3535
id: validate
36+
working-directory: ${{ github.workspace }}
3637
run: |
3738
python .github/scripts/validate_pr.py changed_files.txt > result.txt 2>&1
3839
echo "exit_code=$?" >> $GITHUB_OUTPUT
3940
cat result.txt
4041
4142
- name: Comment on PR
43+
if: github.event_name == 'pull_request'
4244
uses: actions/github-script@v7
4345
with:
4446
script: |
@@ -48,7 +50,7 @@ jobs:
4850
const icon = exitCode === '0' ? '✅' : '❌';
4951
const status = exitCode === '0' ? '校验通过' : '校验失败,请修复后重新提交';
5052
github.rest.issues.createComment({
51-
issue_number: context.issue.number,
53+
issue_number: context.payload.pull_request.number,
5254
owner: context.repo.owner,
5355
repo: context.repo.repo,
5456
body: `## ${icon} PR 自动校验结果\n\n**状态**: ${status}\n\n\`\`\`\n${result}\n\`\`\``

0 commit comments

Comments
 (0)