Skip to content

Commit 534ed3f

Browse files
author
milesight-liu
committed
feat: add Codec Validator GitHub Action for validating codec JSON files
1 parent bc69138 commit 534ed3f

File tree

2 files changed

+4158
-4099
lines changed

2 files changed

+4158
-4099
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Codec Validator
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
paths:
8+
- '**/*codec*.json'
9+
pull_request:
10+
branches:
11+
- '**'
12+
paths:
13+
- '**/*codec*.json'
14+
15+
jobs:
16+
detect-files:
17+
runs-on: ubuntu-latest
18+
outputs:
19+
files: ${{ steps.changed_files.outputs.files }}
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 2
25+
26+
- name: Get changed codec files
27+
id: changed_files
28+
run: |
29+
if [ "${{ github.event_name }}" == "pull_request" ]; then
30+
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep -E '.*codec.*\.json$' || echo "")
31+
else
32+
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD | grep -E '.*codec.*\.json$' || echo "")
33+
fi
34+
35+
# 转换为 JSON 数组
36+
if [ -z "$CHANGED_FILES" ]; then
37+
echo "files=[]" >> $GITHUB_OUTPUT
38+
else
39+
FILES_JSON=$(echo "$CHANGED_FILES" | jq -R -s -c 'split("\n") | map(select(length > 0))')
40+
echo "files=$FILES_JSON" >> $GITHUB_OUTPUT
41+
fi
42+
43+
validate:
44+
needs: detect-files
45+
if: needs.detect-files.outputs.files != '[]'
46+
runs-on: ubuntu-latest
47+
strategy:
48+
matrix:
49+
file: ${{ fromJson(needs.detect-files.outputs.files) }}
50+
fail-fast: false # 即使某个文件失败,也继续验证其他文件
51+
steps:
52+
- name: Checkout code
53+
uses: actions/checkout@v4
54+
55+
- name: Validate ${{ matrix.file }}
56+
id: validate
57+
uses: FengFuLiu/codec-validator-action@main
58+
with:
59+
codec-path: ${{ matrix.file }}
60+
fail-on-warning: false
61+
62+
notify:
63+
needs: [detect-files, validate]
64+
if: always() && failure() && needs.detect-files.outputs.files != '[]'
65+
runs-on: ubuntu-latest
66+
steps:
67+
- name: Send WeChat notification
68+
env:
69+
WECHAT_WEBHOOK: ${{ secrets.WECHAT_WEBHOOK_URL }}
70+
run: |
71+
if [ -n "$WECHAT_WEBHOOK" ]; then
72+
curl -X POST "$WECHAT_WEBHOOK" \
73+
-H 'Content-Type: application/json' \
74+
-d "{
75+
\"msgtype\": \"markdown\",
76+
\"markdown\": {
77+
\"content\": \"## Codec Validation Failed\n\n**Repository:** ${{ github.repository }}\n**Branch:** <font color=\\\"warning\\\">${{ github.ref_name }}</font>\n**Author:** ${{ github.actor }}\n**Commit:** ${{ github.event.head_commit.message }}\n\n────────────────\n\n[View Commit](${{ github.event.head_commit.url }}) | [View Actions](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})\"
78+
}
79+
}"
80+
else
81+
echo "Warning: WECHAT_WEBHOOK_URL secret is not configured, skipping notification"
82+
fi

0 commit comments

Comments
 (0)