fix: Github Action issue #14
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: "/var/www/html/dist" | |
# 원격 서버에서 Nginx 재시작 | |
- name: Restart Nginx on server | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USER }} | |
password: ${{ secrets.PASSWORD }} | |
port: ${{ secrets.PORT }} | |
script: | | |
sudo service nginx restart |