Merge pull request #846 from OFFER-HUB/feat/improve-project #150
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: Backend CI/CD | |
on: | |
push: | |
branches: [main] | |
paths: | |
- "backend/**" | |
pull_request: | |
branches: [main] | |
paths: | |
- "backend/**" | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: ./backend | |
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" | |
cache-dependency-path: backend/package-lock.json | |
- name: Cache node_modules | |
uses: actions/cache@v4 | |
with: | |
path: backend/node_modules | |
key: ${{ runner.os }}-node-${{ hashFiles('backend/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node- | |
- name: Cache build output | |
uses: actions/cache@v4 | |
with: | |
path: backend/dist | |
key: ${{ runner.os }}-build-${{ hashFiles('backend/src/**/*.ts') }} | |
restore-keys: | | |
${{ runner.os }}-build- | |
- name: Install dependencies | |
run: npm ci | |
- name: Run linting | |
run: npm run lint | |
- name: Build application | |
run: npm run build | |
- name: Upload build artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: backend-build-${{ matrix.node-version }} | |
path: backend/dist/ | |
retention-days: 7 | |
security: | |
runs-on: ubuntu-latest | |
needs: build | |
defaults: | |
run: | |
working-directory: ./backend | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "18.x" | |
cache: "npm" | |
cache-dependency-path: backend/package-lock.json | |
- name: Install dependencies | |
run: npm ci | |
- name: Run security audit | |
run: npm audit --audit-level=moderate |