Fix: Resolve .gitignore issues and add missing essential files #4
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
| name: Build Pipeline | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| pull_request: | |
| branches: [ main, develop ] | |
| env: | |
| PYTHON_VERSION: '3.11' | |
| NODE_VERSION: '20' | |
| jobs: | |
| # Build Backend Services | |
| build-backend: | |
| name: Build Backend Services | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| service: [auth-service, data-processing, analytics, api-gateway, data-ingestion, notification] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| - name: Cache Python dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.cache/pip | |
| key: ${{ runner.os }}-pip-${{ matrix.service }}-${{ hashFiles(format('services/{0}/requirements.txt', matrix.service)) }} | |
| restore-keys: | | |
| ${{ runner.os }}-pip-${{ matrix.service }}- | |
| ${{ runner.os }}-pip- | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| if [ -f services/${{ matrix.service }}/requirements.txt ]; then | |
| pip install -r services/${{ matrix.service }}/requirements.txt | |
| fi | |
| - name: Build service | |
| run: | | |
| echo "Building ${{ matrix.service }}..." | |
| cd services/${{ matrix.service }} | |
| # Compile Python files to check for syntax errors | |
| python -m py_compile $(find . -name "*.py") | |
| echo "✅ ${{ matrix.service }} build successful" | |
| # Build Frontend | |
| build-frontend: | |
| name: Build Frontend | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| - name: Cache Node.js dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: frontend/node_modules | |
| key: ${{ runner.os }}-node-${{ hashFiles('frontend/package-lock.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-node- | |
| - name: Debug directory structure | |
| run: | | |
| echo "Current directory: $(pwd)" | |
| echo "Contents of root directory:" | |
| ls -la | |
| echo "Contents of frontend directory:" | |
| ls -la frontend/ || echo "frontend directory not found" | |
| - name: Install dependencies | |
| working-directory: frontend | |
| run: | | |
| echo "Current working directory: $(pwd)" | |
| echo "Contents of current directory:" | |
| ls -la | |
| echo "Node version: $(node --version)" | |
| echo "NPM version: $(npm --version)" | |
| npm install --frozen-lockfile | |
| - name: Build frontend | |
| working-directory: frontend | |
| run: | | |
| echo "Building frontend..." | |
| npm run build | |
| echo "✅ Frontend build successful" | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: frontend-build | |
| path: frontend/dist/ | |
| retention-days: 7 | |
| # Build Docker Images | |
| build-docker: | |
| name: Build Docker Images | |
| runs-on: ubuntu-latest | |
| needs: [build-backend, build-frontend] | |
| strategy: | |
| matrix: | |
| service: [auth-service, data-processing, analytics, api-gateway, data-ingestion, notification, frontend] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Download frontend build artifacts | |
| if: matrix.service == 'frontend' | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: frontend-build | |
| path: frontend/dist/ | |
| - name: Build Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: ${{ matrix.service == 'frontend' && './frontend' || format('./services/{0}', matrix.service) }} | |
| file: ${{ matrix.service == 'frontend' && './frontend/Dockerfile' || format('./services/{0}/Dockerfile', matrix.service) }} | |
| tags: energy-tracking/${{ matrix.service }}:latest | |
| push: false | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Test Docker image | |
| run: | | |
| echo "Testing Docker image for ${{ matrix.service }}..." | |
| docker run --rm energy-tracking/${{ matrix.service }}:latest echo "✅ ${{ matrix.service }} Docker image runs successfully" | |
| # Build Status Summary | |
| build-summary: | |
| name: Build Summary | |
| runs-on: ubuntu-latest | |
| needs: [build-backend, build-frontend, build-docker] | |
| if: always() | |
| steps: | |
| - name: Check build results | |
| run: | | |
| echo "Backend Build: ${{ needs.build-backend.result }}" | |
| echo "Frontend Build: ${{ needs.build-frontend.result }}" | |
| echo "Docker Build: ${{ needs.build-docker.result }}" | |
| if [[ "${{ needs.build-backend.result }}" == "failure" || \ | |
| "${{ needs.build-frontend.result }}" == "failure" || \ | |
| "${{ needs.build-docker.result }}" == "failure" ]]; then | |
| echo "❌ Build failed" | |
| exit 1 | |
| fi | |
| echo "✅ All builds passed successfully" |