-
Notifications
You must be signed in to change notification settings - Fork 1
79 lines (70 loc) · 2.16 KB
/
cd.yml
File metadata and controls
79 lines (70 loc) · 2.16 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
name: CD
on:
push:
branches: [main, develop]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: deploy-${{ github.ref_name }}
cancel-in-progress: false
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
- name: Install dependencies
run: pip install -e ".[dev]"
- name: Run tests
run: python -m pytest tests/ --cov=paperscout --cov-fail-under=90 -v
deploy:
name: Deploy
needs: test
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop'
runs-on: ubuntu-latest
timeout-minutes: 15
environment: >-
${{ github.ref == 'refs/heads/main' && 'production'
|| github.ref == 'refs/heads/develop' && 'staging'
|| '' }}
steps:
- name: Deploy via SSH
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
port: ${{ secrets.SERVER_PORT || 22 }}
command_timeout: 15m
script: |
set -euo pipefail
cd "${{ vars.DEPLOY_PATH }}"
git fetch origin "${{ vars.DEPLOY_BRANCH }}"
git checkout "${{ vars.DEPLOY_BRANCH }}"
git pull --ff-only origin "${{ vars.DEPLOY_BRANCH }}"
docker compose up -d --build paperscout
- name: Health check
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
port: ${{ secrets.SERVER_PORT || 22 }}
command_timeout: 5m
script: |
set -euo pipefail
url="http://localhost:${{ vars.HEALTH_PORT }}/health"
for i in $(seq 1 12); do
if curl -sf "$url"; then
echo "Health check OK after attempt $i"
exit 0
fi
sleep 5
done
echo "Health check failed after 12 attempts"
exit 1