Skip to content

Commit e737266

Browse files
authored
chores: split github workflows (#812)
* chores: split github workflows * docs: typo in the name of the build jobs Signed-off-by: inimaz <93inigo93@gmail.com> --------- Signed-off-by: inimaz <93inigo93@gmail.com>
1 parent e69626e commit e737266

File tree

5 files changed

+193
-167
lines changed

5 files changed

+193
-167
lines changed

.github/workflows/build-server.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: build server
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "carbonserver/**"
7+
- "pyproject.toml"
8+
push:
9+
paths:
10+
- "carbonserver/**"
11+
- "pyproject.toml"
12+
branches: [master]
13+
14+
jobs:
15+
build_server:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: 3.12
23+
- name: Clean pip cache
24+
run: pip cache purge
25+
- name: Install dependencies
26+
run: |
27+
python -m pip install --upgrade pip
28+
29+
- name: Unit tests on api
30+
run: |
31+
pip install hatch==1.13.0 hatchling==1.25.0
32+
hatch run api:test-unit
33+
34+
test_api_server:
35+
runs-on: ubuntu-latest
36+
# Service containers to run with `container-job`
37+
services:
38+
# Label used to access the service container
39+
postgres:
40+
# Docker Hub image
41+
image: postgres:16
42+
# Provide the password for postgres
43+
env:
44+
POSTGRES_DB: codecarbon_db
45+
POSTGRES_PASSWORD: supersecret
46+
POSTGRES_USER: codecarbon-user
47+
POSTGRES_HOST: localhost
48+
# Set health checks to wait until postgres has started
49+
options: >-
50+
--health-cmd pg_isready
51+
--health-interval 10s
52+
--health-timeout 5s
53+
--health-retries 5
54+
ports:
55+
- 5480:5432
56+
57+
steps:
58+
# Downloads a copy of the code in your repository before running CI tests
59+
- name: Check out repository code
60+
uses: actions/checkout@v4
61+
62+
# Performs a clean installation of all dependencies
63+
- name: Set up Python
64+
uses: actions/setup-python@v5
65+
with:
66+
python-version: 3.12
67+
- name: Install dependencies
68+
run: |
69+
python -m pip install --upgrade pip
70+
pip install hatch==1.13.0 hatchling==1.25.0
71+
72+
- name: Setup PostgreSQL
73+
# Runs a script that creates a PostgreSQL table, populates
74+
# the table with data, and then retrieves the data.
75+
run: hatch run api:setup-db
76+
77+
env:
78+
# The hostname used to communicate with the PostgreSQL service container
79+
DATABASE_URL: postgresql://codecarbon-user:supersecret@localhost:5480/codecarbon_db
80+
81+
- name: Run API tests
82+
env:
83+
CODECARBON_API_URL: http://localhost:8008
84+
# The hostname used to communicate with the PostgreSQL service container
85+
DATABASE_URL: postgresql://codecarbon-user:supersecret@localhost:5480/codecarbon_db
86+
run: |
87+
# hatch run api:server-ci &
88+
sleep 2
89+
# netstat -o -n -a | grep 8008
90+
# hatch run api:test-integ

.github/workflows/build-ui.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: build ui
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "webapp/**"
7+
- "pyproject.toml"
8+
push:
9+
paths:
10+
- "webapp/**"
11+
- "pyproject.toml"
12+
branches: [master]
13+
14+
jobs:
15+
build-ui:
16+
runs-on: ubuntu-22.04
17+
steps:
18+
- uses: actions/checkout@v4
19+
- name: Use Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: '18'
23+
- name: Install dependencies
24+
working-directory: ./webapp
25+
run: npm ci
26+
- name: Build
27+
working-directory: ./webapp
28+
run: npm run build
29+
- name: Check formatting with Prettier
30+
working-directory: ./webapp
31+
run: npx prettier . --check

.github/workflows/build.yml

Lines changed: 0 additions & 167 deletions
This file was deleted.

.github/workflows/deploy.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ name: Deploy to Clever Cloud
22

33
on:
44
push:
5+
paths:
6+
- "carbonserver/**"
7+
- "webapp/**"
8+
- "pyproject.toml"
59
branches: [master]
610

711
jobs:

.github/workflows/package.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ name: package
22

33
on:
44
push:
5+
paths:
6+
- "codecarbon/**"
7+
- "pyproject.toml"
58
branches: [master]
69

710
jobs:
@@ -26,3 +29,68 @@ jobs:
2629
with:
2730
name: pypi_dist
2831
path: dist
32+
33+
python-test:
34+
runs-on: ubuntu-24.04
35+
strategy:
36+
matrix:
37+
python-version: ["3.9", "3.12", "3.13"]
38+
steps:
39+
- uses: actions/checkout@v4
40+
- name: Set up Python ${{ matrix.python-version }}
41+
uses: actions/setup-python@v5
42+
with:
43+
python-version: ${{ matrix.python-version }}
44+
- name: Install dependencies
45+
run: |
46+
python -m pip install --upgrade pip
47+
pip install hatch==1.13.0 hatchling==1.25.0
48+
- name: Test package
49+
run: |
50+
hatch run +py=${{ matrix.python-version }} test:package
51+
52+
build-conda:
53+
runs-on: ubuntu-24.04
54+
steps:
55+
- name: Checkout
56+
uses: actions/checkout@v4
57+
- name: Cache build
58+
uses: actions/cache@v4
59+
with:
60+
path: /tmp/conda-bld
61+
key: build-conda-${{ github.sha }}
62+
- name: set version
63+
run: |
64+
python3 .github/pyproject_versions.py --replace True
65+
- name: Build conda package
66+
uses: prefix-dev/rattler-build-action@v0.2.16
67+
with:
68+
build-args: --channel codecarbon --channel conda-forge --output-dir /tmp/conda-bld
69+
recipe-path: .conda/recipe.yaml
70+
upload-artifact: false
71+
72+
test-conda:
73+
runs-on: ubuntu-24.04
74+
needs: [ build-conda ]
75+
steps:
76+
# Checkout needed to get github.sha
77+
- uses: actions/checkout@v4
78+
- name: Setup conda
79+
uses: conda-incubator/setup-miniconda@v3
80+
with:
81+
activate-environment: codecarbon
82+
miniforge-version: latest
83+
python-version: 3.12
84+
use-mamba: true
85+
- name: Restore build
86+
uses: actions/cache@v4
87+
with:
88+
path: /tmp/conda-bld
89+
key: build-conda-${{ github.sha }}
90+
fail-on-cache-miss: true
91+
- name: Install package
92+
shell: bash -l {0}
93+
run: mamba install --channel file:///tmp/conda-bld --channel codecarbon codecarbon
94+
- name: Test conda package
95+
shell: bash -l {0}
96+
run: codecarbon --help

0 commit comments

Comments
 (0)