Skip to content

Commit 6190dab

Browse files
author
Ivan Lim
committed
feat: add github action to auto deploy to shared hosting server
1 parent 7f3fdf8 commit 6190dab

3 files changed

Lines changed: 115 additions & 1 deletion

File tree

.github/workflows/ssh-deploy.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Version: 3.0.0
2+
# Last Updated: 2025-11-06
3+
4+
name: Deploy to Shared Hosting (FTP/S)
5+
6+
on:
7+
push:
8+
branches:
9+
- main
10+
workflow_dispatch:
11+
12+
# Permissions: Restrict what the workflow can do
13+
# - contents: read allows checkout of your repository code
14+
# This follows the principle of least privilege: only grant what's needed
15+
# For this workflow: We only need to read the code; we don't need write access
16+
permissions:
17+
contents: read
18+
19+
# Concurrency control: Ensures only one deployment runs at a time
20+
# - group: Logical grouping for this workflow (same across all project types)
21+
# - cancel-in-progress: Cancels any currently running deployment before starting a new one
22+
# This prevents multiple deployments from stacking up or conflicting if you push rapidly
23+
concurrency:
24+
group: shared-hosting-deploy
25+
cancel-in-progress: true
26+
27+
jobs:
28+
build:
29+
name: Build static site
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Checkout
33+
uses: actions/checkout@v4
34+
35+
- name: Setup pnpm
36+
uses: pnpm/action-setup@v4
37+
with:
38+
version: 10
39+
40+
- name: Setup Node.js
41+
uses: actions/setup-node@v4
42+
with:
43+
node-version: 22
44+
# Cache: Speed up dependency installation by caching pnpm's store directory
45+
# On subsequent runs, pnpm reuses cached dependencies instead of re-downloading them
46+
# Saves significant time and bandwidth, especially for workflows that run frequently
47+
cache: 'pnpm'
48+
49+
# Install dependencies for the project
50+
# --no-frozen-lockfile: Allows pnpm to update the lock file if needed
51+
# By default, pnpm is strict and fails if pnpm-lock.yaml is missing or outdated
52+
# This flag lets pnpm regenerate the lock file, useful if it's not committed or is stale
53+
# Tradeoff: Less reproducible (lock file may differ between runs), but more flexible
54+
# Note: For production, consider using --frozen-lockfile for strict reproducibility
55+
- name: Install dependencies
56+
run: pnpm install --no-frozen-lockfile
57+
58+
- name: Generate static site
59+
run: pnpm generate
60+
61+
# Store the generated static site as an artifact for the deploy job
62+
# Artifacts are temporary files that persist between jobs in the same workflow run
63+
# This avoids rebuilding the site during the deploy job; we just reuse the pre-built output
64+
# Artifacts are automatically deleted after 90 days (configurable in GitHub settings)
65+
- name: Upload generated site as artifact
66+
uses: actions/upload-artifact@v4
67+
with:
68+
name: generated-output
69+
path: .output/public
70+
71+
deploy:
72+
name: Upload to shared hosting
73+
needs: build
74+
runs-on: ubuntu-latest
75+
steps:
76+
- name: Download site artifact
77+
uses: actions/download-artifact@v4
78+
with:
79+
name: generated-output
80+
path: generated-output
81+
82+
# Deploy via SCP (Secure Copy Protocol)
83+
# SCP is more reliable than FTP/FTPS for shared hosting and works over SSH
84+
# Requires: SSH_HOST, SSH_USER, SSH_KEY (private key), and SSH_DEPLOY_PATH secrets
85+
- name: Deploy via SCP
86+
uses: garygrossgarten/github-action-scp@release
87+
with:
88+
host: ${{ secrets.SSH_HOST }}
89+
username: ${{ secrets.SSH_USERNAME }}
90+
privateKey: ${{ secrets.SSH_KEY }}
91+
local: generated-output/
92+
remote: ${{ secrets.SSH_DEPLOY_PATH }}
93+
# recursive: Copies entire directory structure from local to remote
94+
# When true: Creates subdirectories on the server as needed
95+
# When false: Only copies files in the root directory (usually not what you want)
96+
recursive: true
97+
# Optional: Set to true to delete files on remote that don't exist locally
98+
# directoryMode: 0755
99+
# fileMode: 0644

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,19 @@ pnpm update --interactive --latest
120120

121121
All changes ensure compatibility with Nuxt 4 and the official Vuetify module while maintaining existing functionality.
122122

123+
124+
## === GitHub Action Auto Deploy to Shared Hosting Server ===
125+
126+
* Ensure these secret names match the variables referenced in `.github/workflows/ssh-deploy.yml`
127+
128+
* In the repository, go to `Settings` > `Secrets and variables` > `Actions` > `Repository secrets` > `New repository secret`
129+
130+
* SSH_HOST: Server hostname/IP
131+
132+
* SSH_USERNAME: Your SSH username
133+
134+
* SSH_KEY: Your private SSH key content (the entire key including headers)
135+
136+
* SSH_DEPLOY_PATH: Path on host to copy files
137+
138+
* Create GitHub action file (e.g. `.github/workflows/ssh-deploy.yml`)

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"scripts": {
1010
"build": "nuxt build",
1111
"dev": "nuxt dev",
12-
"devo": "nuxt dev -o",
1312
"generate": "nuxt generate",
1413
"preview": "nuxt preview",
1514
"postinstall": "nuxt prepare",

0 commit comments

Comments
 (0)