1+ name : CI/CD Pipeline
2+
3+ on :
4+ push :
5+ branches :
6+ - main
7+ pull_request :
8+ branches :
9+ - main
10+
11+ jobs :
12+ build-and-deploy :
13+ runs-on : ubuntu-latest
14+
15+ steps :
16+ - name : Checkout code
17+ uses : actions/checkout@v4
18+
19+ - name : Setup Node.js
20+ uses : actions/setup-node@v4
21+ with :
22+ node-version : ' 20'
23+ cache : ' npm'
24+
25+ - name : Install dependencies
26+ run : npm ci
27+
28+ - name : Create .env file
29+ if : github.ref == 'refs/heads/main'
30+ env :
31+ ENV_FILE_CONTENT : ${{ secrets.ENV }}
32+ run : |
33+ echo "$ENV_FILE_CONTENT" > .env
34+
35+ - name : Build project
36+ run : npm run build
37+
38+ - name : Copy files to server
39+ if : github.ref == 'refs/heads/main'
40+ uses : appleboy/scp-action@v0.1.7
41+ with :
42+ host : ${{ secrets.SSH_HOST }}
43+ username : ${{ secrets.SSH_USER }}
44+ key : ${{ secrets.SSH_KEY }}
45+ # We transfer only what's needed for Next.js production
46+ source : ' .next,public,package.json,package-lock.json,.env'
47+ target : ' ~/projects/aqora-forms-01'
48+
49+ - name : Execute post-deployment commands
50+ if : github.ref == 'refs/heads/main'
51+ uses : appleboy/ssh-action@v1.0.3
52+ with :
53+ host : ${{ secrets.SSH_HOST }}
54+ username : ${{ secrets.SSH_USER }}
55+ key : ${{ secrets.SSH_KEY }}
56+ script : |
57+ # Load Node.js environment (for NVM users)
58+ export NVM_DIR="$HOME/.nvm"
59+ [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
60+
61+ # Fallback for standard bash profile
62+ source ~/.bash_profile || source ~/.profile || source ~/.bashrc || true
63+
64+ # Add standard paths just in case
65+ export PATH=$PATH:$HOME/.npm-global/bin:/usr/local/bin:/usr/bin
66+
67+ cd ~/projects/aqora-forms-01
68+
69+ # Install production dependencies
70+ npm ci --omit=dev
71+
72+ pm2 delete aqora-forms-01 || true
73+
74+ # Next.js starts through npm
75+ pm2 start npm --name aqora-forms-01 -- start
76+
77+ pm2 save
0 commit comments