-
Notifications
You must be signed in to change notification settings - Fork 18
178 lines (156 loc) · 4.35 KB
/
ci.yaml
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
name: CI
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
install:
name: Install
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: pipenv
- name: Install pipenv and dependencies
run: |
pip install --user pipenv
pipenv install --dev --deploy
check:
name: Check Formatting and Typing
runs-on: ubuntu-latest
needs:
- install
if: success()
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: pipenv
- name: Install pipenv and dependencies
run: |
pip install --user pipenv
pipenv sync --dev
- name: Check formatting with black
run: |
pipenv run black --check --diff --exclude __tests__ .
- name: Check code style with ruff
run: |
pipenv run ruff check .
- name: Check types with pyright
if: always()
run: |
pipenv run pyright --verbose
test:
name: Run Tests with Pytest
runs-on: ubuntu-latest
needs:
- install
if: success()
services:
postgres:
image: postgres:14.7
env:
POSTGRES_USER: apollo
POSTGRES_PASSWORD: apollo
POSTGRES_DB: apollo
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: pipenv
- name: Install pipenv and dependencies
run: |
pip install --user pipenv
pipenv sync --dev
cp config.example.yaml config.yaml
- name: Test with pytest
run: pipenv run pytest -v
migrate:
name: Check Migrations
runs-on: ubuntu-latest
needs:
- install
if: success()
# postgres container to test migrations against
services:
postgres:
image: postgres:12
env:
POSTGRES_USER: apollo
POSTGRES_PASSWORD: apollo
POSTGRES_DB: apollo
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: pipenv
- name: Install pipenv and dependencies
run: |
pip install --user pipenv
pipenv sync --dev
cp config.example.yaml config.yaml
cp alembic.example.ini alembic.ini
- name: Check upgrade migrations
run: pipenv run alembic upgrade head
- name: Check no migrations need to be generated
run: pipenv run alembic check
- name: Check downgrade migrations
#if: always() #check downgrade even if check failes
run: pipenv run alembic downgrade base
build-and-push-image:
name: Build and Push Docker Image
runs-on: ubuntu-latest
permissions:
packages: write
needs:
- check
- migrate
- test
if: success() && github.ref_name == 'master' && github.event_name == 'push'
steps:
- uses: actions/checkout@v3
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get Docker Metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}
tags: | # tag with commit hash and with 'latest'
type=sha
type=raw,value=latest,enable={{is_default_branch}}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and Push Docker image
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max