Add ESLint and n8n webhook notifications to CI/CD

- Add ESLint 9 with flat config for Node.js linting
- Add lint and lint:fix npm scripts
- Add lint job to CI/CD pipeline
- Add notify job to send test/lint results to n8n webhook
- Webhook reports pass/fail status with failure details

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-28 09:39:55 -07:00
parent 8dfdfdc8bb
commit 6daacf4d12
4 changed files with 998 additions and 3 deletions

View File

@ -12,6 +12,42 @@ env:
IMAGE_NAME: apartment-api
jobs:
# ============================================================
# Lint Job - ESLint static analysis
# ============================================================
lint:
name: Run Linting
runs-on: ubuntu-latest
outputs:
status: ${{ steps.lint.outcome }}
output: ${{ steps.lint.outputs.lint_output }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run ESLint
id: lint
continue-on-error: true
run: |
set +e
OUTPUT=$(npm run lint 2>&1)
EXIT_CODE=$?
echo "lint_output<<EOF" >> $GITHUB_OUTPUT
echo "$OUTPUT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
exit $EXIT_CODE
# ============================================================
# Test Job - Runs first, blocks everything if tests fail
# ============================================================
@ -19,6 +55,10 @@ jobs:
name: Run Tests
runs-on: ubuntu-latest
outputs:
status: ${{ steps.test.outcome }}
output: ${{ steps.test.outputs.test_output }}
services:
mongodb:
image: mongo:7
@ -44,12 +84,107 @@ jobs:
run: npm ci
- name: Run tests
run: npm test -- --runInBand
id: test
continue-on-error: true
run: |
set +e
OUTPUT=$(npm test -- --runInBand 2>&1)
EXIT_CODE=$?
echo "test_output<<EOF" >> $GITHUB_OUTPUT
echo "$OUTPUT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
exit $EXIT_CODE
env:
MONGO_URI: mongodb://localhost:27018
JWT_SECRET: test-jwt-secret-for-ci
NODE_ENV: test
# ============================================================
# Notify Job - Send results to n8n webhook
# ============================================================
notify:
name: Send Webhook Notification
runs-on: ubuntu-latest
needs: [lint, test]
if: always()
steps:
- name: Send results to n8n webhook
run: |
# Determine overall status
LINT_STATUS="${{ needs.lint.result }}"
TEST_STATUS="${{ needs.test.result }}"
if [ "$LINT_STATUS" = "success" ] && [ "$TEST_STATUS" = "success" ]; then
OVERALL_STATUS="success"
else
OVERALL_STATUS="failure"
fi
# Truncate outputs if too long (max 10000 chars each)
LINT_OUTPUT=$(echo '${{ needs.lint.outputs.output }}' | head -c 10000)
TEST_OUTPUT=$(echo '${{ needs.test.outputs.output }}' | head -c 10000)
# Build JSON payload
PAYLOAD=$(jq -n \
--arg repo "${{ github.repository }}" \
--arg branch "${{ github.ref_name }}" \
--arg commit "${{ github.sha }}" \
--arg commit_short "$(echo '${{ github.sha }}' | cut -c1-7)" \
--arg commit_message "${{ github.event.head_commit.message || github.event.pull_request.title || 'N/A' }}" \
--arg author "${{ github.actor }}" \
--arg event "${{ github.event_name }}" \
--arg run_id "${{ github.run_id }}" \
--arg run_url "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
--arg overall_status "$OVERALL_STATUS" \
--arg lint_status "$LINT_STATUS" \
--arg lint_output "$LINT_OUTPUT" \
--arg test_status "$TEST_STATUS" \
--arg test_output "$TEST_OUTPUT" \
--arg timestamp "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
'{
repository: $repo,
branch: $branch,
commit: {
sha: $commit,
short_sha: $commit_short,
message: $commit_message,
author: $author
},
event: $event,
run: {
id: $run_id,
url: $run_url
},
status: $overall_status,
results: {
lint: {
status: $lint_status,
output: (if $lint_status != "success" then $lint_output else null end)
},
test: {
status: $test_status,
output: (if $test_status != "success" then $test_output else null end)
}
},
timestamp: $timestamp
}')
# Send webhook
curl -X POST \
-H "Content-Type: application/json" \
-d "$PAYLOAD" \
"${{ secrets.N8N_WEBHOOK_URL }}" \
--fail --silent --show-error
- name: Fail if lint or tests failed
if: needs.lint.result != 'success' || needs.test.result != 'success'
run: |
echo "❌ Pipeline failed:"
echo " Lint: ${{ needs.lint.result }}"
echo " Test: ${{ needs.test.result }}"
exit 1
# ============================================================
# Dependency Scan Job - Runs in parallel with tests
# ============================================================
@ -80,7 +215,7 @@ jobs:
build:
name: Build & Push Image
runs-on: ubuntu-latest
needs: [test, scan-deps]
needs: [lint, test, scan-deps, notify]
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
outputs: