Fontlay Deploy Prod #16
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: Fontlay Deploy Prod | |
on: | |
workflow_dispatch: | |
push: | |
branches: [main] | |
paths-ignore: | |
- 'README.md' | |
- '.gitignore' | |
- '.gitattributes' | |
- '.vscode/**' | |
env: | |
APP_ARTIFACTS_NAME: fontlay-web | |
APP_BUILD_NAME: build-web | |
APP_DIR: /var/www/fontlay-web | |
BUILD_DIR: dist | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
environment: build-production | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: pnpm/action-setup@v2 | |
with: | |
version: '8' | |
- name: Use Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '18.x' | |
cache: 'pnpm' | |
# - uses: actions/cache@v3 | |
# with: | |
# path: | | |
# ${{ github.workspace }}/.next/cache | |
# key: ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-${{ hashFiles('**/*.[jt]s', '**/*.[jt]sx') }} | |
# restore-keys: | | |
# ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}- | |
- name: Create .env file π | |
run: | | |
touch .env | |
echo NEXT_TELEMETRY_DISABLED=1 >> .env | |
- name: Install dependencies π¨π»βπ» | |
run: pnpm install -no-frozen-lockfile | |
- name: Build Apps π¦ | |
run: pnpm build | |
- name: Build App Artifacts π§ | |
run: | | |
mkdir ${{ env.BUILD_DIR }} | |
mv .env .nvmrc ecosystem.config.js ${{ env.BUILD_DIR }} | |
mv next.config.js public package.json .next ${{ env.BUILD_DIR }} | |
tar -czf ${{ env.APP_BUILD_NAME }}.tar.gz ${{ env.BUILD_DIR }} | |
- name: Upload Artifact ${{ env.APP_ARTIFACTS_NAME }} βοΈ | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.APP_ARTIFACTS_NAME }} | |
path: ${{ env.APP_BUILD_NAME }}.tar.gz | |
deploy-prod: | |
name: Deploy Production | |
runs-on: ubuntu-latest | |
needs: [build] | |
environment: production | |
steps: | |
- name: Download Artifact ${{ env.APP_ARTIFACTS_NAME }} π¬ | |
uses: actions/download-artifact@v3 | |
with: | |
name: ${{ env.APP_ARTIFACTS_NAME }} | |
- name: Upload ${{ env.APP_BUILD_NAME }}.tar.gz π | |
uses: appleboy/scp-action@v0.1.4 | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ${{ secrets.SSH_USERNAME }} | |
key: ${{ secrets.SSH_KEY }} | |
port: ${{ secrets.SSH_PORT }} | |
source: ${{ env.APP_BUILD_NAME }}.tar.gz | |
target: ${{ env.APP_DIR }} | |
- name: Deploy to Ponyo π | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ${{ secrets.SSH_USERNAME }} | |
key: ${{ secrets.SSH_KEY }} | |
port: ${{ secrets.SSH_PORT }} | |
script_stop: true | |
script: | | |
cd ${{ env.APP_DIR }} | |
rm -rf dist | |
tar -xzf ${{ env.APP_BUILD_NAME }}.tar.gz && rm -rf ${{ env.APP_BUILD_NAME }}.tar.gz | |
cd ${{ env.APP_DIR }}/dist | |
nvm use | |
pnpm install -no-frozen-lockfile | |
pnpm pm2:restart | |
- name: Success Notification π | |
uses: sarisia/actions-status-discord@v1.12.0 | |
with: | |
webhook: ${{ secrets.WEBHOOK_DISCORD }} | |
status: 'Success' | |
title: 'fontlay back-end π' | |
description: 'Deploy fontlay back-end to ponyo server.' | |
color: 0x99FF66 | |
url: 'https://fontlay.com' | |
- name: Failed Notification π€‘ | |
if: ${{ failure() }} | |
uses: sarisia/actions-status-discord@v1.12.0 | |
with: | |
webhook: ${{ secrets.WEBHOOK_DISCORD }} | |
status: 'Failure' | |
content: 'Hey <@&735080822465495090>' | |
title: 'fontlay front-end π₯΅' | |
description: 'Failed to deploy fontlay front-end.' | |
color: 0xF44336 | |
clean-up: | |
name: Clean up Artifact | |
runs-on: ubuntu-latest | |
needs: [deploy-prod] | |
steps: | |
- uses: geekyeggo/delete-artifact@v1 | |
with: | |
name: ${{ env.APP_ARTIFACTS_NAME }} |