Skip to content

Instantly share code, notes, and snippets.

@serverok
Last active August 1, 2025 06:43
Show Gist options
  • Select an option

  • Save serverok/2e72b47ed556e4cf751984e288d9d398 to your computer and use it in GitHub Desktop.

Select an option

Save serverok/2e72b47ed556e4cf751984e288d9d398 to your computer and use it in GitHub Desktop.
GitHub Actions Deploy Next.js to SFTP
name: Deploy Next.js to SFTP
on:
push:
branches:
- main # Or the branch you want to trigger the deployment on
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Create .env file
run: |
echo "NEXT_PUBLIC_API_URL=https://api.serverok.in/" > .env
echo "NEXT_PUBLIC_APP_URL=https://serverok.in/" >> .env
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm install
- name: Build project
run: npm run build
- name: Deploy to SFTP server with SCP
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SERVER_USER }}
port: ${{ secrets.SERVER_PORT }}
key: ${{ secrets.SERVER_KEY }}
strip_components: 1
source: "out/*"
target: "/home/serverok/public_html/"
@serverok
Copy link
Author

serverok commented Aug 1, 2025

You need the following secret setup for this to work

Screenshot from 2025-08-01 10-04-00

SERVER_KEY is the private key, the public key should be in .ssh/authorized_keys on the server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment