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

View File

@@ -1,8 +1,12 @@
name: PR Checks - Run 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 # Safe for fork PRs - results are saved as artifacts
# Companion workflow (pr-checks-comment.yml) will post comments # 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: on:
pull_request: pull_request:
@@ -14,63 +18,8 @@ permissions:
contents: read contents: read
jobs: jobs:
pr-info: # Backend advisory checks
name: PR Information # Different from pr-checks.yml: these use continue-on-error and generate reports
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-checks: backend-checks:
name: Backend Checks name: Backend Checks
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -147,6 +96,8 @@ jobs:
test-output-short.txt test-output-short.txt
retention-days: 1 retention-days: 1
# Frontend advisory checks
# Different from pr-checks.yml: these use continue-on-error and generate reports
frontend-checks: frontend-checks:
name: Frontend Checks name: Frontend Checks
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -173,43 +124,18 @@ jobs:
continue-on-error: true continue-on-error: true
run: npm ci run: npm ci
- name: Run linter - name: Build and Type Check
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
if: steps.check-web.outputs.exists == 'true' if: steps.check-web.outputs.exists == 'true'
id: build id: build
working-directory: ./web working-directory: ./web
continue-on-error: true continue-on-error: true
run: | run: |
# build script includes: tsc && vite build
if npm run build 2>&1 | tee build-output.txt; then if npm run build 2>&1 | tee build-output.txt; then
echo "status=✅ Success" >> $GITHUB_OUTPUT echo "status=✅ Success" >> $GITHUB_OUTPUT
else else
echo "status=⚠️ Failed" >> $GITHUB_OUTPUT 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 fi
- name: Save frontend results - name: Save frontend results
@@ -219,8 +145,6 @@ jobs:
cat > frontend-results.json <<EOF cat > frontend-results.json <<EOF
{ {
"pr_number": ${{ github.event.pull_request.number }}, "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 }}" "build_status": "${{ steps.build.outputs.status }}"
} }
EOF EOF
@@ -232,7 +156,5 @@ jobs:
name: frontend-results name: frontend-results
path: | path: |
web/frontend-results.json web/frontend-results.json
web/lint-output-short.txt
web/typecheck-output-short.txt
web/build-output-short.txt web/build-output-short.txt
retention-days: 1 retention-days: 1

View File

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