Skip to content

Commit

Permalink
deploy: add GitHub Actions Workflow for automated deploys
Browse files Browse the repository at this point in the history
  • Loading branch information
IgStefano committed Dec 14, 2024
1 parent e34516a commit 8dc0791
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Auto Deploy

on:
push:
branches: [main]

jobs:
deploy:
runs-on: ubuntu-latest
steps:
# Step 1: Check out the repository
- name: Checkout code
uses: actions/checkout@v3

# Step 2: Set up SSH
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "$SSH_PRIVATE_KEY" | base64 --decode > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -t rsa $SSH_HOSTNAME >> ~/.ssh/known_hosts
echo -e "Host $SSH_VM_NAME\n HostName $SSH_HOSTNAME\n User $SSH_USER\n IdentityFile ~/.ssh/id_ed25519" > ~/.ssh/config
chmod 600 ~/.ssh/config
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_HOSTNAME: ${{ secrets.SSH_HOSTNAME }}
SSH_USER: ${{ secrets.SSH_USER }}
SSH_VM_NAME: ${{ secrets.SSH_VM_NAME }}

- name: Test SSH Connection
run: ssh $SSH_VM_NAME "echo SSH connection successful!"

env:
SSH_VM_NAME: ${{ secrets.SSH_VM_NAME}}

- name: Execute deploy commands via SSH
run: |
ssh $SSH_VM_NAME '
cd /home/feriado/proximo-feriado
sudo chown -R $SSH_USER:$SSH_USER .
sudo chmod -R 777 .
git reset --hard origin/main
git clean -fd
rm -rf node_modules
mkdir node_modules
/home/debian/.bun/bin/bun install
/home/debian/.bun/bin/bun astro build
pm2 restart proximo-feriado || pm2 start --name proximo-feriado /dist/server/entry.mjs -- start
'
env:
SSH_VM_NAME: ${{ secrets.SSH_VM_NAME}}
SSH_HOSTNAME: ${{ secrets.SSH_HOSTNAME }}
SSH_USER: ${{ secrets.SSH_USER }}
1 change: 1 addition & 0 deletions public/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GREAT SUCCESS

0 comments on commit 8dc0791

Please sign in to comment.