Merge pull request #168 from elizabetheonoja-art/feature/security-tre… #93
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
| coverage-report: | ||
| name: Upload Coverage to Codecov | ||
| runs-on: ubuntu-latest | ||
| needs: [node-lint, node-build] | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| - name: Install pnpm | ||
| run: npm install -g pnpm | ||
| - name: Install dependencies | ||
| run: pnpm install --frozen-lockfile | ||
| - name: Run tests with coverage | ||
| run: pnpm test -- --coverage || npm test -- --coverage | ||
| - name: Upload coverage to Codecov | ||
| uses: codecov/codecov-action@v4 | ||
| with: | ||
| token: ${{ secrets.CODECOV_TOKEN }} | ||
| files: ./coverage/lcov.info | ||
| flags: unittests | ||
| name: codecov-umbrella | ||
| continue-on-error: true | ||
| name: CI | ||
| on: | ||
| push: | ||
| branches: [main, develop] | ||
| pull_request: | ||
| branches: [main, develop] | ||
| jobs: | ||
| rust-test: | ||
| name: Rust Tests | ||
| runs-on: ubuntu-latest | ||
| defaults: | ||
| run: | ||
| working-directory: libs/engine | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| - name: Check for Cargo.toml | ||
| id: check-cargo | ||
| run: | | ||
| if [ -f "Cargo.toml" ]; then | ||
| echo "exists=true" >> $GITHUB_OUTPUT | ||
| echo "Found Cargo.toml, proceeding with Rust tests" | ||
| else | ||
| echo "exists=false" >> $GITHUB_OUTPUT | ||
| echo "No Cargo.toml found in libs/engine. Skipping Rust tests." | ||
| fi | ||
| - name: Install Rust toolchain | ||
| if: steps.check-cargo.outputs.exists == 'true' | ||
| uses: dtolnay/rust-toolchain@stable | ||
| with: | ||
| toolchain: stable | ||
| - name: Cache cargo registry | ||
| if: steps.check-cargo.outputs.exists == 'true' | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: | | ||
| ~/.cargo/bin/ | ||
| ~/.cargo/registry/index/ | ||
| ~/.cargo/registry/cache/ | ||
| ~/.cargo/git/db/ | ||
| libs/engine/target/ | ||
| key: ${{ runner.os }}-cargo-${{ hashFiles('libs/engine/Cargo.lock') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-cargo- | ||
| - name: Run cargo test | ||
| if: steps.check-cargo.outputs.exists == 'true' | ||
| run: cargo test --verbose | ||
| node-lint: | ||
| name: Node.js Lint | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| cache: 'pnpm' | ||
| - name: Detect package manager | ||
| id: package-manager | ||
| run: | | ||
| if [ -f "pnpm-lock.yaml" ]; then | ||
| echo "manager=pnpm" >> $GITHUB_OUTPUT | ||
| echo "lockfile=pnpm-lock.yaml" >> $GITHUB_OUTPUT | ||
| elif [ -f "yarn.lock" ]; then | ||
| echo "manager=yarn" >> $GITHUB_OUTPUT | ||
| - name: Detect package manager | ||
| id: package-manager | ||
| run: | | ||
| if [ -f "pnpm-lock.yaml" ]; then | ||
| echo "manager=pnpm" >> $GITHUB_OUTPUT | ||
| echo "lockfile=pnpm-lock.yaml" >> $GITHUB_OUTPUT | ||
| elif [ -f "yarn.lock" ]; then | ||
| echo "manager=yarn" >> $GITHUB_OUTPUT | ||
| echo "lockfile=yarn.lock" >> $GITHUB_OUTPUT | ||
| elif [ -f "package-lock.json" ]; then | ||
| echo "manager=npm" >> $GITHUB_OUTPUT | ||
| echo "lockfile=package-lock.json" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "manager=npm" >> $GITHUB_OUTPUT | ||
| echo "lockfile=" >> $GITHUB_OUTPUT | ||
| fi | ||
| - name: Check for package.json files | ||
| id: check-package | ||
| run: | | ||
| if [ -f "package.json" ] || [ -f "apps/api/package.json" ] || [ -f "packages/rules/package.json" ]; then | ||
| echo "exists=true" >> $GITHUB_OUTPUT | ||
| echo "Found package.json file(s)" | ||
| else | ||
| echo "exists=false" >> $GITHUB_OUTPUT | ||
| echo "No package.json files found. Skipping Node.js steps." | ||
| fi | ||
| - name: Install dependencies | ||
| if: steps.check-package.outputs.exists == 'true' | ||
| run: | | ||
| case "${{ steps.package-manager.outputs.manager }}" in | ||
| pnpm) | ||
| if [ -f "pnpm-lock.yaml" ]; then | ||
| /usr/local/bin/pnpm install --frozen-lockfile | ||
| else | ||
| echo "No pnpm-lock.yaml found. Skipping dependency installation." | ||
| fi | ||
| ;; | ||
| yarn) | ||
| if [ -f "yarn.lock" ]; then | ||
| yarn install --frozen-lockfile | ||
| else | ||
| echo "No yarn.lock found. Skipping dependency installation." | ||
| fi | ||
| ;; | ||
| npm) | ||
| if [ -f "package-lock.json" ]; then | ||
| npm ci | ||
| elif [ -f "package.json" ]; then | ||
| npm install | ||
| else | ||
| echo "No lock file or package.json found. Skipping dependency installation." | ||
| fi | ||
| ;; | ||
| esac | ||
| - name: Run linter | ||
| if: steps.check-package.outputs.exists == 'true' | ||
| run: | | ||
| MANAGER="${{ steps.package-manager.outputs.manager }}" | ||
| LINT_RAN=false | ||
| # Try root package.json first | ||
| if [ -f "package.json" ] && grep -q '"lint"' package.json; then | ||
| echo "Running lint from root..." | ||
| $MANAGER run lint | ||
| LINT_RAN=true | ||
| fi | ||
| # Try subdirectories | ||
| for dir in apps/api packages/rules; do | ||
| if [ -f "$dir/package.json" ] && grep -q '"lint"' "$dir/package.json"; then | ||
| echo "Running lint in $dir..." | ||
| cd "$dir" && $MANAGER run lint && cd - || exit 1 | ||
| LINT_RAN=true | ||
| fi | ||
| done | ||
| if [ "$LINT_RAN" = "false" ]; then | ||
| echo "No lint script found. Skipping lint step." | ||
| fi | ||
| node-build: | ||
| name: Node.js Build | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| cache: 'pnpm' | ||
| - name: Detect package manager | ||
| id: package-manager | ||
| run: | | ||
| if [ -f "pnpm-lock.yaml" ]; then | ||
| echo "manager=pnpm" >> $GITHUB_OUTPUT | ||
| echo "lockfile=pnpm-lock.yaml" >> $GITHUB_OUTPUT | ||
| elif [ -f "yarn.lock" ]; then | ||
| echo "manager=yarn" >> $GITHUB_OUTPUT | ||
| echo "lockfile=yarn.lock" >> $GITHUB_OUTPUT | ||
| elif [ -f "package-lock.json" ]; then | ||
| echo "manager=npm" >> $GITHUB_OUTPUT | ||
| echo "lockfile=package-lock.json" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "manager=npm" >> $GITHUB_OUTPUT | ||
| echo "lockfile=" >> $GITHUB_OUTPUT | ||
| fi | ||
| - name: Install pnpm | ||
| if: steps.package-manager.outputs.manager == 'pnpm' | ||
| uses: pnpm/action-setup@v2 | ||
| with: | ||
| version: 10.10.0 | ||
| - name: Check for package.json files | ||
| id: check-package-build | ||
| run: | | ||
| if [ -f "package.json" ] || [ -f "apps/api/package.json" ] || [ -f "packages/rules/package.json" ]; then | ||
| echo "exists=true" >> $GITHUB_OUTPUT | ||
| echo "Found package.json file(s)" | ||
| else | ||
| echo "exists=false" >> $GITHUB_OUTPUT | ||
| echo "No package.json files found. Skipping Node.js build." | ||
| fi | ||
| - name: Install dependencies | ||
| if: steps.check-package-build.outputs.exists == 'true' | ||
| run: | | ||
| case "${{ steps.package-manager.outputs.manager }}" in | ||
| pnpm) | ||
| if [ -f "pnpm-lock.yaml" ]; then | ||
| pnpm install --frozen-lockfile | ||
| else | ||
| echo "No pnpm-lock.yaml found. Skipping dependency installation." | ||
| fi | ||
| ;; | ||
| yarn) | ||
| if [ -f "yarn.lock" ]; then | ||
| yarn install --frozen-lockfile | ||
| else | ||
| echo "No yarn.lock found. Skipping dependency installation." | ||
| fi | ||
| ;; | ||
| npm) | ||
| if [ -f "package-lock.json" ]; then | ||
| npm ci | ||
| elif [ -f "package.json" ]; then | ||
| npm install | ||
| else | ||
| echo "No lock file or package.json found. Skipping dependency installation." | ||
| fi | ||
| ;; | ||
| esac | ||
| - name: Run build | ||
| if: steps.check-package-build.outputs.exists == 'true' | ||
| run: | | ||
| MANAGER="${{ steps.package-manager.outputs.manager }}" | ||
| BUILD_RAN=false | ||
| # Try root package.json first | ||
| if [ -f "package.json" ] && grep -q '"build"' package.json; then | ||
| echo "Running build from root..." | ||
| $MANAGER run build | ||
| BUILD_RAN=true | ||
| fi | ||
| # Try subdirectories | ||
| for dir in apps/api packages/rules; do | ||
| if [ -f "$dir/package.json" ] && grep -q '"build"' "$dir/package.json"; then | ||
| echo "Running build in $dir..." | ||
| cd "$dir" && $MANAGER run build && cd - || exit 1 | ||
| BUILD_RAN=true | ||
| fi | ||
| done | ||
| if [ "$BUILD_RAN" = "false" ]; then | ||
| echo "No build script found. Skipping build step." | ||
| fi | ||
| e2e-tests: | ||
| name: E2E Tests | ||
| runs-on: ubuntu-latest | ||
| services: | ||
| postgres: | ||
| image: postgres:15 | ||
| env: | ||
| POSTGRES_PASSWORD: postgres | ||
| POSTGRES_DB: gasguard_test | ||
| options: >- | ||
| --health-cmd pg_isready | ||
| --health-interval 10s | ||
| --health-timeout 5s | ||
| --health-retries 5 | ||
| ports: | ||
| - 5432:5432 | ||
| redis: | ||
| image: redis:7-alpine | ||
| ports: | ||
| - 6379:6379 | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| cache: 'npm' | ||
| - name: Install pnpm | ||
| uses: pnpm/action-setup@v2 | ||
| with: | ||
| version: 8 | ||
| - name: Install dependencies | ||
| run: | | ||
| if [ -f "pnpm-lock.yaml" ]; then | ||
| pnpm install --frozen-lockfile | ||
| else | ||
| echo "No pnpm-lock.yaml found." | ||
| exit 1 | ||
| fi | ||
| - name: Check for E2E test directory | ||
| id: check-e2e | ||
| run: | | ||
| if [ -d "apps/api-service/test/e2e" ]; then | ||
| echo "exists=true" >> $GITHUB_OUTPUT | ||
| echo "E2E test directory found" | ||
| else | ||
| echo "exists=false" >> $GITHUB_OUTPUT | ||
| echo "E2E test directory not found" | ||
| fi | ||
| - name: Run E2E tests | ||
| if: steps.check-e2e.outputs.exists == 'true' | ||
| run: | | ||
| cd apps/api-service | ||
| pnpm run test:e2e | ||
| env: | ||
| DATABASE_URL: postgresql://postgres:postgres@localhost:5432/gasguard_test | ||
| REDIS_URL: redis://localhost:6379 | ||
| NODE_ENV: test | ||
| - name: Upload test results | ||
| if: always() && steps.check-e2e.outputs.exists == 'true' | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: e2e-test-results | ||
| path: apps/api-service/test-results/ | ||
| if-no-files-found: ignore | ||