refactor: update note parsing functions for improved clarity and erro… #37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # CI/CD Pipeline - OSM-Notes-Viewer | |
| # Unified workflow structure for Node.js/JavaScript projects | |
| # Author: Andres Gomez (AngocA) | |
| # Version: 2026-01-27 | |
| name: CI/CD Pipeline | |
| on: | |
| push: | |
| branches: [main, develop] | |
| pull_request: | |
| branches: [main, develop] | |
| schedule: | |
| # Run weekly on Monday at 2am UTC | |
| - cron: '0 2 * * 1' | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| env: | |
| NODE_VERSION: '18.x' | |
| jobs: | |
| # ============================================================================ | |
| # STAGE 1: Quality Checks | |
| # ============================================================================ | |
| quality: | |
| name: Code Quality Checks | |
| runs-on: ubuntu-latest | |
| 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 --prefer-offline --no-audit | |
| - name: Check code formatting | |
| run: npm run lint || echo "No lint script found" | |
| - name: Check Prettier formatting | |
| run: | | |
| npx prettier --check "**/*.{js,md,json,yaml,yml,css,html}" --ignore-path .prettierignore || { | |
| echo "⚠️ Prettier formatting issues found" | |
| exit 1 | |
| } | |
| - name: Validate package.json | |
| run: npm run validate || echo "Package validation skipped" | |
| # ============================================================================ | |
| # STAGE 2: Tests | |
| # ============================================================================ | |
| test: | |
| name: Run Tests | |
| runs-on: ubuntu-latest | |
| needs: [quality] | |
| strategy: | |
| matrix: | |
| node-version: [18.x, 20.x] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js ${{ matrix.node-version }} | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci --prefer-offline --no-audit | |
| - name: Run all tests (master test command) | |
| run: npm run test:run | |
| - name: Upload coverage | |
| if: always() | |
| uses: codecov/codecov-action@v4 | |
| with: | |
| file: ./coverage/coverage-final.json | |
| flags: unittests | |
| fail_ci_if_error: false | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| # ============================================================================ | |
| # STAGE 3: Build | |
| # ============================================================================ | |
| build: | |
| name: Build Check | |
| runs-on: ubuntu-latest | |
| needs: [test] | |
| 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 --prefer-offline --no-audit | |
| - name: Build project | |
| run: npm run build | |
| - name: Check build artifacts | |
| run: | | |
| if [ -d "dist" ]; then | |
| echo "✅ Build successful - dist directory exists" | |
| ls -la dist/ | |
| else | |
| echo "⚠️ No dist directory found (this is OK for static projects)" | |
| fi | |
| # ============================================================================ | |
| # STAGE 4: Security | |
| # ============================================================================ | |
| security: | |
| name: Security Audit | |
| runs-on: ubuntu-latest | |
| 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 --prefer-offline --no-audit | |
| - name: Run security audit | |
| run: npm audit --audit-level=moderate || true | |
| # ============================================================================ | |
| # STAGE 5: Summary | |
| # ============================================================================ | |
| summary: | |
| name: CI Summary | |
| runs-on: ubuntu-latest | |
| needs: [quality, test, build, security] | |
| if: always() | |
| steps: | |
| - name: Check all results | |
| run: | | |
| echo "## CI Results Summary - OSM-Notes-Viewer" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| if [ "${{ needs.quality.result }}" == "success" ]; then | |
| echo "✅ Code Quality: PASSED" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "❌ Code Quality: FAILED" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| if [ "${{ needs.test.result }}" == "success" ]; then | |
| echo "✅ Tests: PASSED" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "❌ Tests: FAILED" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| if [ "${{ needs.build.result }}" == "success" ]; then | |
| echo "✅ Build: PASSED" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "❌ Build: FAILED" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| if [ "${{ needs.security.result }}" == "success" ] || [ "${{ needs.security.result }}" == "skipped" ]; then | |
| echo "✅ Security Audit: PASSED/SKIPPED" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "❌ Security Audit: FAILED" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| # Exit with error if any job failed | |
| if [ "${{ needs.quality.result }}" != "success" ] || \ | |
| [ "${{ needs.test.result }}" != "success" ] || \ | |
| [ "${{ needs.build.result }}" != "success" ] || \ | |
| ([ "${{ needs.security.result }}" != "success" ] && [ "${{ needs.security.result }}" != "skipped" ]); then | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "❌ Some checks failed. Please review the logs above." >> $GITHUB_STEP_SUMMARY | |
| exit 1 | |
| else | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "✅ All checks passed!" >> $GITHUB_STEP_SUMMARY | |
| exit 0 | |
| fi | |
| # ============================================================================ | |
| # STAGE 6: Deployment (conditional) | |
| # ============================================================================ | |
| deploy-staging: | |
| name: Deploy to Staging | |
| runs-on: ubuntu-latest | |
| needs: [build, security] | |
| if: github.ref == 'refs/heads/develop' && github.event_name == 'push' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Deploy to staging | |
| run: | | |
| echo "🚀 Deploying to staging environment..." | |
| echo "This would deploy to a staging server" | |
| # Add your staging deployment commands here | |
| deploy-production: | |
| name: Deploy to Production | |
| runs-on: ubuntu-latest | |
| needs: [build, security] | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Deploy to production | |
| run: | | |
| echo "🚀 Deploying to production..." | |
| echo "Build passed all checks - ready for production" | |
| # GitHub Pages deployment is handled by separate workflow |