Skip to content

Build and Deploy Preview / Frontend #1

Build and Deploy Preview / Frontend

Build and Deploy Preview / Frontend #1

name: Build and Deploy Preview / Frontend
on:
workflow_dispatch:
push:
branches:
- main
paths:
- 'frontend/**'
jobs:
build-and-deploy-frontend:
runs-on: ubuntu-latest
environment: Staging
defaults:
run:
shell: bash
working-directory: frontend
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9
run_install: false
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Setup pnpm cache
uses: actions/cache@v3
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build environment
run: |
cat << EOF > .env
VITE_API_URL=${{ secrets.BACKEND_URL }}/api/v1
EOF
- name: Build
run: pnpm build
- name: Deploy to server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.VPS_IP }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.VPS_KEY }}
source: "frontend/dist/*"
target: "${{ secrets.FE_DIR }}"
strip_components: 2