Skip to content

finish deploy.yml

finish deploy.yml #12

Workflow file for this run

# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
name: Go
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.23.2'
- name: Build
run: |
mkdir -p ~/.ssh
touch ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
echo "${{ secrets.PASSWORD }}" > ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.HOST }} >> ~/.ssh/known_hosts
cd backend
echo "${{ secrets.MongoUrl }}" >> mongo/creds
go get .
go build -v .
scp backend ${{ secrets.USERNAME }}@${{ secrets.HOST }}:/home/${{ secrets.USERNAME }}
- name: Deploy
uses: appleboy/ssh-action@v1.2.0
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.PASSWORD }}
port: ${{ secrets.PORT }}
script: |
echo "On Server!"
kill -9 $(cat backend.pid)
rm nohup.out
nohup ./backend & echo $! > backend.pid
echo "Backend process started in the background. Exiting SSH session..."