-
Notifications
You must be signed in to change notification settings - Fork 3
91 lines (85 loc) · 2.78 KB
/
ci.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: build-test-deploy
run-name: Build, Test, & Deploy
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
permissions:
contents: read
jobs:
ci:
name: Build & Test
runs-on: ubuntu-latest
services:
postgres:
image: 'postgres:11'
ports:
- 5432:5432
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v3
- name: Install poetry
run: pipx install poetry
- uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'poetry'
- run: poetry install --without vscode
- run: poetry run black --check ./api/
- run: poetry run isort --check ./api/
- run: poetry run pytest --cov=api --cov-config=.coveragerc --cov-report=xml
env:
# Configuration details for connecting to Dockerized postgres
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
POSTGRES_USER: test
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test
SECRET_KEY: testsecret
cd:
name: Deploy
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: ci
env:
SCRIPT_PATH: ${{ secrets.SCRIPT_PATH }}
steps:
- name: Configure SSH
run: |
mkdir -p ~/.ssh/
echo "$SSH_KEY" > ~/.ssh/deploy.key
chmod 600 ~/.ssh/deploy.key
cat >>~/.ssh/config <<END
Host deploy-server
HostName $SSH_HOST
User $SSH_USER
IdentityFile ~/.ssh/deploy.key
StrictHostKeyChecking no
END
env:
SSH_USER: ${{ secrets.SSH_USER }}
SSH_KEY: ${{ secrets.SSH_KEY }}
SSH_HOST: ${{ secrets.SSH_HOST }}
- name: Check out source
run: ssh deploy-server "cd \"${SCRIPT_PATH}/${REPO_NAME}\" && git fetch && git reset --hard origin/main"
env:
REPO_NAME: ${{ github.event.repository.name }}
- name: Update dependencies & run migrations
run: ssh deploy-server "cd \"$SCRIPT_PATH\" && ./update"
- name: Stop the server
run: ssh deploy-server "cd \"$SCRIPT_PATH\" && ./stop"
- name: Start the server
if: ${{ always() }}
run: ssh deploy-server "cd \"$SCRIPT_PATH\" && ./start"