---
title: "Triggering a static Next.js build and export with Github Actions"
date: 2020-08-31T00:00:00+00:00
author: "poornerd"
tags: ["github", "nextjs", "ci"]
canonical: https://www.poornerd.com/2020/08/31/deploy-nextjs-github-actions-copy.html
source: Raw Markdown twin of the HTML article; content is the original source.
---
I recently decided to relaunch another of my blogs and move it from Wordpress to another static site generator - this one uses [Jekyll](https://jekyllrb.com/).  Even though [Next.js](https://nextjs.org/) is not really a static site generator, there are blog starter templates, and you can build and export the whole site as static files (instead of the typical server side rendering).

Before I started to iterate on the layout and design, I wanted to make sure I had the deployments automated, so I chose [Github Actions](https://github.com/features/actions) since I was commiting on Github as opposed to the commonly recommended [Vercel](https://vercel.com/) or [Netlify](https://www.netlify.com/).

The primary steps to build and deploy are:
1. ```npm install```
1. ```npm build```
1. ```npm export```
1. SFTP the static code and assets to my server

So I setup an __action__ based on a __node.js__ build using the following two actions:
- actions/checkout@v2.1.0
- [SamKirkland/FTP-Deploy-Action@3.1.1](https://github.com/SamKirkland/FTP-Deploy-Action)

Here is the file:
```
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
  push:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [14.x]

    steps:
    - uses: actions/checkout@v2.1.0
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - run: npm install
    - run: npm run build --if-present
    - run: npm run export
      env:
        CI: true
    - name: FTP-Deploy-Action
      uses: SamKirkland/FTP-Deploy-Action@3.1.1
      with:
        ftp-server: ${{ secrets.SFTP_URL }}
        ftp-username: ${{ secrets.SFTP_USER }}
        ftp-password: ${{ secrets.KEY }}
        local-dir: dist
        git-ftp-args: --insecure 
```
*I did have to add a ```.git-ftp-include``` file with the directory I wanted to copy with SFTP. I found this in the README for the __FTP-Deploy-Action__.  This is what it looked like:*
```
!dist/
```
