-
Notifications
You must be signed in to change notification settings - Fork 2
58 lines (50 loc) · 1.45 KB
/
cicd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
name: CI/CD Pipeline
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.22.4
- name: Run tests
run: ./tester.sh
deploy:
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- name: Deploy to server
uses: appleboy/ssh-action@master
env:
GITHUB_SHA: ${{ github.sha }}
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
password: ${{ secrets.SERVER_PASSWORD }}
# key: ${{ secrets.SERVER_SSH_KEY }}
port: ${{ secrets.SERVER_SSH_PORT }}
envs: GITHUB_SHA
script: |
# Navigate to the project directory (create if it doesn't exist)
mkdir -p ~/mini-yektanet
cd ~/mini-yektanet
# Clone or pull the latest changes
if [ -d .git ]; then
git restore .
git pull origin main
else
git clone https://github.com/YellowBloomKnapsack/mini-yektanet.git .
fi
# Checkout the specific commit that triggered the workflow
git checkout $GITHUB_SHA
# Build and start the containers
docker compose up -d --build
# Prune old images to free up space (optional)
docker image prune -af