Skip to content

Commit

Permalink
build in workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Andcool-Systems committed Jul 28, 2024
1 parent 22079a3 commit 6de3a53
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Check and Deploy to Server
name: Build and Deploy to Server

on:
push:
Expand All @@ -14,7 +14,7 @@ jobs:
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: "20"

Expand All @@ -24,6 +24,15 @@ jobs:
- name: Run build
run: npm run build

- name: Archive production artifacts
run: tar -czf build.tar.gz .next public package.json package-lock.json

- name: Upload production artifacts
uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: build.tar.gz

deploy:
runs-on: ubuntu-latest
needs: build
Expand All @@ -32,22 +41,29 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Download production artifacts
uses: actions/download-artifact@v4
with:
name: build-artifacts
path: .

- name: Install SSH and SCP
run: sudo apt-get update && sudo apt-get install -y openssh-client sshpass

- name: Copy files via SCP
- name: Copy build artifacts via SCP
env:
SSHPASS: ${{ secrets.ROOT_SSH_PASSWORD }}
run: |
sshpass -e scp -o StrictHostKeyChecking=no -r ./* root@${{ secrets.SERVER_IP }}:/home/ppl_site
sshpass -e scp -o StrictHostKeyChecking=no build.tar.gz root@${{ secrets.SERVER_IP }}:/home/ppl_site
- name: Execute remote commands
- name: Extract build artifacts on server
env:
SSHPASS: ${{ secrets.ROOT_SSH_PASSWORD }}
run: |
sshpass -e ssh -o StrictHostKeyChecking=no root@${{ secrets.SERVER_IP }} << 'EOF'
cd /home/ppl_site
npm install
npm run build
tar -xzf build.tar.gz
rm build.tar.gz
npm install --production
systemctl restart ppl_site
EOF

0 comments on commit 6de3a53

Please sign in to comment.