-
Notifications
You must be signed in to change notification settings - Fork 0
82 lines (68 loc) · 2.2 KB
/
Copy pathci-cd.yml
File metadata and controls
82 lines (68 loc) · 2.2 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
name: CI/CD Pipeline
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: pip
cache-dependency-path: pyproject.toml
- name: Install the package
run: |
python -m pip install --upgrade pip
pip install -e ".[dev,redis]"
- name: Run black
run: black --check --diff .
- name: Run isort
run: isort --check-only --diff .
- name: Run tests
run: pytest
- name: Check the console script is installed
run: match-engine --help
deploy:
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
steps:
- uses: actions/checkout@v5
- name: Check a deploy target is configured
id: target
env:
DEPLOY_HOST: ${{ vars.DEPLOY_HOST }}
run: |
if [ -z "$DEPLOY_HOST" ]; then
echo "No DEPLOY_HOST variable set, skipping deploy"
echo "configured=false" >> "$GITHUB_OUTPUT"
else
echo "configured=true" >> "$GITHUB_OUTPUT"
fi
- name: Deploy over SSH
if: steps.target.outputs.configured == 'true'
shell: bash
env:
SSH_PRIVATE_KEY: ${{ secrets.DOCKER_SSH_PRIVATE_KEY }}
DEPLOY_HOST: ${{ vars.DEPLOY_HOST }}
DEPLOY_USER: ${{ vars.DEPLOY_USER }}
run: |
install -m 600 -D /dev/null ~/.ssh/id_rsa
echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
ssh-keyscan -H "$DEPLOY_HOST" >> ~/.ssh/known_hosts
rsync -avz --delete \
--exclude '.git' --exclude '.venv' --exclude 'specs' \
-e "ssh -i ~/.ssh/id_rsa" \
./ "$DEPLOY_USER@$DEPLOY_HOST:~/match_engine/"
ssh -i ~/.ssh/id_rsa "$DEPLOY_USER@$DEPLOY_HOST" <<'REMOTE'
cd ~/match_engine
cp ~/envs/.env .
docker compose down || true
docker compose up -d --build
REMOTE
rm -f ~/.ssh/id_rsa