Skip to content

Instantly share code, notes, and snippets.

@quan-vu
Created July 15, 2024 03:24
Show Gist options
  • Save quan-vu/d22b3389f838139162eae725f7ea9784 to your computer and use it in GitHub Desktop.
Save quan-vu/d22b3389f838139162eae725f7ea9784 to your computer and use it in GitHub Desktop.
Github action build Vite App
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
name: Build Frontend Dev
on:
push:
branches: ["main", "cicd", "dev/*"]
pull_request:
branches: ["main"]
workflow_dispatch:
env:
PROJECT_ROOT_DEV: "${{ secrets.PROJECT_ROOT_DEV }}"
PROJECT_BUILD_DIR: "dist"
jobs:
lint-test:
name: Lint and Test
runs-on: [ubuntu-22.04]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
- uses: pnpm/action-setup@v3
with:
version: 8
- run: pnpm install --frozen-lockfile
- run: pnpm lint
build:
needs: lint-test
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
# Setup SSH
- name: Setup SSH - Step 1 - Init SSH Key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_PRIVATE_KEY }}
known_hosts: "just-a-placeholder-so-we-dont-get-errors"
- name: Setup SSH - Step 2 - Adding Known Hosts
run: ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
# Setup Node
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
- uses: pnpm/action-setup@v3
with:
version: 8
- run: pnpm install --frozen-lockfile
- run: pnpm lint
# Setup Project
- name: Check current directory
run: |
pwd
ls -la
- name: Install dependencies
run: |
pnpm install
- name: Create .env file
run: |
touch .env
echo "${{ vars.ENV_DEV }}" >> .env
echo "${{ vars.VITE_API_BASE_URL }}" >> .env
echo "${{ vars.VITE_APP_TITLE }}" >> .env
- name: Build Vue App
run: |
pnpm build
# Deploy project
- name: Deploy with rsync
run: |
rsync -avz ./$PROJECT_BUILD_DIR/ ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:$PROJECT_ROOT_DEV
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment