Skip to content

Staging Deployment

Staging Deployment #11

name: Staging Deployment
on:
workflow_dispatch:
workflow_run:
workflows: ["Build and Upload"]
types:
- completed
branches:
- staging
jobs:
build-and-deploy:
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/staging'}} && ${{ github.event.workflow_run.conclusion == 'success' }}
environment:
name: "staging"
url: ${{ vars.URL }}
steps:
- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "20"
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9
- name: Decode and create .env file
run: |
echo ${{ secrets.ENV_BASE64 }} | base64 -d > .env
- name: Install dependencies
run: pnpm install
- name: Build Next.js application
run: pnpm build
- name: Archive production artifacts
run: tar -czf nextjs-staging.tar.gz .next public .env
- name: Copy to server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
source: "nextjs-staging.tar.gz"
target: "~/hng_boilerplate_nextjs/staging"
- name: Delete zip file
run: rm -f nextjs-staging.tar.gz
- name: Deploy on server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
script: |
cd ~/hng_boilerplate_nextjs/staging
tar -xzf nextjs-staging.tar.gz
rm -f nextjs-staging.tar.gz
cp -r .next/standalone/* .
pm2 restart boilerplate_fe_staging --update-env