Skip to content

Add one more if

Add one more if #52

Workflow file for this run

name: Deploy
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.21'
- name: Install dependencies
run: go mod download
- name: Run unit tests
id: test
run: go test -v ./...
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build Docker image
run: docker build -t trackme-builder .
- name: Extract binary from Docker container
if: steps.test.outcome == 'success'
run: |
docker create --name extract trackme-builder
docker cp extract:/app/trackme ./trackme
docker rm extract
- name: Copy assets and templates
if: steps.test.outcome == 'success'
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: 22
source: "trackme,web"
target: "~/track-me-temp/"
- name: Deploy to server
if: steps.test.outcome == 'success'
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: 22
script: |
~/track-me-temp/trackme --ping
if [ $? -eq 0 ]; then
echo "New binary test passed. Proceeding with deployment."
sudo systemctl stop trackme.service
mv ~/track-me-temp/trackme /root/track-me/trackme
rsync -av ~/track-me-temp/web/assets/* /root/track-me/web/assets
rsync -av ~/track-me-temp/web/templates/* /root/track-me/web/templates
sudo systemctl start trackme.service
else
echo "New binary test failed. Aborting deployment."
exit 1
fi
rm -rf ~/track-me-temp/*