ci: update file #9
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 React App to Server | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: 🎯 Checkout Code | |
uses: actions/checkout@v2 | |
- name: 🧩 Set up Node.js 20.12.2 | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '20.12.2' | |
- name: 🛠️ Install Dependencies and Build Project | |
run: | | |
npm install | |
npm run build | |
- name: 🔑 Set up SSH Agent | |
uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
- name: 📝 Add SSH Host Key | |
run: | | |
mkdir -p ~/.ssh | |
ssh-keyscan -H ${{ secrets.SERVER_IP }} >> ~/.ssh/known_hosts | |
cat ~/.ssh/known_hosts # Add this for debugging to ensure key is correctly added | |
- name: 📂 Create Directory on Server | |
run: | | |
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=~/.ssh/known_hosts jiho99322@${{ secrets.SERVER_IP }} "mkdir -p /var/www/html/dist" | |
- name: 📤 Copy Files to Server | |
run: | | |
scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=~/.ssh/known_hosts -r dist/* jiho99322@${{ secrets.SERVER_IP }}:/tmp/ | |
- name: ⚙️ Move Files to Target Directory and Set Permissions | |
run: | | |
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=~/.ssh/known_hosts jiho99322@${{ secrets.SERVER_IP }} "sudo mv /tmp/* /var/www/html/dist/ && sudo chmod -R 755 /var/www/html/dist" | |
- name: 🔄 Restart Nginx on Server | |
run: | | |
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=~/.ssh/known_hosts jiho99322@${{ secrets.SERVER_IP }} "sudo systemctl restart nginx" |