2023-02-16 20:27:25 +00:00
|
|
|
# SPDX-FileCopyrightText: : 2021-2023 The PyPSA-Eur Authors
|
2021-06-22 09:01:33 +00:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: CC0-1.0
|
|
|
|
|
|
|
|
name: CI
|
|
|
|
|
2022-01-13 17:25:12 +00:00
|
|
|
# Caching method based on and described by:
|
|
|
|
# epassaro (2021): https://dev.to/epassaro/caching-anaconda-environments-in-github-actions-5hde
|
|
|
|
# and code in GitHub repo: https://github.com/epassaro/cache-conda-envs
|
|
|
|
|
2021-07-09 08:22:40 +00:00
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- master
|
|
|
|
pull_request:
|
2022-06-27 17:00:41 +00:00
|
|
|
branches:
|
|
|
|
- master
|
2021-07-09 08:22:40 +00:00
|
|
|
schedule:
|
2022-09-16 13:04:04 +00:00
|
|
|
- cron: "0 5 * * TUE"
|
2021-06-22 09:01:33 +00:00
|
|
|
|
2022-01-13 17:25:12 +00:00
|
|
|
env:
|
2022-04-11 15:08:25 +00:00
|
|
|
CONDA_CACHE_NUMBER: 1 # Change this value to manually reset the environment cache
|
2023-03-08 19:46:00 +00:00
|
|
|
DATA_CACHE_NUMBER: 2
|
2022-01-13 17:25:12 +00:00
|
|
|
|
2021-06-22 09:01:33 +00:00
|
|
|
jobs:
|
|
|
|
build:
|
|
|
|
|
|
|
|
strategy:
|
2023-03-09 10:52:06 +00:00
|
|
|
fail-fast: false
|
2021-06-22 09:01:33 +00:00
|
|
|
matrix:
|
2022-01-13 17:25:12 +00:00
|
|
|
include:
|
|
|
|
# Matrix required to handle caching with Mambaforge
|
2022-09-16 13:04:04 +00:00
|
|
|
- os: ubuntu-latest
|
|
|
|
label: ubuntu-latest
|
|
|
|
prefix: /usr/share/miniconda3/envs/pypsa-eur
|
2022-01-13 17:25:12 +00:00
|
|
|
|
2023-03-07 08:15:29 +00:00
|
|
|
- os: macos-latest
|
|
|
|
label: macos-latest
|
|
|
|
prefix: /Users/runner/miniconda3/envs/pypsa-eur
|
2022-01-13 17:25:12 +00:00
|
|
|
|
2023-03-07 08:15:29 +00:00
|
|
|
- os: windows-latest
|
|
|
|
label: windows-latest
|
|
|
|
prefix: C:\Miniconda3\envs\pypsa-eur
|
2022-01-13 17:25:12 +00:00
|
|
|
|
|
|
|
name: ${{ matrix.label }}
|
2021-06-22 09:01:33 +00:00
|
|
|
|
2022-01-13 17:25:12 +00:00
|
|
|
runs-on: ${{ matrix.os }}
|
2022-09-16 13:04:04 +00:00
|
|
|
|
2021-06-22 09:01:33 +00:00
|
|
|
defaults:
|
|
|
|
run:
|
|
|
|
shell: bash -l {0}
|
2022-09-16 13:04:04 +00:00
|
|
|
|
2021-06-22 09:01:33 +00:00
|
|
|
steps:
|
2023-03-08 19:40:21 +00:00
|
|
|
- uses: actions/checkout@v3
|
2022-09-16 13:04:04 +00:00
|
|
|
|
|
|
|
- name: Setup secrets
|
|
|
|
run: |
|
|
|
|
echo -ne "url: ${CDSAPI_URL}\nkey: ${CDSAPI_TOKEN}\n" > ~/.cdsapirc
|
|
|
|
|
2022-09-19 10:15:05 +00:00
|
|
|
- name: Add solver to environment
|
|
|
|
run: |
|
|
|
|
echo -e "- glpk\n- ipopt<3.13.3" >> envs/environment.yaml
|
|
|
|
if: ${{ matrix.label }} == 'windows-latest'
|
|
|
|
|
|
|
|
- name: Add solver to environment
|
|
|
|
run: |
|
|
|
|
echo -e "- glpk\n- ipopt" >> envs/environment.yaml
|
|
|
|
if: ${{ matrix.label }} != 'windows-latest'
|
|
|
|
|
2022-09-16 13:04:04 +00:00
|
|
|
- name: Setup Mambaforge
|
|
|
|
uses: conda-incubator/setup-miniconda@v2
|
|
|
|
with:
|
|
|
|
miniforge-variant: Mambaforge
|
|
|
|
miniforge-version: latest
|
|
|
|
activate-environment: pypsa-eur
|
|
|
|
use-mamba: true
|
|
|
|
|
2023-03-06 08:27:45 +00:00
|
|
|
- name: Set cache dates
|
|
|
|
run: |
|
|
|
|
echo "DATE=$(date +'%Y%m%d')" >> $GITHUB_ENV
|
|
|
|
echo "WEEK=$(date +'%Y%U')" >> $GITHUB_ENV
|
|
|
|
|
|
|
|
- name: Cache data and cutouts folders
|
|
|
|
uses: actions/cache@v3
|
|
|
|
with:
|
|
|
|
path: |
|
|
|
|
data
|
2023-03-06 10:54:08 +00:00
|
|
|
cutouts
|
2023-03-06 08:27:45 +00:00
|
|
|
key: data-cutouts-${{ env.WEEK }}-${{ env.DATA_CACHE_NUMBER }}
|
2022-09-16 13:04:04 +00:00
|
|
|
|
|
|
|
- name: Create environment cache
|
2023-02-15 09:29:34 +00:00
|
|
|
uses: actions/cache@v3
|
2022-09-16 13:04:04 +00:00
|
|
|
id: cache
|
|
|
|
with:
|
|
|
|
path: ${{ matrix.prefix }}
|
2023-03-06 08:27:45 +00:00
|
|
|
key: ${{ matrix.label }}-conda-${{ env.DATE }}-${{ env.CONDA_CACHE_NUMBER }}
|
2022-09-16 13:04:04 +00:00
|
|
|
|
|
|
|
- name: Update environment due to outdated or unavailable cache
|
|
|
|
run: mamba env update -n pypsa-eur -f envs/environment.yaml
|
|
|
|
if: steps.cache.outputs.cache-hit != 'true'
|
|
|
|
|
|
|
|
- name: Test snakemake workflow
|
|
|
|
run: |
|
|
|
|
conda activate pypsa-eur
|
|
|
|
conda list
|
2023-03-06 10:54:08 +00:00
|
|
|
snakemake -call solve_all_elec_networks --configfile test/config.test1.yaml
|
2023-03-06 16:26:41 +00:00
|
|
|
snakemake -call all --configfile test/config.overnight.yaml
|
|
|
|
snakemake -call all --configfile test/config.myopic.yaml
|
2023-03-08 19:06:18 +00:00
|
|
|
|
|
|
|
- name: Upload artifacts
|
|
|
|
uses: actions/upload-artifact@v3
|
|
|
|
with:
|
|
|
|
name: resources-results
|
|
|
|
path: |
|
|
|
|
resources
|
|
|
|
results
|
|
|
|
if-no-files-found: warn
|
|
|
|
retention-days: 1
|