Skip to content

Commit

Permalink
ci: better inhouse checks (#1331)
Browse files Browse the repository at this point in the history
* ci: better inhouse checks

* fix: no uv
  • Loading branch information
lkstrp authored Sep 27, 2024
1 parent d4bad07 commit 9919163
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 40 deletions.
124 changes: 94 additions & 30 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,19 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
ENV_FILE: envs/environment.yaml

jobs:
run:
name: Run
run-tests:
name: OS
strategy:
fail-fast: false
matrix:
os:
- macos
- windows
- ubuntu
inhouse:
- stable-inhouse-deps
- dev-inhouse-deps
exclude:
- os: macos
inhouse: dev-inhouse-deps
- os: windows
inhouse: dev-inhouse-deps
runs-on: ${{ matrix.os }}-latest

defaults:
Expand All @@ -46,57 +41,126 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Setup secrets
- name: Setup secrets & cache dates
run: |
echo -ne "url: ${CDSAPI_URL}\nkey: ${CDSAPI_TOKEN}\n" > ~/.cdsapirc
echo "week=$(date +'%Y%U')" >> $GITHUB_ENV # data and cutouts
echo "today=$(/bin/date -u '+%Y%m%d')" >> $GITHUB_ENV # env
- uses: actions/cache@v4
with:
path: |
data
cutouts
key: data-cutouts-${{ env.week }}

- uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: pypsa-eur

- name: Cache Conda env
uses: actions/cache@v4
with:
path: ${{ env.CONDA }}/envs
key: conda-${{ runner.os }}-${{ runner.arch }}-${{ env.today }}-${hashFiles('${{ env.ENV_FILE }}')}
id: cache-env

- name: Update environment
if: steps.cache-env.outputs.cache-hit != 'true'
run: conda env update -n pypsa-eur -f ${{ env.ENV_FILE }}

- name: Set cache dates
- name: Run snakemake test workflows
run: |
conda activate pypsa-eur
make test
- name: Upload artifacts
uses: actions/upload-artifact@v3.2.1-node20
with:
name: logs-${{ matrix.inhouse }}
path: |
logs
.snakemake/log
retention-days: 3

run-tests-on-dev-deps:
name: Inhouse
strategy:
fail-fast: false
matrix:
inhouse:
- pypsa
- atlite
- powerplantmatching
- linopy
runs-on: ubuntu-latest

defaults:
run:
shell: bash -l {0}

steps:
- uses: actions/checkout@v4

# Only run checks if package is not pinned
- name: Check if inhouse package is pinned
run: |
grep_line=$(grep -- '- ${{ matrix.inhouse }}' ${{ env.ENV_FILE }})
if [[ $grep_line == *"<"* || $grep_line == *"=="* ]]; then
echo "pinned=true" >> $GITHUB_ENV
else
echo "pinned=false" >> $GITHUB_ENV
fi
- name: Setup secrets & cache dates
if: env.pinned == 'false'
run: |
echo -ne "url: ${CDSAPI_URL}\nkey: ${CDSAPI_TOKEN}\n" > ~/.cdsapirc
echo "week=$(date +'%Y%U')" >> $GITHUB_ENV # data and cutouts
echo "today=$(/bin/date -u '+%Y%m%d')" >> $GITHUB_ENV # env
- name: Cache data and cutouts folders
uses: actions/cache@v4
- uses: actions/cache@v4
if: env.pinned == 'false'
with:
path: |
data
cutouts
key: data-cutouts-${{ env.week }}

- name: Setup Conda
uses: conda-incubator/setup-miniconda@v3
- uses: conda-incubator/setup-miniconda@v3
if: env.pinned == 'false'
with:
activate-environment: pypsa-eur

- name: Cache Conda env
if: env.pinned == 'false'
uses: actions/cache@v4
with:
path: ${{ env.CONDA }}/envs
key: conda-${{ runner.os }}--${{ runner.arch }}--${{ env.today }}-${{ hashFiles('envs/environment.yaml') }}
key: conda-${{ runner.os }}-${{ runner.arch }}-${{ matrix.inhouse }}-${{ env.today }}-${hashFiles('${{ env.ENV_FILE }}')}
id: cache-env

- name: Update environment
if: steps.cache-env.outputs.cache-hit != 'true'
run: conda env update -n pypsa-eur -f envs/environment.yaml
if: env.pinned == 'false' && steps.cache-env.outputs.cache-hit != 'true'
run: conda env update -n pypsa-eur -f ${{ env.ENV_FILE }}

- name: Install inhouse packages from master
if: matrix.inhouse == 'dev-inhouse-deps'
if: env.pinned == 'false'
run: |
python -m pip install uv
uv pip install git+https://github.com/PyPSA/pypsa.git@master
uv pip install git+https://github.com/PyPSA/atlite.git@master
uv pip install git+https://github.com/PyPSA/powerplantmatching.git@master
uv pip install git+https://github.com/PyPSA/linopy.git@master
python -m pip install git+https://github.com/PyPSA/${{ matrix.inhouse }}.git@master
- name: Run snakemake test workflows
if: env.pinned == 'false'
run: |
conda activate pypsa-eur
make test
- name: Upload artifacts
if: matrix.os == 'ubuntu' && matrix.inhouse == 'stable-inhouse-deps'
uses: actions/upload-artifact@v4.4.0
if: env.pinned == 'false'
uses: actions/upload-artifact@v4
with:
name: resources-results
name: logs-${{ matrix.inhouse }}
path: |
results
retention-days: 7
logs
.snakemake/log
retention-days: 3
4 changes: 2 additions & 2 deletions config/test/config.electricity.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ lines:

solving:
solver:
name: glpk
options: "glpk-default"
name: highs
options: highs-default


plotting:
Expand Down
4 changes: 2 additions & 2 deletions config/test/config.myopic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ industry:

solving:
solver:
name: glpk
options: glpk-default
name: highs
options: highs-default
mem: 4000

plotting:
Expand Down
4 changes: 2 additions & 2 deletions config/test/config.overnight.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ industry:

solving:
solver:
name: glpk
options: glpk-default
name: highs
options: highs-default
mem: 4000

plotting:
Expand Down
4 changes: 2 additions & 2 deletions config/test/config.perfect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ industry:

solving:
solver:
name: glpk
options: glpk-default
name: highs
options: highs-default
mem: 4000

plotting:
Expand Down
4 changes: 2 additions & 2 deletions config/test/config.scenarios.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ renewable:

solving:
solver:
name: glpk
options: "glpk-default"
name: highs
options: highs-default

0 comments on commit 9919163

Please sign in to comment.