forked from docs/doc-exports
82 lines
2.5 KiB
YAML
82 lines
2.5 KiB
YAML
# .gitea/workflows/class-txt-check.yml
|
|
name: Docs Precheck - CLASS.TXT.json Check
|
|
|
|
on:
|
|
pull_request:
|
|
types: [opened, reopened, synchronize, edited]
|
|
|
|
permissions:
|
|
contents: read
|
|
pull-requests: write
|
|
|
|
jobs:
|
|
class-txt-check:
|
|
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: Get changed CLASS.TXT.json files
|
|
id: changed-files
|
|
run: |
|
|
BASE_SHA="${{ gitea.event.pull_request.base.sha }}"
|
|
changed=$(git diff --name-only ${BASE_SHA}...HEAD | grep -E 'CLASS\.TXT\.json$' | tr '\n' ' ' || true)
|
|
echo "files=$changed" >> $GITHUB_OUTPUT
|
|
echo "CHANGED_FILES=$changed" >> $GITHUB_ENV
|
|
echo "Changed CLASS.TXT.json files: $changed"
|
|
|
|
- name: Run duplicate title check
|
|
id: class-check
|
|
run: |
|
|
python3 .gitea/workflows/helpers/class-txt-check.py
|
|
|
|
- name: Comment on PR with violations
|
|
if: failure() && steps.class-check.outcome == 'failure'
|
|
env:
|
|
GITEA_SERVER_URL: ${{ gitea.server_url }}
|
|
REPO: ${{ gitea.repository }}
|
|
PR_NUMBER: ${{ gitea.event.pull_request.number }}
|
|
TOKEN: ${{ gitea.token }}
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
# Ensure URL starts with http
|
|
if [[ ! "${GITEA_SERVER_URL}" =~ ^https?:// ]]; then
|
|
GITEA_SERVER_URL="http://${GITEA_SERVER_URL}"
|
|
echo "Added http:// prefix to URL"
|
|
fi
|
|
|
|
# Generate comment message
|
|
MSG=$(python3 .gitea/workflows/helpers/class-comment.py)
|
|
echo "$MSG"
|
|
|
|
# Extract body from JSON
|
|
BODY=$(echo "$MSG" | python3 -c "import sys, json; print(json.load(sys.stdin)['body'])")
|
|
|
|
# Build the full URL
|
|
FULL_URL="${GITEA_SERVER_URL}/api/v1/repos/${REPO}/issues/${PR_NUMBER}/comments"
|
|
echo "Posting comment to: ${FULL_URL}"
|
|
|
|
# Comment on PR
|
|
curl -sS -X POST \
|
|
-H "Authorization: token ${TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
"${FULL_URL}" \
|
|
-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::CLASS.TXT.json check failed. See previous step for details."
|
|
exit 1
|
|
fi
|