Update main.yml
This commit is contained in:
+20
-13
@@ -1,23 +1,30 @@
|
|||||||
|
name: Deploy to Server
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
run_pull:
|
deploy:
|
||||||
name: run pull
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: install ssh keys
|
- name: Checkout code
|
||||||
# check this thread to understand why its needed:
|
uses: actions/checkout@v3
|
||||||
# https://stackoverflow.com/a/70447517
|
|
||||||
|
- name: Install sshpass
|
||||||
|
run: sudo apt-get install -y sshpass
|
||||||
|
|
||||||
|
- name: SSH into server and pull application
|
||||||
run: |
|
run: |
|
||||||
install -m 600 -D /dev/null ~/.ssh/id_rsa
|
sshpass -p "${{ secrets.SSH_PRIVATE_KEY }}" ssh -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} << EOF
|
||||||
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
|
cd ${{ secrets.WORK_DIR }}
|
||||||
ssh-keyscan -H ${{ secrets.SSH_HOST }} > ~/.ssh/known_hosts
|
|
||||||
- name: connect and pull
|
# Set GitHub credentials using GITHUB_TOKEN
|
||||||
run: ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "cd ${{ secrets.WORK_DIR }} && git checkout ${{ secrets.MAIN_BRANCH }} && git pull && exit"
|
git config --global credential.helper store
|
||||||
- name: cleanup
|
echo "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}" > ~/.git-credentials
|
||||||
run: rm -rf ~/.ssh
|
|
||||||
|
# Pull the latest code from the repository
|
||||||
|
git pull origin ${{ secrets.MAIN_BRANCH }}
|
||||||
|
EOF
|
||||||
|
|||||||
Reference in New Issue
Block a user