Staging Deployment #6
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: Staging Deployment | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- staging | |
paths-ignore: | |
- .github/workflows/** | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
if: github.event.repository.fork == false | |
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: Cache pnpm modules | |
uses: actions/cache@v3 | |
with: | |
path: ~/.pnpm-store | |
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }} | |
restore-keys: | | |
${{ runner.os }}-pnpm- | |
- 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" | |
- 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 | |
tar -xzf nextjs-staging.tar.gz | |
rm -f nextjs-staging.tar.gz | |
cp -r .next/standalone/* . | |
pm2 restart nextjs_boilerplate --update-env |