|
| 1 | +name: 🚀 Deploy Blog to Server (Build & Upload) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - blog |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + ref: |
| 10 | + description: Branch to deploy |
| 11 | + required: false |
| 12 | + default: blog |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + |
| 17 | +jobs: |
| 18 | + test: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + |
| 21 | + steps: |
| 22 | + # Step 1: Checkout code |
| 23 | + - name: 📂 Checkout code |
| 24 | + uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + ref: ${{ github.event.inputs.ref || github.ref_name }} |
| 27 | + fetch-depth: 1 |
| 28 | + |
| 29 | + # Step 2: Set up Node.js and pnpm |
| 30 | + - name: 📦 Set up Node.js and pnpm |
| 31 | + uses: pnpm/action-setup@v4 |
| 32 | + with: |
| 33 | + run_install: | |
| 34 | + - recursive: true |
| 35 | + args: [--frozen-lockfile] |
| 36 | +
|
| 37 | + # Step 3: Run linter |
| 38 | + - name: 🚨 Lint Code |
| 39 | + run: pnpm run lint |
| 40 | + |
| 41 | + # Step 4: Test wether build is successful |
| 42 | + - name: ✅ Build Project |
| 43 | + run: pnpm run build |
| 44 | + |
| 45 | + # Step 5: Pack build artifacts |
| 46 | + - name: 📦 Package build files |
| 47 | + run: | |
| 48 | + tar -czf build.tar.gz \ |
| 49 | + .next \ |
| 50 | + public \ |
| 51 | + package.json \ |
| 52 | + pnpm-lock.yaml \ |
| 53 | + .node-version \ |
| 54 | + LICENSE |
| 55 | +
|
| 56 | + # Step 6: Upload packaged build to server |
| 57 | + - name: 📤 Upload build to server |
| 58 | + |
| 59 | + with: |
| 60 | + host: ${{ secrets.SSH_HOST }} |
| 61 | + username: ${{ secrets.SSH_USER }} |
| 62 | + key: ${{ secrets.SSH_KEY }} |
| 63 | + source: build.tar.gz |
| 64 | + target: /data/apps/SuzuBlog/app |
| 65 | + |
| 66 | + # Step 7: SSH into server and run deploy script |
| 67 | + - name: 🛠️ SSH Run deploy.sh |
| 68 | + |
| 69 | + with: |
| 70 | + host: ${{ secrets.SSH_HOST }} |
| 71 | + username: ${{ secrets.SSH_USER }} |
| 72 | + key: ${{ secrets.SSH_KEY }} |
| 73 | + script: | |
| 74 | + cd /data/apps/SuzuBlog/app |
| 75 | + ./deploy.sh |
0 commit comments