Update README.md #21
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: Build and deploy to remote server | |
on: | |
push: | |
branches: [ "main" ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: [ 18.x ] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ matrix.node-version }} | |
cache: 'npm' | |
- name: Install the dependencies | |
run: npm install | |
- name: Build the app | |
run: | | |
npm run build:frontend | |
npm run build:backend | |
- name: Bundle the app | |
run: npm run bundle | |
- name: Upload artifacts | |
uses: actions/upload-artifact@master | |
with: | |
name: bundled-app | |
path: bundle | |
deploy: | |
needs: [build] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download artifacts | |
uses: actions/download-artifact@master | |
with: | |
name: bundled-app | |
path: bundle | |
- name: Copy files via SSH | |
uses: appleboy/scp-action@v0.1.4 | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ${{ secrets.SSH_USER }} | |
key: ${{ secrets.SSH_KEY }} | |
port: ${{ secrets.SSH_PORT }} | |
source: bundle/* | |
target: ${{ secrets.DEST_PATH }} | |
- name: Restart the app | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ${{ secrets.SSH_USER }} | |
key: ${{ secrets.SSH_KEY }} | |
port: ${{ secrets.SSH_PORT }} | |
script: | | |
cd ${{ secrets.DEST_PATH }}/bundle | |
tar -c build server package.json -f artifact.tar | |
cd .. | |
npm install | |
tar -xf bundle/artifact.tar -C . --overwrite | |
rm -rf bundle | |
pm2 restart urfu-ui |