|
| 1 | +name: Reusable Paper AI Check |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + checker_ref: |
| 7 | + description: "Ref (branch/tag/SHA) of pssg-paper-checker to run" |
| 8 | + required: false |
| 9 | + type: string |
| 10 | + default: "main" |
| 11 | + latex_root: |
| 12 | + description: "LaTeX project root in caller repository" |
| 13 | + required: false |
| 14 | + type: string |
| 15 | + default: "." |
| 16 | + pdf_path: |
| 17 | + description: "Path to PDF file (relative to latex_root). If empty, runs text-based AI checks only." |
| 18 | + required: false |
| 19 | + type: string |
| 20 | + default: "" |
| 21 | + model: |
| 22 | + description: "LLM model to use" |
| 23 | + required: false |
| 24 | + type: string |
| 25 | + default: "GLM-4.7" |
| 26 | + strict: |
| 27 | + description: "Fail job when AI checks fail" |
| 28 | + required: false |
| 29 | + type: boolean |
| 30 | + default: true |
| 31 | + secrets: |
| 32 | + api_key: |
| 33 | + description: "API key for the LLM provider" |
| 34 | + required: false |
| 35 | + |
| 36 | +jobs: |
| 37 | + ai-check: |
| 38 | + runs-on: ubuntu-latest |
| 39 | + steps: |
| 40 | + - name: Checkout caller repository |
| 41 | + uses: actions/checkout@v4 |
| 42 | + |
| 43 | + - name: Checkout checker repository |
| 44 | + uses: actions/checkout@v4 |
| 45 | + with: |
| 46 | + repository: hpcgroup/pssg-paper-checker |
| 47 | + ref: ${{ inputs.checker_ref }} |
| 48 | + path: _paper_checker |
| 49 | + |
| 50 | + - name: Set up Python |
| 51 | + uses: actions/setup-python@v5 |
| 52 | + with: |
| 53 | + python-version: "3.11" |
| 54 | + |
| 55 | + - name: Install checker dependencies |
| 56 | + run: | |
| 57 | + python -m pip install --upgrade pip |
| 58 | + python -m pip install -r _paper_checker/requirements.txt |
| 59 | +
|
| 60 | + - name: Run AI paper checks |
| 61 | + env: |
| 62 | + ZAI_API_KEY: ${{ secrets.api_key }} |
| 63 | + run: | |
| 64 | + mkdir -p _paper_check_reports |
| 65 | + # Build command |
| 66 | + CMD="python _paper_checker/paper_check.py --latex '${{ inputs.latex_root }}' --model '${{ inputs.model }}'" |
| 67 | + if [ -n "${{ inputs.pdf_path }}" ]; then |
| 68 | + CMD="$CMD --pdf '${{ inputs.latex_root }}/${{ inputs.pdf_path }}'" |
| 69 | + fi |
| 70 | + if [ "${{ inputs.strict }}" = "true" ]; then |
| 71 | + CMD="$CMD --fail-on-error" |
| 72 | + fi |
| 73 | + # Run the check and capture all output |
| 74 | + eval $CMD 2>&1 | tee _paper_check_reports/output.txt |
| 75 | + # Copy the generated markdown report |
| 76 | + cp *_quality_report.md _paper_check_reports/ 2>/dev/null || true |
| 77 | + # Extract JSON from output (the report is printed as JSON) |
| 78 | + python -c " |
| 79 | +import re, sys, json |
| 80 | +text = open('_paper_check_reports/output.txt').read() |
| 81 | +# Find JSON array/object in output |
| 82 | +match = re.search(r'(\{[\s\S]*\"result\"[\s\S]*\})', text) |
| 83 | +if match: |
| 84 | + try: |
| 85 | + data = json.loads(match.group(1)) |
| 86 | + json.dump(data, open('_paper_check_reports/report.json', 'w'), indent=2) |
| 87 | + except: |
| 88 | + pass |
| 89 | +" |
| 90 | +
|
| 91 | + - name: Publish report to run summary |
| 92 | + if: always() |
| 93 | + run: | |
| 94 | + { |
| 95 | + echo "## Paper AI Check" |
| 96 | + echo "" |
| 97 | + echo "- Repository: \`${{ github.repository }}\`" |
| 98 | + echo "- Ref: \`${{ github.ref_name }}\`" |
| 99 | + echo "- Model: \`${{ inputs.model }}\`" |
| 100 | + echo "- Strict: \`${{ inputs.strict }}\`" |
| 101 | + echo "" |
| 102 | + if [ -f "_paper_check_reports/report.json" ]; then |
| 103 | + echo "### JSON Report" |
| 104 | + echo '```json' |
| 105 | + cat "_paper_check_reports/report.json" |
| 106 | + echo '```' |
| 107 | + else |
| 108 | + echo "### Output" |
| 109 | + echo '```' |
| 110 | + cat "_paper_check_reports/output.txt" |
| 111 | + echo '```' |
| 112 | + fi |
| 113 | + } >> "$GITHUB_STEP_SUMMARY" |
| 114 | + |
| 115 | + - name: Upload AI check reports |
| 116 | + if: always() |
| 117 | + uses: actions/upload-artifact@v4 |
| 118 | + with: |
| 119 | + name: paper-ai-check-report |
| 120 | + path: _paper_check_reports/ |
0 commit comments