Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 31 additions & 48 deletions .github/workflows/build-server.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
name: build server

on:
pull_request:
paths:
Expand All @@ -10,27 +9,21 @@ on:
- "carbonserver/**"
- "pyproject.toml"
branches: [master]

jobs:
build_server:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
python-version: 3.12
- name: Clean pip cache
run: pip cache purge
version: "latest"
- name: Set up Python
run: uv python install 3.12
- name: Install dependencies
run: |
python -m pip install --upgrade pip

run: uv sync --extra api
- name: Unit tests on api
run: |
pip install hatch==1.13.0 hatchling==1.25.0
hatch run api:test-unit

run: uv run task test-api-unit
test_api_server:
runs-on: ubuntu-latest
# Service containers to run with `container-job`
Expand All @@ -52,39 +45,29 @@ jobs:
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5480:5432

steps:
# Downloads a copy of the code in your repository before running CI tests
- name: Check out repository code
uses: actions/checkout@v4

# Performs a clean installation of all dependencies
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install hatch==1.13.0 hatchling==1.25.0

- name: Setup PostgreSQL
# Runs a script that creates a PostgreSQL table, populates
# the table with data, and then retrieves the data.
run: hatch run api:setup-db

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
env:
CODECARBON_API_URL: http://localhost:8008
# The hostname used to communicate with the PostgreSQL service container
DATABASE_URL: postgresql://codecarbon-user:supersecret@localhost:5480/codecarbon_db
run: |
# hatch run api:server-ci &
sleep 2
# netstat -o -n -a | grep 8008
# hatch run api:test-integ
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
version: "latest"
- name: Set up Python
run: uv python install 3.12
- name: Install dependencies
run: uv sync --extra api
- name: Setup database
env:
DATABASE_URL: postgresql://codecarbon-user:supersecret@localhost:5480/codecarbon_db
run: uv run task setup-db
- name: Integration tests on api
env:
CODECARBON_API_URL: http://localhost:8008
DATABASE_URL: postgresql://codecarbon-user:supersecret@localhost:5480/codecarbon_db
run: |
# uv run task dashboard-ci &
# sleep 10 # wait for server to start
# netstat -o -n -a | grep 8008
# uv run task test-api-integ
echo "Integration tests temporarily disabled - need to fix server startup"
29 changes: 13 additions & 16 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,52 @@
name: package

on:
push:
paths:
- "codecarbon/**"
- "pyproject.toml"
branches: [master]

jobs:
build-package:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
python-version: 3.12
version: "latest"
- name: Set up Python
run: uv python install 3.12
- name: Check versions
run: |
pip install -U pip requests
uv pip install --system requests
python3 .github/check_version.py -o
- name: Build pip package
run: |
pip install -U pip build
python3 -m build
uv build
- name: Archive Pypi artifacts
uses: actions/upload-artifact@v4
with:
name: pypi_dist
path: dist

python-test:
runs-on: ubuntu-24.04
strategy:
matrix:
python-version: ["3.9", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
version: "latest"
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install hatch==1.13.0 hatchling==1.25.0
run: uv sync
- name: Test package
run: |
hatch run +py=${{ matrix.python-version }} test:package

run: uv run task test-package
build-conda:
runs-on: ubuntu-24.04
steps:
Expand All @@ -68,7 +66,6 @@ jobs:
build-args: --channel codecarbon --channel conda-forge --output-dir /tmp/conda-bld
recipe-path: .conda/recipe.yaml
upload-artifact: false

test-conda:
runs-on: ubuntu-24.04
needs: [ build-conda ]
Expand Down
28 changes: 10 additions & 18 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,37 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Upload Python Package

on:
release:
types: [published]

permissions:
contents: read

jobs:
deploy-pypi:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
python-version: 3.12
version: "latest"
- name: Set up Python
run: uv python install 3.12
- name: Check versions
run: |
pip install -U pip requests
uv pip install --system requests
python3 .github/check_version.py
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install hatch==1.13.0 hatchling==1.25.0
- name: Build package
run: hatch build -c
run: uv build
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}

publish-to-conda:
runs-on: ubuntu-24.04
needs: [ deploy-pypi ]
Expand All @@ -64,8 +56,8 @@ jobs:
shell: bash -l {0}
run: codecarbon --help
- name: Conda upload already build package
# This shell is made necessary by https://github.com/conda-incubator/setup-miniconda/issues/128
shell: bash -l {0}
env:
ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_TOKEN }}
run: |
conda install --yes anaconda-client
anaconda -t ${{ secrets.ANACONDA_TOKEN }} upload --user codecarbon /tmp/conda-bld/noarch/codecarbon-*
anaconda upload --user codecarbon /tmp/conda-bld/noarch/codecarbon-*.tar.bz2
17 changes: 8 additions & 9 deletions .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
paths:
- "codecarbon/**"
- "pyproject.toml"
- "requirements.txt"
- "uv.lock"

jobs:
python-test:
Expand All @@ -15,14 +15,13 @@ jobs:
python-version: ["3.9", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
python-version: ${{ matrix.python-version }}
version: "latest"
- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install hatch==1.13.0 hatchling==1.25.0
run: uv sync --python ${{ matrix.python-version }}
- name: Test package
run: |
hatch run +py=${{ matrix.python-version }} test:package
run: uv run --python ${{ matrix.python-version }} task test-package
Loading
Loading