Last active
April 11, 2023 22:38
-
-
Save Fray117/359cfdb07c5d1e1cf9d31eda911b1531 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy NextJS | |
on: | |
push: | |
branches: [ "main" ] | |
workflow_dispatch: | |
env: | |
NODE_VERSION: '18.14' # set this to the node version to use | |
HOST: HOSTNAME # ssh hostname | |
USERNAME: USERNAME # ssh user credentials | |
PASSWORD: PASSWORD # ssh pass credentials | |
PATH: "/var/www" # ssh target directory | |
permissions: | |
contents: read | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout origin | |
uses: actions/checkout@v3 | |
- name: Setup Yarn Cache | |
uses: actions/cache@v3 | |
env: | |
cache-name: cache-node-modules | |
with: | |
# npm cache files are stored in `~/.npm` on Linux/macOS | |
path: ~/.yarn | |
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-build-${{ env.cache-name }}- | |
${{ runner.os }}-build- | |
${{ runner.os }}- | |
- name: Setup NodeJS | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
cache: 'yarn' | |
- name: yarn install, build, and test | |
run: | | |
yarn install | |
yarn run build | |
- name: Copy file via SSH | |
uses: appleboy/scp-action@master | |
with: | |
HOST: ${{ env.HOST }} | |
USERNAME: ${{ env.USERNAME }} | |
PASSWORD: ${{ env.PASSWORD }} | |
source: "./.next" | |
target: ${{ env.PATH }} | |
strip_components: 2 # this is important | |
- name: Restart server | |
uses: appleboy/ssh-action@master | |
with: | |
HOST: ${{ env.HOST }} | |
USERNAME: ${{ env.USERNAME }} | |
PASSWORD: ${{ env.PASSWORD }} | |
script: pm2 restart 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment