forked from docs/doc-exports
75 lines
2.2 KiB
YAML
75 lines
2.2 KiB
YAML
# .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 }}"
|
|
changed=$(git diff --name-only ${BASE_SHA}...HEAD | grep -E '\.(html|htm)$' | tr '\n' ' ' || true)
|
|
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
|