Prechecks using Gitea Actions

This commit is contained in:
2026-04-02 11:41:00 +00:00
parent 88b6007443
commit 96eb58b771
3 changed files with 306 additions and 0 deletions

View File

@ -0,0 +1,75 @@
# .gitea/workflows/docs-precheck.yml
name: Docs Precheck - Underscore Check
on:
pull_request:
types: [opened, reopened, synchronize, edited]
permissions:
contents: read
pull-requests: write
jobs:
docs-precheck:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: pip install beautifulsoup4 lxml
- name: Get changed HTML files
id: changed-files
run: |
BASE_SHA="${{ gitea.event.pull_request.base.sha }}"
git fetch origin $BASE_SHA
changed=$(git diff --name-only ${BASE_SHA}...HEAD | grep -E '\.(html|htm)$' | tr '\n' ' ')
echo "files=$changed" >> $GITHUB_OUTPUT
echo "CHANGED_FILES=$changed" >> $GITHUB_ENV
echo "Changed HTML files: $changed"
- name: Run underscore check
id: underscore-check
run: |
python3 .gitea/workflows/underscore-check.py
- name: Comment on PR with violations
if: failure() && steps.underscore-check.outcome == 'failure'
env:
GITEA_URL: ${{ gitea.server_url }}
REPO: ${{ gitea.repository }}
PR_NUMBER: ${{ gitea.event.pull_request.number }}
TOKEN: ${{ gitea.token }}
run: |
set -euo pipefail
# Generate comment message
MSG=$(python3 .gitea/workflows/generate-comment.py)
echo "$MSG"
# Extract body from JSON
BODY=$(echo "$MSG" | python3 -c "import sys, json; print(json.load(sys.stdin)['body'])")
# Comment on PR
curl -sS --fail-with-body -X POST \\
-H "Authorization: token ${TOKEN}" \\
-H "Content-Type: application/json" \\
"${GITEA_URL}/api/v1/repos/${REPO}/issues/${PR_NUMBER}/comments" \\
-d "$(echo "$BODY" | python3 -c "import sys, json; print(json.dumps({'body': sys.stdin.read()}))")"
- name: Final status
if: always()
run: |
if [ -f violations.json ]; then
echo "::error::Underscore check failed. See previous step for details."
exit 1
fi

View File

@ -0,0 +1,52 @@
#!/usr/bin/env python3
"""Generate PR comment from violations."""
import json
import sys
def main():
try:
with open('violations.json', 'r') as f:
violations = json.load(f)
except Exception:
violations = []
if not violations:
print(json.dumps({'body': 'No violations to report'}))
sys.exit(0)
# Group violations by file
by_file = {}
for v in violations:
key = v['file']
if key not in by_file:
by_file[key] = []
by_file[key].append(v)
# Build message
lines = [
"❌ **Underscore check failed**",
"",
"Found words ending with underscore (not followed by alphanumeric characters):",
""
]
for filepath, file_violations in by_file.items():
lines.append(f"**{filepath}:**")
for v in file_violations:
word = v['word']
line_num = v['line']
context = v['context']
# Escape markdown special chars in context
context = context.replace('`', '\\`')
lines.append(f" - Line {line_num}: `{word}` in context: `{context}`")
lines.append("")
lines.append("**Please fix these issues as soon as possible.** Words should not end with an underscore unless followed by alphanumeric characters (A-Za-z0-9).")
message = "\n".join(lines)
print(json.dumps({'body': message}))
if __name__ == '__main__':
main()

File diff suppressed because it is too large Load Diff