forked from mlco2/codecarbon
-
Notifications
You must be signed in to change notification settings - Fork 0
105 lines (96 loc) · 3.14 KB
/
build.yml
File metadata and controls
105 lines (96 loc) · 3.14 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
name: build package & server
on:
pull_request:
push:
branches: [master]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9"]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Test package with tox
run: tox -vv
build_server:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: '3.8'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Unit tests on api with tox
run: |
cd carbonserver/
tox -e unit -vv
test_api_server:
runs-on: ubuntu-latest
# Service containers to run with `container-job`
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres:12
# Provide the password for postgres
env:
POSTGRES_DB: codecarbon_db
POSTGRES_PASSWORD: supersecret
POSTGRES_USER: codecarbon-user
POSTGRES_HOST: localhost
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5480:5432
steps:
# Downloads a copy of the code in your repository before running CI tests
- name: Check out repository code
uses: actions/checkout@v2
# Performs a clean installation of all dependencies
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: '3.8'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
cd carbonserver
pip install -r requirements-test.txt
pip install tox tox-gh-actions
- name: Setup PostgreSQL
# Runs a script that creates a PostgreSQL table, populates
# the table with data, and then retrieves the data.
run: |
cd carbonserver
python3 -m alembic -c carbonserver/database/alembic.ini upgrade head
env:
# The hostname used to communicate with the PostgreSQL service container
DATABASE_URL: postgresql://codecarbon-user:supersecret@localhost:5480/codecarbon_db
- name: Run API tests
run: |
cd carbonserver
uvicorn main:app --host 0.0.0.0 --port 8008 &
sleep 2
netstat -o -n -a | grep 8008
tox -e integration
# Environment variables used by the `client.js` script to create a new PostgreSQL table.
env:
# The hostname used to communicate with the PostgreSQL service container
DATABASE_URL: postgresql://codecarbon-user:supersecret@localhost:5480/codecarbon_db