Skip to content

Commit

Permalink
ci: switch from poetry to uv in github action
Browse files Browse the repository at this point in the history
Co-authored-by: Billie Thompson <billie.thompson@armakuni.com>
  • Loading branch information
jblackman and PurpleBooth committed Oct 9, 2024
1 parent ce9f24e commit 74455c9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 75 deletions.
75 changes: 14 additions & 61 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ on:
pull_request: ~
workflow_dispatch:

env:
PYTHON_VERSION: 3.11

jobs:
validate-pipeline:
uses: armakuni/github-actions/.github/workflows/lint-pipeline.yml@v0.19.4
Expand All @@ -28,15 +25,11 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: specdown/setup-specdown-action@v0.2.30
- name: Set up python ${{ env.PYTHON_VERSION }}
id: setup-python
uses: actions/setup-python@v5
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v3
with:
python-version: ${{ env.PYTHON_VERSION }}
- uses: armakuni/github-actions/setup-poetry@v0.19.4
- name: Install dependencies
shell: bash
run: poetry install --no-interaction
version: "latest"
enable-cache: true
- run: make lint
- run: make test
- run: |
Expand Down Expand Up @@ -70,31 +63,11 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up python ${{ env.PYTHON_VERSION }}
id: setup-python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Load cached Poetry Binary
id: cached-poetry-binary
uses: actions/cache@v4
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v3
with:
path: ~/.local
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}
- run: curl -sSL https://install.python-poetry.org | python3 -
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
shell: bash
run: poetry install --no-interaction --no-root
version: "latest"
enable-cache: true
- name: Cocogitto release
id: release
continue-on-error: true
Expand Down Expand Up @@ -125,35 +98,15 @@ jobs:
- uses: actions/checkout@v4
with:
ref: ${{ needs.release.outputs.version }}
- name: Set up python ${{ env.PYTHON_VERSION }}
id: setup-python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Load cached Poetry Binary
id: cached-poetry-binary
uses: actions/cache@v4
with:
path: ~/.local
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}
- run: curl -sSL https://install.python-poetry.org | python3 -
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
shell: bash
run: poetry install --no-interaction --no-root
version: "latest"
enable-cache: true
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
shell: bash
run: poetry build
run: uv build
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
skip-existing: true
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pipelines from running when the carbon intensity is high.


```shell,script(name="usage",expected_exit_code=0)
poetry run carbon_guard --help
uv run carbon_guard --help
```

``` ,verify(script_name="usage",stream=stdout)
Expand All @@ -32,7 +32,7 @@ poetry run carbon_guard --help
### Check

```shell,script(name="usage-check",expected_exit_code=0)
poetry run carbon_guard check --help
uv run carbon_guard check --help
```

``` ,verify(script_name="usage-check",stream=stdout)
Expand Down Expand Up @@ -112,7 +112,7 @@ poetry run carbon_guard check --help
### Schedule

```shell,script(name="usage-schedule",expected_exit_code=0)
poetry run carbon_guard schedule --help
uv run carbon_guard schedule --help
```

``` ,verify(script_name="usage-schedule",stream=stdout)
Expand Down Expand Up @@ -163,7 +163,7 @@ Comparing carbon levels with the expected outcome for high carbon intensity:

```shell,script(name="carbon_threshold_exceeded", expected_exit_code=1)
carbon_intensity_is 1000
poetry run carbon_guard check --max-carbon-intensity=999
uv run carbon_guard check --max-carbon-intensity=999
```

``` ,verify(script_name="carbon_threshold_exceeded", stream=stdout)
Expand All @@ -174,14 +174,14 @@ You may also return a successful exit code even on high carbon intensity by pass

```shell,script(name="carbon_threshold_exceeded_and_skipped", expected_exit_code=0)
carbon_intensity_is 1000
poetry run carbon_guard check --max-carbon-intensity=999 --advise-only
uv run carbon_guard check --max-carbon-intensity=999 --advise-only
```

Comparing carbon levels with the expected outcome for low carbon intensity:

```shell,script(name="carbon_threshold_ok", expected_exit_code=0)
carbon_intensity_is 999
poetry run carbon_guard check --max-carbon-intensity=999
uv run carbon_guard check --max-carbon-intensity=999
```

``` ,verify(script_name="carbon_threshold_ok", stream=stdout)
Expand All @@ -201,7 +201,7 @@ Using the [national-grid-eso-carbon-intensity data source](https://carbonintensi
[**note**] this only supplies data for the United Kingdom.

```shell,script(name="national_grid_eso_carbon_threshold_ok", expected_exit_code=0)
poetry run carbon_guard check --data-source national-grid-eso-carbon-intensity --max-carbon-intensity=100000
uv run carbon_guard check --data-source national-grid-eso-carbon-intensity --max-carbon-intensity=100000
```

``` ,skip()
Expand All @@ -211,7 +211,7 @@ Carbon intensity is 98 gCO2eq/kWh, which is below or equal to the max of 100000
You can use this data provider to schedule find the forecasted lowest carbon intensity within a given time period.

```shell,script(name="national_grid_eso_carbon_threshold_ok", expected_exit_code=0)
poetry run carbon_guard schedule --data-source national-grid-eso-carbon-intensity --within "1 hour"
uv run carbon_guard schedule --data-source national-grid-eso-carbon-intensity --within "1 hour"
```

``` ,skip()
Expand All @@ -225,7 +225,7 @@ Using the [co2-signal data source](https://www.co2signal.com/)

```shell,script(name="co2-signal-carbon-threshold-ok", expected_exit_code=0)
# export CO2_SIGNAL_API_KEY=<your_api_key_here>
poetry run carbon_guard check --data-source co2-signal --max-carbon-intensity=100000 --co2-signal-country-code=GB
uv run carbon_guard check --data-source co2-signal --max-carbon-intensity=100000 --co2-signal-country-code=GB
```

``` ,skip()
Expand All @@ -238,7 +238,7 @@ if you don't provide a `co2-signal-country-code` the call will fail.

```shell,script(name="co2-signal-no-country-code-error", expected_exit_code=1)
# export CO2_SIGNAL_API_KEY=<your_api_key_here>
poetry run carbon_guard check --data-source co2-signal --max-carbon-intensity=100000
uv run carbon_guard check --data-source co2-signal --max-carbon-intensity=100000
```

``` ,verify(script_name="co2-signal-no-country-code-error", stream=stdout)
Expand All @@ -249,7 +249,7 @@ if you don't provide a `co2-signal-api-key` the call will fail.

```shell,script(name="co2-signal-no-api-key-error", expected_exit_code=1)
export CO2_SIGNAL_API_KEY=""
poetry run carbon_guard check --data-source co2-signal --max-carbon-intensity=100000 --co2-signal-country-code=GB
uv run carbon_guard check --data-source co2-signal --max-carbon-intensity=100000 --co2-signal-country-code=GB
```

``` ,verify(script_name="co2-signal-no-api-key-error", stream=stdout)
Expand Down
6 changes: 3 additions & 3 deletions cog.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ branch_whitelist = [
"release/**"
]
pre_bump_hooks = [
"poetry version {{version}}",
"poetry lock --no-update",
"uv version {{version}}",
"uv lock --no-upgrade",
]
post_bump_hooks = [
"git push origin v{{version}}",
Expand All @@ -24,4 +24,4 @@ repository = "carbon-guard"
owner = "armakuni"
authors = []

[bump_profiles]
[bump_profiles]

0 comments on commit 74455c9

Please sign in to comment.