Skip to content

Commit 9fabc24

Browse files
Merge pull request #22 from pineapple-EPITA/feature/ci-deploy-workflow
ci: add deployment workflow for testing, building, and linting at eve…
2 parents 1f5c82d + c0f2c70 commit 9fabc24

File tree

1 file changed

+63
-48
lines changed

1 file changed

+63
-48
lines changed

.github/workflows/deploy.yml

Lines changed: 63 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,75 @@
1-
name: Deploy
1+
name: CI/CD Pipeline
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [main, develop]
66

77
jobs:
8-
test-build-deploy:
8+
build-test-deploy:
99
runs-on: ubuntu-latest
1010

1111
strategy:
1212
matrix:
1313
node-version: [18.x]
1414

1515
steps:
16-
- uses: actions/checkout@v3
17-
18-
- name: Use Node.js ${{ matrix.node-version }}
19-
uses: actions/setup-node@v3
20-
with:
21-
node-version: ${{ matrix.node-version }}
22-
cache: 'npm'
23-
24-
- name: Install dependencies
25-
run: npm ci
26-
27-
- name: Run linting
28-
run: npm run lint
29-
30-
- name: Run tests
31-
env:
32-
NODE_ENV: test
33-
MONGO_URI: ${{ secrets.MONGO_URI_TEST }}
34-
DB_USER: ${{ secrets.DB_USER_TEST }}
35-
DB_PASSWORD: ${{ secrets.DB_PASSWORD_TEST }}
36-
DB_HOST: ${{ secrets.DB_HOST_TEST }}
37-
DB_NAME: ${{ secrets.DB_NAME_TEST }}
38-
SESSION_SECRET: ${{ secrets.SESSION_SECRET_TEST }}
39-
run: npm test
40-
41-
- name: Build
42-
run: npm run build
43-
44-
- name: Verify build
45-
run: |
46-
if [ ! -d "dist" ]; then
47-
echo "Build failed: dist directory not found"
48-
exit 1
49-
fi
50-
if [ ! -f "dist/server.js" ]; then
51-
echo "Build failed: server.js not found in dist directory"
52-
exit 1
53-
fi
54-
55-
- name: Check for build artifacts
56-
run: |
57-
echo "Build artifacts:"
58-
ls -la dist/
59-
echo "Checking server.js content:"
60-
head -n 5 dist/server.js
16+
- name: Checkout repo
17+
uses: actions/checkout@v4
18+
19+
- name: 🔧 Setup Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: ${{ matrix.node-version }}
23+
cache: npm
24+
25+
- name: Install dependencies
26+
run: npm ci
27+
28+
- name: Lint code
29+
run: npm run lint
30+
31+
- name: Run tests
32+
env:
33+
NODE_ENV: test
34+
MONGO_URI: ${{ secrets.MONGO_URI_TEST }}
35+
DB_USER: ${{ secrets.DB_USER_TEST }}
36+
DB_PASSWORD: ${{ secrets.DB_PASSWORD_TEST }}
37+
DB_HOST: ${{ secrets.DB_HOST_TEST }}
38+
DB_NAME: ${{ secrets.DB_NAME_TEST }}
39+
SESSION_SECRET: ${{ secrets.SESSION_SECRET_TEST }}
40+
run: npm test
41+
42+
- name: Build project
43+
run: npm run build
44+
45+
- name: Verify build output
46+
run: |
47+
test -d dist || (echo "dist/ directory not found!" && exit 1)
48+
test -f dist/server.js || (echo "dist/server.js not found!" && exit 1)
49+
echo "Build verified successfully."
50+
51+
- name: Deploy (only from main)
52+
if: github.ref == 'refs/heads/main'
53+
env:
54+
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
55+
DEPLOY_URL: ${{ secrets.DEPLOY_URL }}
56+
NODE_ENV: production
57+
MONGO_URI: ${{ secrets.MONGO_URI_PROD }}
58+
DB_USER: ${{ secrets.DB_USER_PROD }}
59+
DB_PASSWORD: ${{ secrets.DB_PASSWORD_PROD }}
60+
DB_HOST: ${{ secrets.DB_HOST_PROD }}
61+
DB_NAME: ${{ secrets.DB_NAME_PROD }}
62+
SESSION_SECRET: ${{ secrets.SESSION_SECRET_PROD }}
63+
run: |
64+
echo "Starting deployment..."
65+
66+
# Example SSH Deployment
67+
# chmod 600 deploy_key && ssh -i deploy_key user@host "
68+
# cd /app &&
69+
# git pull &&
70+
# npm ci &&
71+
# npm run build &&
72+
# pm2 restart app
73+
# "
74+
75+
echo "Deployment completed."

0 commit comments

Comments
 (0)