Skip to content

Commit 979e536

Browse files
authored
Workflow (#5) (babalae#2038)
1 parent 5363918 commit 979e536

2 files changed

Lines changed: 59 additions & 5 deletions

File tree

.github/workflows/jsonDataValidation.yml

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ jobs:
286286
PR_REPO: ${{ steps.set_env.outputs.head_repo || github.repository }}
287287
CHANGED_FILES_B64: ${{ steps.changed_files.outputs.changed_files }}
288288
run: |
289+
set -e
289290
# 使用base64解码文件列表
290291
CHANGED_FILES=$(echo "$CHANGED_FILES_B64" | base64 --decode)
291292
@@ -299,18 +300,34 @@ jobs:
299300
echo "Python编码设置:"
300301
python -c "import sys; print(sys.getdefaultencoding())"
301302
303+
# 初始化日志文件
304+
: > validation_output.log
305+
VALIDATION_FAILED=false
306+
302307
# 检查CHANGED_FILES是否包含整个目录
303308
if [ "$CHANGED_FILES" = "repo/pathing" ]; then
304309
echo "验证整个目录: repo/pathing"
305-
python build/validate.py "repo/pathing" --fix
310+
set +e
311+
python build/validate.py "repo/pathing" --fix 2>&1 | tee -a validation_output.log
312+
PY_EXIT=$?
313+
set -e
314+
if [ $PY_EXIT -ne 0 ]; then
315+
VALIDATION_FAILED=true
316+
fi
306317
else
307318
# 创建一个临时文件来存储文件列表
308319
echo "$CHANGED_FILES" > temp_file_list.txt
309320
# 单独验证每个修改的文件,使用while读取避免文件名中的空格和特殊字符问题
310321
while IFS= read -r file; do
311322
echo "验证文件: $file"
312323
if [ -f "$file" ]; then
313-
python build/validate.py "$file" --fix
324+
set +e
325+
python build/validate.py "$file" --fix 2>&1 | tee -a validation_output.log
326+
PY_EXIT=$?
327+
set -e
328+
if [ $PY_EXIT -ne 0 ]; then
329+
VALIDATION_FAILED=true
330+
fi
314331
else
315332
echo "警告: 文件不存在 - $file"
316333
fi
@@ -345,6 +362,20 @@ jobs:
345362
echo "没有文件被修改,无需提交"
346363
fi
347364
365+
# 基于日志内容二次判定失败(validate.py 若未正确返回非零时)
366+
if grep -E "❌|JSON 格式错误|JSON格式错误|Expecting property name enclosed in double quotes|Traceback|Error:" -q validation_output.log; then
367+
VALIDATION_FAILED=true
368+
fi
369+
370+
if [ "$VALIDATION_FAILED" = true ]; then
371+
echo "检测到校验错误,生成校验说明并标记失败"
372+
{
373+
echo "### ❌ 校验失败"
374+
echo "请前往 Actions 查看报错详情(运行日志)。"
375+
} > validation_notes.md
376+
exit 1
377+
fi
378+
348379
- name: Run validation for manual trigger
349380
if: ${{ steps.set_env.outputs.trigger_type == 'manual' }}
350381
env:
@@ -356,9 +387,27 @@ jobs:
356387
VALIDATE_PATH: ${{ steps.set_env.outputs.validate_path }}
357388
AUTO_FIX: ${{ steps.set_env.outputs.auto_fix }}
358389
run: |
390+
set -e
359391
echo "手动触发模式,验证路径: ${VALIDATE_PATH}"
360392
# 使用引号包裹路径,处理特殊字符
361-
python build/validate.py "${VALIDATE_PATH}" $([[ "${AUTO_FIX}" == "true" ]] && echo "--fix")
393+
: > validation_output.log
394+
set +e
395+
python build/validate.py "${VALIDATE_PATH}" $([[ "${AUTO_FIX}" == "true" ]] && echo "--fix") 2>&1 | tee -a validation_output.log
396+
PY_EXIT=$?
397+
set -e
398+
VALIDATION_FAILED=false
399+
if [ $PY_EXIT -ne 0 ]; then
400+
VALIDATION_FAILED=true
401+
fi
402+
if grep -E "❌|JSON 格式错误|JSON格式错误|Expecting property name enclosed in double quotes|Traceback|Error:" -q validation_output.log; then
403+
VALIDATION_FAILED=true
404+
fi
405+
if [ "$VALIDATION_FAILED" = true ]; then
406+
{
407+
echo "### ❌ 校验失败"
408+
echo "请前往 Actions 查看报错详情(运行日志)。"
409+
} > validation_notes.md
410+
fi
362411
363412
# 检查是否有文件被修改
364413
if [ -n "$(git status --porcelain)" ]; then
@@ -425,8 +474,12 @@ jobs:
425474
echo "没有文件被修改,无需提交"
426475
fi
427476
477+
if [ "$VALIDATION_FAILED" = true ]; then
478+
exit 1
479+
fi
480+
428481
- name: Add PR comment
429-
if: ${{ (steps.set_env.outputs.trigger_type == 'pr') || (steps.set_env.outputs.trigger_type == 'manual' && steps.set_env.outputs.pr_number != '' && steps.pr_info.outputs.found == 'true') }}
482+
if: ${{ always() && ((steps.set_env.outputs.trigger_type == 'pr') || (steps.set_env.outputs.trigger_type == 'manual' && steps.set_env.outputs.pr_number != '' && steps.pr_info.outputs.found == 'true')) }}
430483
continue-on-error: true
431484
uses: actions/github-script@v6
432485
with:

build/author_config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"鸿羽er": "https://github.com/evildoer12138",
5858
"芝士贝果": "https://github.com/cheese-bagel",
5959
"MissDan": "https://github.com/MisDandan23",
60-
"白白喵": "https://github.com/taotao568685"
60+
"白白喵": "https://github.com/taotao568685",
61+
"躁动的氨气": "https://github.com/zaodonganqi"
6162
}
6263
}

0 commit comments

Comments
 (0)