Fix validation logic

This commit is contained in:
zbhan
2025-11-02 22:49:43 -05:00
parent 3c7925dc46
commit 9f311580e1
3 changed files with 39 additions and 170 deletions

View File

@@ -1,8 +1,11 @@
name: PR Checks - Comment
# This workflow posts PR check results as comments
# This workflow posts ADVISORY check results as comments
# Runs in the main repo context with write permissions (SAFE)
# Triggered after pr-checks-run.yml completes
#
# NOTE: PR title and size checks are handled by pr-checks.yml (no duplication)
# This workflow only posts backend/frontend advisory check results
on:
workflow_run:
@@ -19,7 +22,7 @@ permissions:
jobs:
comment:
name: Post Check Results
name: Post Advisory Check Results
runs-on: ubuntu-latest
# Only run if the workflow was triggered by a pull_request event
if: github.event.workflow_run.event == 'pull_request'
@@ -37,24 +40,6 @@ jobs:
ls -la artifacts/ || echo "No artifacts directory"
find artifacts/ -type f || echo "No files found"
- name: Read PR info results
id: pr-info
continue-on-error: true
run: |
if [ -f artifacts/pr-info-results/pr-info.json ]; then
echo "=== PR Info JSON ==="
cat artifacts/pr-info-results/pr-info.json
echo "pr_number=$(jq -r '.pr_number' artifacts/pr-info-results/pr-info.json)" >> $GITHUB_OUTPUT
echo "title_status=$(jq -r '.title_status' artifacts/pr-info-results/pr-info.json)" >> $GITHUB_OUTPUT
echo "title_message=$(jq -r '.title_message' artifacts/pr-info-results/pr-info.json)" >> $GITHUB_OUTPUT
echo "size=$(jq -r '.size' artifacts/pr-info-results/pr-info.json)" >> $GITHUB_OUTPUT
echo "lines=$(jq -r '.lines' artifacts/pr-info-results/pr-info.json)" >> $GITHUB_OUTPUT
echo "size_suggestion=$(jq -r '.size_suggestion' artifacts/pr-info-results/pr-info.json)" >> $GITHUB_OUTPUT
else
echo "pr_number=0" >> $GITHUB_OUTPUT
echo "⚠️ PR info artifact not found"
fi
- name: Read backend results
id: backend
continue-on-error: true
@@ -62,6 +47,7 @@ jobs:
if [ -f artifacts/backend-results/backend-results.json ]; then
echo "=== Backend Results JSON ==="
cat artifacts/backend-results/backend-results.json
echo "pr_number=$(jq -r '.pr_number' artifacts/backend-results/backend-results.json)" >> $GITHUB_OUTPUT
echo "fmt_status=$(jq -r '.fmt_status' artifacts/backend-results/backend-results.json)" >> $GITHUB_OUTPUT
echo "vet_status=$(jq -r '.vet_status' artifacts/backend-results/backend-results.json)" >> $GITHUB_OUTPUT
echo "test_status=$(jq -r '.test_status' artifacts/backend-results/backend-results.json)" >> $GITHUB_OUTPUT
@@ -83,6 +69,7 @@ jobs:
echo "EOF" >> $GITHUB_OUTPUT
fi
else
echo "pr_number=0" >> $GITHUB_OUTPUT
echo "⚠️ Backend results artifact not found"
fi
@@ -93,21 +80,9 @@ jobs:
if [ -f artifacts/frontend-results/frontend-results.json ]; then
echo "=== Frontend Results JSON ==="
cat artifacts/frontend-results/frontend-results.json
echo "lint_status=$(jq -r '.lint_status' artifacts/frontend-results/frontend-results.json)" >> $GITHUB_OUTPUT
echo "typecheck_status=$(jq -r '.typecheck_status' artifacts/frontend-results/frontend-results.json)" >> $GITHUB_OUTPUT
echo "build_status=$(jq -r '.build_status' artifacts/frontend-results/frontend-results.json)" >> $GITHUB_OUTPUT
# Read output files
if [ -f artifacts/frontend-results/lint-output-short.txt ]; then
echo "lint_output<<EOF" >> $GITHUB_OUTPUT
cat artifacts/frontend-results/lint-output-short.txt >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
fi
if [ -f artifacts/frontend-results/typecheck-output-short.txt ]; then
echo "typecheck_output<<EOF" >> $GITHUB_OUTPUT
cat artifacts/frontend-results/typecheck-output-short.txt >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
fi
if [ -f artifacts/frontend-results/build-output-short.txt ]; then
echo "build_output<<EOF" >> $GITHUB_OUTPUT
cat artifacts/frontend-results/build-output-short.txt >> $GITHUB_OUTPUT
@@ -117,29 +92,16 @@ jobs:
echo "⚠️ Frontend results artifact not found"
fi
- name: Post combined comment
if: steps.pr-info.outputs.pr_number != '0'
- name: Post advisory results comment
if: steps.backend.outputs.pr_number != '0'
uses: actions/github-script@v7
with:
script: |
const prNumber = ${{ steps.pr-info.outputs.pr_number }};
const prNumber = ${{ steps.backend.outputs.pr_number }};
// PR Info section
const titleStatus = '${{ steps.pr-info.outputs.title_status }}' || '⚠️ Unknown';
const prSize = '${{ steps.pr-info.outputs.size }}' || '⚠️ Unknown';
const prLines = '${{ steps.pr-info.outputs.lines }}' || '0';
const sizeSuggestion = '${{ steps.pr-info.outputs.size_suggestion }}' || '';
let comment = '## 🤖 PR Checks Results\n\n';
comment += 'Thank you for your contribution! Here are the automated check results:\n\n';
// PR Info
comment += '### 📋 PR Information\n\n';
comment += '**Title Format:** ' + titleStatus + '\n';
comment += '**PR Size:** ' + prSize + ' (' + prLines + ' lines changed)\n';
if (sizeSuggestion) {
comment += '\n💡 **Suggestion:** ' + sizeSuggestion + '\n';
}
let comment = '## 🤖 Advisory Check Results\n\n';
comment += 'These are **advisory** checks to help improve code quality. They won\'t block your PR from being merged.\n\n';
comment += '> **Note:** PR title and size checks are handled by the main workflow and may appear in a separate comment.\n\n';
// Backend checks
const fmtStatus = '${{ steps.backend.outputs.fmt_status }}';
@@ -182,43 +144,21 @@ jobs:
}
// Frontend checks
const lintStatus = '${{ steps.frontend.outputs.lint_status }}';
const typecheckStatus = '${{ steps.frontend.outputs.typecheck_status }}';
const buildStatus = '${{ steps.frontend.outputs.build_status }}';
if (lintStatus || typecheckStatus || buildStatus) {
if (buildStatus) {
comment += '\n### ⚛️ Frontend Checks\n\n';
if (lintStatus) {
comment += '**Linting:** ' + lintStatus + '\n';
const lintOutput = `${{ steps.frontend.outputs.lint_output }}`;
if (lintOutput && lintOutput.trim()) {
comment += '<details><summary>Issues found</summary>\n\n```\n' + lintOutput.substring(0, 500) + '\n```\n</details>\n\n';
}
}
if (typecheckStatus) {
comment += '**Type Checking:** ' + typecheckStatus + '\n';
const typecheckOutput = `${{ steps.frontend.outputs.typecheck_output }}`;
if (typecheckOutput && typecheckOutput.trim()) {
comment += '<details><summary>Type errors</summary>\n\n```\n' + typecheckOutput.substring(0, 500) + '\n```\n</details>\n\n';
}
}
if (buildStatus) {
comment += '**Build:** ' + buildStatus + '\n';
const buildOutput = `${{ steps.frontend.outputs.build_output }}`;
if (buildOutput && buildOutput.trim()) {
comment += '<details><summary>Build output</summary>\n\n```\n' + buildOutput.substring(0, 500) + '\n```\n</details>\n\n';
}
comment += '**Build & Type Check:** ' + buildStatus + '\n';
const buildOutput = `${{ steps.frontend.outputs.build_output }}`;
if (buildOutput && buildOutput.trim()) {
comment += '<details><summary>Build output</summary>\n\n```\n' + buildOutput.substring(0, 1000) + '\n```\n</details>\n\n';
}
comment += '\n**Fix locally:**\n';
comment += '```bash\n';
comment += 'cd web\n';
comment += 'npm run lint -- --fix # Fix linting\n';
comment += 'npm run type-check # Check types\n';
comment += 'npm run build # Test build\n';
comment += 'npm run build # Test build (includes type checking)\n';
comment += '```\n';
}

View File

@@ -1,8 +1,12 @@
name: PR Checks - Run
# This workflow runs all PR checks with read-only permissions
# This workflow runs advisory PR checks with read-only permissions
# Safe for fork PRs - results are saved as artifacts
# Companion workflow (pr-checks-comment.yml) will post comments
#
# NOTE: This workflow provides ADVISORY checks (non-blocking)
# Main blocking checks are in pr-checks.yml
# PR title and size checks are handled by pr-checks.yml (no duplication)
on:
pull_request:
@@ -14,63 +18,8 @@ permissions:
contents: read
jobs:
pr-info:
name: PR Information
runs-on: ubuntu-latest
steps:
- name: Check PR title format
id: check-title
run: |
PR_TITLE="${{ github.event.pull_request.title }}"
# Check if title follows conventional commits (expanded type list)
if echo "$PR_TITLE" | grep -qE "^(feat|fix|docs|style|refactor|perf|test|chore|ci|security|build)(\(.+\))?: .+"; then
echo "status=✅ Good" >> $GITHUB_OUTPUT
echo "message=PR title follows Conventional Commits format" >> $GITHUB_OUTPUT
else
echo "status=⚠️ Suggestion" >> $GITHUB_OUTPUT
echo "message=Consider using format: type(scope): description. Valid types: feat, fix, docs, style, refactor, perf, test, chore, ci, security, build" >> $GITHUB_OUTPUT
fi
- name: Calculate PR size and save results
id: pr-size
run: |
ADDITIONS=${{ github.event.pull_request.additions }}
DELETIONS=${{ github.event.pull_request.deletions }}
TOTAL=$((ADDITIONS + DELETIONS))
if [ $TOTAL -lt 100 ]; then
SIZE="🟢 Small"
SUGGESTION=""
elif [ $TOTAL -lt 500 ]; then
SIZE="🟡 Medium"
SUGGESTION=""
else
SIZE="🔴 Large"
SUGGESTION="Consider breaking this into smaller PRs for easier review"
fi
# Save all results to JSON file
cat > pr-info.json <<EOF
{
"pr_number": ${{ github.event.pull_request.number }},
"title_status": "${{ steps.check-title.outputs.status }}",
"title_message": "${{ steps.check-title.outputs.message }}",
"size": "$SIZE",
"lines": $TOTAL,
"size_suggestion": "$SUGGESTION"
}
EOF
cat pr-info.json
- name: Upload PR info results
uses: actions/upload-artifact@v4
with:
name: pr-info-results
path: pr-info.json
retention-days: 1
# Backend advisory checks
# Different from pr-checks.yml: these use continue-on-error and generate reports
backend-checks:
name: Backend Checks
runs-on: ubuntu-latest
@@ -147,6 +96,8 @@ jobs:
test-output-short.txt
retention-days: 1
# Frontend advisory checks
# Different from pr-checks.yml: these use continue-on-error and generate reports
frontend-checks:
name: Frontend Checks
runs-on: ubuntu-latest
@@ -173,43 +124,18 @@ jobs:
continue-on-error: true
run: npm ci
- name: Run linter
if: steps.check-web.outputs.exists == 'true'
id: lint
working-directory: ./web
continue-on-error: true
run: |
if npm run lint 2>&1 | tee lint-output.txt; then
echo "status=✅ Good" >> $GITHUB_OUTPUT
else
echo "status=⚠️ Issues found" >> $GITHUB_OUTPUT
cat lint-output.txt | head -20 > lint-output-short.txt
fi
- name: Type check
if: steps.check-web.outputs.exists == 'true'
id: typecheck
working-directory: ./web
continue-on-error: true
run: |
if npm run type-check 2>&1 | tee typecheck-output.txt; then
echo "status=✅ Good" >> $GITHUB_OUTPUT
else
echo "status=⚠️ Issues found" >> $GITHUB_OUTPUT
cat typecheck-output.txt | head -20 > typecheck-output-short.txt
fi
- name: Build
- name: Build and Type Check
if: steps.check-web.outputs.exists == 'true'
id: build
working-directory: ./web
continue-on-error: true
run: |
# build script includes: tsc && vite build
if npm run build 2>&1 | tee build-output.txt; then
echo "status=✅ Success" >> $GITHUB_OUTPUT
else
echo "status=⚠️ Failed" >> $GITHUB_OUTPUT
cat build-output.txt | tail -20 > build-output-short.txt
cat build-output.txt | tail -30 > build-output-short.txt
fi
- name: Save frontend results
@@ -219,8 +145,6 @@ jobs:
cat > frontend-results.json <<EOF
{
"pr_number": ${{ github.event.pull_request.number }},
"lint_status": "${{ steps.lint.outputs.status }}",
"typecheck_status": "${{ steps.typecheck.outputs.status }}",
"build_status": "${{ steps.build.outputs.status }}"
}
EOF
@@ -232,7 +156,5 @@ jobs:
name: frontend-results
path: |
web/frontend-results.json
web/lint-output-short.txt
web/typecheck-output-short.txt
web/build-output-short.txt
retention-days: 1

View File

@@ -193,11 +193,18 @@ jobs:
run: go mod download
- name: Run go fmt
continue-on-error: true # Don't block PR if formatting issues found
run: |
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
echo "Please run 'go fmt' on your code"
echo "⚠️ Code formatting issues found. Please run 'go fmt ./...' locally."
echo ""
echo "Files needing formatting:"
gofmt -s -l .
echo ""
echo "This is a warning and won't block your PR from being merged."
exit 1
else
echo "✅ All Go files are properly formatted"
fi
- name: Run go vet