Update main.yml #32
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 | |
on: | |
push: | |
branches: | |
- main # main 브랜치에 푸시될 때 실행 | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest # 최신 Ubuntu 버전에서 실행 | |
steps: | |
# Git 체크아웃 | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
# Node.js 버전 설정 | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '16' | |
# node_modules 캐시 | |
- name: Cache node_modules | |
uses: actions/cache@v2 | |
with: | |
path: ./node_modules | |
key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node-modules- | |
# 의존성 설치 및 빌드 | |
- name: Install dependencies and build | |
run: | | |
npm install | |
npm run build | |
# 빌드 파일을 서버로 전송 | |
- name: Copy build directory to server | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USER }} | |
password: ${{ secrets.PASSWORD }} | |
port: ${{ secrets.PORT }} | |
source: "./dist/*" | |
target: "/home/rayoen/dist" | |
# 복사한 파일 권한 설정 및 Nginx 재시작 | |
- name: Move files to target directory and restart Nginx | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USER }} | |
password: ${{ secrets.PASSWORD }} | |
port: ${{ secrets.PORT }} | |
script: | | |
# 대상 폴더가 이미 있는 경우 삭제 | |
sudo rm -rf /var/www/html/dist | |
# /home/rayoen/dist의 파일을 /var/www/html/dist로 이동 | |
sudo mv /home/rayoen/dist /var/www/html/dist | |
# 권한 설정 | |
sudo chmod -R 755 /var/www/html/dist | |
# Nginx 재시작 | |
sudo service nginx restart |