Skip to content

Commit e9f32ff

Browse files
authored
workflow: run keywords check weekly (#22951)
1 parent 8b756ae commit e9f32ff

2 files changed

Lines changed: 111 additions & 10 deletions

File tree

.github/workflows/keywords.yaml

Lines changed: 110 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,119 @@
11
name: Keywords
22

33
on:
4-
pull_request:
5-
push:
6-
branches:
7-
- 'master'
4+
repository_dispatch:
5+
workflow_dispatch:
6+
schedule:
7+
# Runs at 09:00 every Monday (Beijing time, UTC+8)
8+
- cron: "0 1 * * 1"
9+
10+
env:
11+
# Branches to check (docs branch and TiDB parser branch share the same name).
12+
# Edit this space-separated list to add or remove branches.
13+
CHECK_BRANCHES: "master release-8.5"
14+
15+
permissions:
16+
contents: read
17+
issues: write
818

919
jobs:
1020
check-keywords:
21+
if: github.repository == 'pingcap/docs'
1122
runs-on: ubuntu-latest
1223
steps:
1324
- uses: actions/checkout@v6
14-
- run: |
15-
REF="${GITHUB_BASE_REF:-$GITHUB_REF_NAME}"
16-
./scripts/check-keywords.py \
17-
--download_from_url \
18-
--parser_url "https://github.com/pingcap/tidb/raw/refs/heads/${REF}/pkg/parser/parser.y"
25+
with:
26+
fetch-depth: 0
27+
28+
- name: Set up Python
29+
uses: actions/setup-python@v5
30+
with:
31+
python-version: "3.x"
32+
33+
- name: Install dependencies
34+
run: pip install requests
35+
36+
- name: Check keywords for all branches
37+
id: check
38+
run: |
39+
mkdir -p /tmp/kw-results
40+
has_failure=false
41+
42+
for branch in $CHECK_BRANCHES; do
43+
git checkout "$branch" --quiet
44+
45+
set +e
46+
output=$(python ./scripts/check-keywords.py \
47+
--download_from_url \
48+
--parser_url "https://github.com/pingcap/tidb/raw/refs/heads/${branch}/pkg/parser/parser.y" 2>&1)
49+
exit_code=$?
50+
set -e
51+
52+
if [ $exit_code -eq 0 ]; then
53+
echo "pass" > "/tmp/kw-results/${branch}.status"
54+
elif echo "$output" | grep -q "Failed to download parser file"; then
55+
echo "::warning::Failed to download parser.y for branch ${branch}. Skipping."
56+
echo "skip" > "/tmp/kw-results/${branch}.status"
57+
else
58+
has_failure=true
59+
echo "fail" > "/tmp/kw-results/${branch}.status"
60+
echo "$output" | grep -v "^Fetching " > "/tmp/kw-results/${branch}.errors"
61+
fi
62+
done
63+
64+
echo "has_failure=$has_failure" >> "$GITHUB_OUTPUT"
65+
66+
- name: Build issue report
67+
if: steps.check.outputs.has_failure == 'true'
68+
run: |
69+
{
70+
echo "# Weekly Keywords Check Report"
71+
echo
72+
echo "## Summary"
73+
echo
74+
75+
for branch in $CHECK_BRANCHES; do
76+
status=$(cat "/tmp/kw-results/${branch}.status")
77+
case "$status" in
78+
pass) echo "- **${branch}** — Keywords check result: ✅ pass" ;;
79+
skip) echo "- **${branch}** — Keywords check result: ⚠️ skipped (download failed)" ;;
80+
fail) echo "- **${branch}** — Keywords check result: ❌ mismatch" ;;
81+
esac
82+
done
83+
84+
echo
85+
echo "---"
86+
echo
87+
88+
for branch in $CHECK_BRANCHES; do
89+
status=$(cat "/tmp/kw-results/${branch}.status")
90+
if [ "$status" = "fail" ]; then
91+
error_count=$(wc -l < "/tmp/kw-results/${branch}.errors" | tr -d ' ')
92+
echo "## \`${branch}\` — ${error_count} issue(s)"
93+
echo
94+
echo "Comparing [\`keywords.md\`]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/blob/${branch}/keywords.md)"
95+
echo "against [TiDB parser (\`${branch}\`)](https://github.com/pingcap/tidb/blob/${branch}/pkg/parser/parser.y):"
96+
echo
97+
echo '```'
98+
cat "/tmp/kw-results/${branch}.errors"
99+
echo '```'
100+
echo
101+
fi
102+
done
103+
104+
echo "## How to fix"
105+
echo
106+
echo "Update \`keywords.md\` on the affected branch to match the current TiDB parser keywords."
107+
echo "See [check-keywords.py]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/blob/master/scripts/check-keywords.py) for details."
108+
echo
109+
echo "---"
110+
echo "**Run date:** $(date -u '+%Y-%m-%d %H:%M UTC')"
111+
echo "**Workflow run:** $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
112+
} > keywords-report.md
113+
114+
- name: Create issue
115+
if: steps.check.outputs.has_failure == 'true'
116+
uses: peter-evans/create-issue-from-file@v6
117+
with:
118+
title: "Weekly keywords check: mismatches found"
119+
content-filepath: keywords-report.md

scripts/check-keywords.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,4 @@
8181
print(f"Missing docs for non-reserved keyword from {section}: {kw}")
8282
errors += 1
8383

84-
sys.exit(errors)
84+
sys.exit(1 if errors else 0)

0 commit comments

Comments
 (0)