From Localhost to Production: CI/CD for Vue with GitHub Actions

Seyyed Ali Mohammadiyeh (Max Base)
Vue.js Global Summit 25 - May 21, 2025

Vue.js Global Summit 2025

About Me

Seyyed Ali Mohammadiyeh (Max Base)
Open-source Maintainer, GitHub
Senior Software Engineer
CTO, asrez
πŸ“§ maxbasecode@gmail.com

Vue.js Global Summit 2025

Experience

  • πŸ‘¨β€πŸ’» GitHub: https://github.com/basemax
  • 🧠 10+ years of experience in software development
  • πŸŽ“ Background in pure and applied mathematics with research experience
Vue.js Global Summit 2025

Session Overview

Learn how to create a reliable, automated CI/CD pipeline for your Vue.js applications using GitHub Actions.

  • Avoid manual and error-prone deployments
  • Automate linting, testing, building, and deploying
  • Cover static, dynamic, and Docker-based deployment targets
Vue.js Global Summit 2025

This talk includes:

βœ… Real-world CI/CD workflows
βœ… Demo-ready GitHub Actions templates
βœ… Deployment strategies + secrets management

Vue.js Global Summit 2025

Goals of This Talk

  1. Build a complete Vue CI/CD pipeline using GitHub Actions
  2. Automate your Vue project from commit to deploy
  3. Customize workflows for any deployment environment
  4. Learn environments, secrets, talk about rollback tactics
Vue.js Global Summit 2025

Why Automate CI/CD?

  • ❌ Manual deployments = time wasted + human error
  • βœ… Automation = faster feedback, confidence, and consistency
  • βš–οΈ Works the same locally, on dev, and in production
Vue.js Global Summit 2025

What is GitHub Actions?

  • Built-in CI/CD solution in GitHub
  • Define workflows as YAML files
  • Runs on push, pull_request, schedule, etc.
  • Supports caching, matrix builds, environments, secrets, Docker
Vue.js Global Summit 2025

CI/CD Flow for Vue.js

  1. ✨ Code (Vite + TypeScript)
  2. ✏️ Lint (ESLint, Prettier)
  3. βœ… Test (Vitest, Jest)
  4. πŸš€ Build (Vite)
  5. πŸ’Ύ Deploy (Static host, Docker, etc.)
Vue.js Global Summit 2025

Directory Structure

GitHub actions files are located in .github/workflows/ directory.

.vue-project/
β”œβ”€β”€ .github/workflows/
β”‚   └── deploy.yml
β”œβ”€β”€ src/
β”œβ”€β”€ public/
β”œβ”€β”€ vite.config.ts
β”œβ”€β”€ package.json
Vue.js Global Summit 2025

Step 1: Basic GitHub Action

# .github/workflows/deploy.yml
name: Vue CI/CD
on: [push]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
      - run: npm ci
      - run: npm run build
Vue.js Global Summit 2025

Add Linting & Testing

βœ… Lint β†’ βœ… Test β†’ βœ… Build β†’ βœ… Deploy

      - run: npm run lint
      - run: npm run test

Make sure you have scripts in package.json:

"scripts": {
  "lint": "eslint .",
  "test": "vitest"
}
Vue.js Global Summit 2025

Deployment Targets

  • 🌐 Static hosts: Netlify, Vercel, GitHub Pages
  • 🚨 Dynamic servers: Node, Nuxt SSR
  • 🚧 Docker-based servers: VPS, cloud infra (e.g. DigitalOcean)
Vue.js Global Summit 2025

Use Environments & Secrets

  • Define secrets in GitHub Settings β†’ Secrets
  • Access them via ${{ secrets.YOUR_SECRET }}
  • Use Environments (dev, staging, prod) to control manual approvals
Vue.js Global Summit 2025

Settings

You can find settings of your repository at top of your repository page:

Vue.js Global Summit 2025

Settings - Actions

In settings page, you can find Actions in the left sidebar:

Vue.js Global Summit 2025

Use Environments & Secrets

In settings actions envirnment variable, you can manage and add/edit/delete your secret variables:

Vue.js Global Summit 2025

Write access for your GitHub Actions

Sometime you need write access inside your github actions, in this case you need to check and enable it in repository settings:

Vue.js Global Summit 2025

Demo Time!

Let’s walk through a real Vue project using GitHub Actions end-to-end:

βœ… Build β†’ βœ… Connect β†’ βœ… Deploy

Vue.js Global Summit 2025

Examples

  • First: Auto deploy to GitHub Pages
  • Second: Auto deploy to SFTP/SSH Server
  • Third: Auto deploy to FTP/CPanel Host

Let's do it one by one.

Vue.js Global Summit 2025

First Example: Deploy to GitHub Pages

For your local machine:

{
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview",
    "deploy": "vite build && gh-pages -d dist"
  }
}
Vue.js Global Summit 2025

First Example: Deploy to GitHub Pages

For GitHub Actions:

{
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview",
    "deploy": "vite build && gh-pages -d dist
      -u 'Max Base (Seyyed Ali Mohammadiyeh) <maxbasecode@gmail.com>'
      -r https://x-access-token:${GITHUB_TOKEN}@github.com/BaseMax/vuejs-cicd-deploy-on-github-pages.git"
  }
}
Vue.js Global Summit 2025

First Example: Deploy to GitHub Pages

name: πŸš€ Deploy project in GitHub Pages
on:
  push:
    branches: [ main ]
jobs:
  gh-pages-deploy:
    name: 🧩 Deploying code to gh-pages branch
    runs-on: ubuntu-latest
    steps:
      - name: πŸ”€ Checkout code from repository
        uses: actions/checkout@v4
      - name: πŸ›  Setup Node version
        uses: actions/setup-node@v4
        with:
          node-version: 20.x
      - name: πŸ“¦ Install dependencies
        run: npm install

First Example: Deploy to GitHub Pages

      - name: πŸ™ Setup git user
        run: |
          git config user.name "Max Base (Seyyed Ali Mohammadiyeh)"
          git config user.email "maxbasecode@gmail.com"
      - name: πŸ— Deploy project
        run: npm run deploy
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Vue.js Global Summit 2025

Second Example: Deploy to SFTP/SSH

name: πŸš€ Deploy project to SFTP server

on:
  push:
    branches: [ main ]

jobs:
  sftp-deploy:
    name: 🧩 Deploying to SSH SFTP
    runs-on: ubuntu-latest

    steps:
      - name: πŸ”€ Checkout code from repository
        uses: actions/checkout@v4

      - name: πŸ›  Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20.x

      - name: πŸ“¦ Install dependencies
        run: npm install

      - name: 🧱 Build project
        run: npm run build

Second Example: Deploy to SFTP/SSH Server

      - name: πŸ“₯ Install sshpass
        run: sudo apt-get install -y sshpass

      - name: πŸ“€ Upload dist folder to remote SFTP server
        run: |
          sshpass -p "${{ secrets.SSH_PASSWORD }}" scp -o StrictHostKeyChecking=no -P ${{ secrets.SSH_PORT }} -r dist/* ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_IP }}:${{ secrets.SSH_PATH }}
Vue.js Global Summit 2025

Second Example: Deploy to SFTP/SSH Server

After running the deployment, you can ese directory, and files all created in your server via SSH:

Vue.js Global Summit 2025

Second Example: Deploy to SFTP/SSH Server

Envirnment variables for this SSH github actions:

Vue.js Global Summit 2025

Third Example: Deploy to FTP/CPanel

name: πŸš€ Deploy project via FTP to cPanel

on:
  push:
    branches: [ main ]

jobs:
  ftp-deploy:
    name: πŸ“‘ Deploying via FTP to cPanel
    runs-on: ubuntu-latest

    steps:
      - name: πŸ”€ Checkout code from repository
        uses: actions/checkout@v4

      - name: πŸ›  Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20.x

      - name: πŸ“¦ Install dependencies
        run: npm install

      - name: 🧱 Build project
        run: npm run build

      - name: πŸ“₯ Install lftp
        run: sudo apt-get install -y lftp
Vue.js Global Summit 2025

Third Example: Deploy to FTP/CPanel

      - name: πŸ“€ Upload via FTP with custom port
        run: |
          lftp -u "${{ secrets.FTP_USERNAME }},${{ secrets.FTP_PASSWORD }}" -p ${{ secrets.FTP_PORT }} ${{ secrets.FTP_HOST }} -e "
            set dns:order inet;
            set ftp:ssl-allow no;
            set ssl:verify-certificate no;
            mirror -R -e -n dist ${{ secrets.FTP_PATH }};
            bye
          "
Vue.js Global Summit 2025

Third Example: Deploy to FTP/CPanel

Envirnment variables for this FTP github actions:

Vue.js Global Summit 2025

Third Example: Deploy to FTP/CPanel

Here is filemanager in our host before running the github actions:

Vue.js Global Summit 2025

Use Caching to Speed Up

      - uses: actions/cache@v3
        with:
          path: ~/.npm
          key: npm-${{ hashFiles('package-lock.json') }}
Vue.js Global Summit 2025

Rollback Strategies

  • Keep previous release in a backup folder
  • Add health check after deploy
  • If failed, restore previous version
      - name: Health Check
        run: curl --fail https://example.com || exit 1
Vue.js Global Summit 2025

Tips & Best Practices

  • One job per stage (lint, test, build, deploy)
  • Use matrix to test on multiple Node versions
  • Keep workflows short and readable
  • Secure secrets, never hardcode credentials
Vue.js Global Summit 2025

Full Workflow Overview

on: [push]
jobs:
  lint:
    ...
  test:
    ...
  build:
    ...
  deploy:
    ...
Vue.js Global Summit 2025

Recap

  • CI/CD saves time, prevents bugs, and increases confidence
  • GitHub Actions + Vue = scalable automation
  • Build once, deploy anywhere (static or dynamic)
Vue.js Global Summit 2025

Public Examples

Open-Source repositories:

Vue.js Global Summit 2025

Thank You!

πŸ”— github.com/basemax
πŸ“§ maxbasecode@gmail.com
🌟 Happy Coding!

Vue.js Global Summit 2025