61 lines
1.7 KiB
YAML
61 lines
1.7 KiB
YAML
name: Deploy
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
test-and-deploy:
|
|
name: Test and deploy
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '20'
|
|
|
|
- name: Install
|
|
run: npm ci
|
|
|
|
- name: Typecheck
|
|
run: npm run typecheck
|
|
|
|
- name: Test
|
|
run: npm test
|
|
|
|
- name: Deploy over SSH
|
|
env:
|
|
SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
|
|
VPS_HOST: ${{ secrets.VPS_HOST }}
|
|
VPS_USER: ${{ secrets.VPS_USER }}
|
|
run: |
|
|
set -euo pipefail
|
|
test -n "${SSH_KEY:-}"
|
|
test -n "${VPS_HOST:-}"
|
|
test -n "${VPS_USER:-}"
|
|
|
|
apt-get update -qq
|
|
apt-get install -y -qq rsync openssh-client
|
|
|
|
install -m 700 -d "$HOME/.ssh"
|
|
printf '%s\n' "$SSH_KEY" > "$HOME/.ssh/deploy_key"
|
|
chmod 600 "$HOME/.ssh/deploy_key"
|
|
|
|
SSH=(ssh -i "$HOME/.ssh/deploy_key" -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new)
|
|
|
|
"${SSH[@]}" "${VPS_USER}@${VPS_HOST}" 'install -d -m 0750 /opt/ghabilee-telegram-relay'
|
|
rsync -az --delete \
|
|
-e "ssh -i $HOME/.ssh/deploy_key -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new" \
|
|
--exclude '.git' \
|
|
--exclude 'node_modules' \
|
|
--exclude 'dist' \
|
|
--exclude '.env' \
|
|
./ "${VPS_USER}@${VPS_HOST}:/opt/ghabilee-telegram-relay/"
|
|
|
|
"${SSH[@]}" "${VPS_USER}@${VPS_HOST}" \
|
|
'chmod +x /opt/ghabilee-telegram-relay/scripts/deploy-on-vps.sh && APP_DIR=/opt/ghabilee-telegram-relay /opt/ghabilee-telegram-relay/scripts/deploy-on-vps.sh'
|
|
|
|
rm -f "$HOME/.ssh/deploy_key"
|