Update ci.yml #20
This file contains 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: Fullstack Tasks Application Pipeline | |
# Trigger the workflow | |
on: | |
push: | |
branches: | |
- "**" # Matches every branch for push events | |
pull_request: | |
branches: | |
- "**" # Matches every branch for pull request events | |
jobs: | |
# Step 1: Set up Node.js environment | |
setup-node: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "20.17.0" # Specify Node.js version | |
# Step 2: Cache Node.js Modules | |
cache-dependencies: | |
needs: setup-node | |
runs-on: ubuntu-latest | |
steps: | |
- name: Restore Server Node.js Modules Cache | |
uses: actions/cache@v3 | |
with: | |
path: server/node_modules | |
key: ${{ runner.os }}-server-node-${{ hashFiles('server/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-server-node- | |
- name: Restore Frontend Node.js Modules Cache | |
uses: actions/cache@v3 | |
with: | |
path: frontend/node_modules | |
key: ${{ runner.os }}-frontend-node-${{ hashFiles('frontend/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-frontend-node- | |
# Step 3: Install Dependencies | |
install-dependencies: | |
needs: cache-dependencies | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
- name: Install Server Dependencies | |
run: npm ci | |
working-directory: ./server | |
- name: Install Frontend Dependencies | |
run: npm ci | |
working-directory: ./frontend | |
- name: Save Server Node.js Modules Cache | |
uses: actions/cache@v3 | |
with: | |
path: server/node_modules | |
key: ${{ runner.os }}-server-node-${{ hashFiles('server/package-lock.json') }} | |
- name: Save Frontend Node.js Modules Cache | |
uses: actions/cache@v3 | |
with: | |
path: frontend/node_modules | |
key: ${{ runner.os }}-frontend-node-${{ hashFiles('frontend/package-lock.json') }} | |
# Step 4: Lint the code | |
lint: | |
needs: install-dependencies | |
runs-on: ubuntu-latest | |
steps: | |
- name: Lint Server Code | |
run: npm run eslint | |
working-directory: ./server | |
- name: Lint Frontend Code | |
run: npm run lint | |
working-directory: ./frontend | |
# Step 5: Formatting job | |
format: | |
needs: install-dependencies | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check Frontend Code Formatting with Prettier | |
run: npm run prettier | |
working-directory: ./frontend | |
# Step 6: Security audit for both server and frontend | |
security-audit: | |
needs: install-dependencies | |
runs-on: ubuntu-latest | |
steps: | |
- name: Run Server npm audit | |
run: npm run audit | |
working-directory: ./server | |
continue-on-error: true | |
- name: Run Frontend npm audit | |
run: npm run audit | |
working-directory: ./frontend | |
continue-on-error: true | |
# Step 7: Run unit tests | |
test: | |
needs: [lint, format, security-audit] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Run Frontend Unit Tests | |
run: npm run test:coverage | |
working-directory: ./frontend | |
env: | |
CI: true # Ensures Vitest runs in Continuous Integration mode | |
# Step 8: Build the project | |
build: | |
needs: test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Build Server for Production | |
run: npm run build | |
working-directory: ./server | |
env: | |
NODE_ENV: production | |
- name: Build Frontend for Production | |
run: npm run build:prod | |
working-directory: ./frontend | |
env: | |
NODE_ENV: production | |
- name: Save Server Build Artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: server-build | |
path: server/build | |
- name: Save Frontend Build Artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: frontend-build | |
path: frontend/build |