|
| 1 | +name: CI/CD Pipeline |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, develop ] |
| 6 | + pull_request: |
| 7 | + branches: [ main ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + test: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + strategy: |
| 14 | + matrix: |
| 15 | + node-version: [16.x, 18.x, 20.x] |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Checkout code |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Setup Node.js ${{ matrix.node-version }} |
| 22 | + uses: actions/setup-node@v4 |
| 23 | + with: |
| 24 | + node-version: ${{ matrix.node-version }} |
| 25 | + cache: 'npm' |
| 26 | + |
| 27 | + - name: Install dependencies |
| 28 | + run: npm ci |
| 29 | + |
| 30 | + - name: Run linter |
| 31 | + run: npm run lint |
| 32 | + |
| 33 | + - name: Run tests |
| 34 | + run: npm test -- --coverage --watchAll=false |
| 35 | + |
| 36 | + - name: Build application |
| 37 | + run: npm run build |
| 38 | + |
| 39 | + - name: Upload coverage reports |
| 40 | + uses: codecov/codecov-action@v3 |
| 41 | + if: matrix.node-version == '18.x' |
| 42 | + with: |
| 43 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 44 | + files: ./coverage/lcov.info |
| 45 | + fail_ci_if_error: true |
| 46 | + |
| 47 | + security: |
| 48 | + runs-on: ubuntu-latest |
| 49 | + |
| 50 | + steps: |
| 51 | + - name: Checkout code |
| 52 | + uses: actions/checkout@v4 |
| 53 | + |
| 54 | + - name: Setup Node.js |
| 55 | + uses: actions/setup-node@v4 |
| 56 | + with: |
| 57 | + node-version: '18.x' |
| 58 | + cache: 'npm' |
| 59 | + |
| 60 | + - name: Install dependencies |
| 61 | + run: npm ci |
| 62 | + |
| 63 | + - name: Run security audit |
| 64 | + run: npm audit --audit-level=moderate |
| 65 | + |
| 66 | + - name: Run dependency check |
| 67 | + run: npx audit-ci --moderate |
| 68 | + |
| 69 | + build-and-deploy: |
| 70 | + needs: [test, security] |
| 71 | + runs-on: ubuntu-latest |
| 72 | + if: github.ref == 'refs/heads/main' && github.event_name == 'push' |
| 73 | + |
| 74 | + steps: |
| 75 | + - name: Checkout code |
| 76 | + uses: actions/checkout@v4 |
| 77 | + |
| 78 | + - name: Setup Node.js |
| 79 | + uses: actions/setup-node@v4 |
| 80 | + with: |
| 81 | + node-version: '18.x' |
| 82 | + cache: 'npm' |
| 83 | + |
| 84 | + - name: Install dependencies |
| 85 | + run: npm ci |
| 86 | + |
| 87 | + - name: Build for production |
| 88 | + run: npm run build |
| 89 | + |
| 90 | + - name: Create deployment package |
| 91 | + run: | |
| 92 | + mkdir -p deployment |
| 93 | + cp -r build/* deployment/ |
| 94 | + cd deployment |
| 95 | + zip -r ../react-neural-engine-${{ github.sha }}.zip . |
| 96 | + |
| 97 | + - name: Upload build artifacts |
| 98 | + uses: actions/upload-artifact@v3 |
| 99 | + with: |
| 100 | + name: build-files |
| 101 | + path: react-neural-engine-${{ github.sha }}.zip |
| 102 | + retention-days: 30 |
| 103 | + |
0 commit comments