Skip to content

Instantly share code, notes, and snippets.

@Vincenius
Last active November 7, 2023 06:30
Show Gist options
  • Save Vincenius/2e3763334562e6266bc11d47aa2158a1 to your computer and use it in GitHub Desktop.
Save Vincenius/2e3763334562e6266bc11d47aa2158a1 to your computer and use it in GitHub Desktop.
Github Action - Deploy to Linux using password
name: Deploy to Server
on:
push:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Set up SSH agent
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
- name: SSH into the server and run a command
run: |
ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ubuntu@YOUR_IP << 'EOF'
echo "Connected!!!"
export PATH="$PATH:/root/.nvm/versions/node/YOUR_NODE_VERSION/bin"
cd ~/your/application
git pull
yarn
yarn build
pm2 restart your-application
echo "Deployment done!"
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment