Skip to content

deploy

deploy #1683

Workflow file for this run

name: deploy
on:
push:
branches:
- main
workflow_dispatch:
inputs:
environment:
type: environment
description: 'Environment to deploy to'
jobs:
deploy:
if: ${{ github.event_name == 'workflow_dispatch' || vars.DEFAULT_ENV }}
runs-on: ubuntu-latest
environment:
name: ${{ github.event.inputs.environment || vars.DEFAULT_ENV }}
url: ${{ vars.DEPLOY_URL }}
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8.3.1
- uses: actions/setup-node@v3
with:
node-version: '20'
cache: 'pnpm'
- run: |
pnpm install --frozen-lockfile
cat << EOF > .env.local
${{ secrets.DOT_ENV }}
EOF
pnpm build
- name: Install SSH Key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_PRIVATE_KEY }}
# ssh-keygen -H -F [<host>]:<port>
known_hosts: ${{ vars.SSH_KNOWN_HOSTS }}
- name: Deploy
run: |
zip -r build.zip build
scp -P ${{ vars.SSH_PORT }} build.zip ${{ vars.SSH_USER }}@${{ vars.SSH_HOST }}:${{ vars.SSH_FOLDER }}/build.zip
ssh -p ${{ vars.SSH_PORT }} ${{ vars.SSH_USER }}@${{ vars.SSH_HOST }} "hostnamectl && git lfs install && cd ${{ vars.SSH_FOLDER }} && git remote prune origin && git fetch && git checkout $GITHUB_SHA && pnpm install && unzip -o build.zip && pm2 reload ${{ vars.PM2_APP_NAME }} && cd build && find . -mtime +30 -type f -delete"