update github workflow to build the project before deploying #8
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: π Deploy website on push | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
web-deploy: | |
name: π Deploy | |
runs-on: ubuntu-latest | |
steps: | |
- name: π Get latest code | |
uses: actions/checkout@v4 | |
# Step 1: Install and Build Project Locally | |
- name: π¨ Build Project Locally | |
run: | | |
npm install | |
npm run build | |
# Step 2: Deploy Files to the Server | |
- name: π Sync files to server | |
uses: SamKirkland/FTP-Deploy-Action@v4.3.5 | |
with: | |
server: ${{ vars.FTP_SERVER }} | |
username: ${{ vars.FTP_USERNAME }} | |
password: ${{ vars.FTP_PASSWORD }} | |
local-dir: ./ # Sync all files in the root directory (after build) | |
server-dir: /home/tbtouris/api/ # Your server directory | |
exclude: | | |
**/.git* | |
**/.git*/** | |
**/node_modules/** | |
**/frontend/node_modules/** | |
**/backend/node_modules/** | |
# Step 3: Run npm install on the server after deployment | |
- name: π§ Run npm install on server | |
run: | | |
sshpass -p "${{ vars.SSH_PASSWORD }}" ssh -o StrictHostKeyChecking=no -T -p ${{ vars.SSH_PORT }} ${{ vars.SSH_USER }}@${{ vars.SSH_HOST }} << 'EOF' | |
cd /home/tbtouris/api | |
npm install | |
EOF | |
env: | |
SSH_PASSWORD: ${{ vars.SSH_PASSWORD }} | |
SSH_USER: ${{ vars.SSH_USER }} | |
SSH_HOST: ${{ vars.SSH_HOST }} | |
SSH_PORT: ${{ vars.SSH_PORT }} |