CI-check for scenario management #29
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI-Linux | |
on: | |
push: | |
branches: | |
- scenario_management | |
pull_request: | |
branches: | |
- scenario_management | |
schedule: | |
- cron: "0 5 * * TUE" | |
env: | |
CACHE_NUMBER: 1 # Change this value to manually reset the environment cache | |
jobs: | |
build: | |
strategy: | |
fail-fast: false # don't break CI for ubuntu if windows fails before | |
matrix: | |
include: | |
# Matrix required to handle environment caching with Mambaforge | |
- os: ubuntu-latest | |
label: ubuntu-latest | |
prefix: /usr/share/miniconda3/envs/pypsa-earth | |
name: ${{ matrix.label }} | |
runs-on: ${{ matrix.os }} | |
defaults: | |
run: | |
shell: bash -l {0} | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Download PyPSA-Earth | |
run: | | |
cd .. | |
git clone https://github.com/pypsa-meets-earth/pypsa-earth.git | |
- name: Organize folder structure | |
run: | | |
cd .. | |
cp -r pypsa-kz-data ./pypsa-earth/pypsa-kz-data | |
- name: Setup Mambaforge | |
uses: conda-incubator/setup-miniconda@v2 | |
with: | |
miniforge-variant: Mambaforge | |
miniforge-version: latest | |
activate-environment: pypsa-earth | |
use-mamba: true | |
- name: Create environment cache | |
uses: actions/cache@v2 | |
id: cache | |
with: | |
path: ${{ matrix.prefix }} | |
key: ${{ matrix.label }}-conda-${{ hashFiles('envs/environment.yaml') }}-${{ env.DATE }}-${{ env.CACHE_NUMBER }} | |
- name: Update environment due to outdated or unavailable cache | |
if: steps.cache.outputs.cache-hit != 'true' | |
run: | | |
ls | |
mamba env update -n pypsa-earth -f ../pypsa-earth/envs/environment.yaml | |
- name: Conda list | |
run: | | |
conda list | |
- name: Move test config | |
run: | | |
cd ../pypsa-earth | |
cp pypsa-kz-data/test/config_kz_default_test.yaml ./test/config.landlock.yaml | |
- name: Create test configs | |
run: | | |
cd ../pypsa-earth | |
snakemake --cores all build_test_configs | |
- name: Clean scenarios folder | |
run: | | |
cd ../pypsa-earth | |
rm -r pypsa-kz-data/scenarios/* | |
- name: Move test configs to scenario folder | |
run: | | |
cd ../pypsa-earth | |
cp pypsa-kz-data/test/config_kz_test1.yaml pypsa-kz-data/scenarios/config.kz_2013.yaml | |
cp ./test/tmp/config.landlock_tmp.yaml pypsa-kz-data/config.kz_default.yaml | |
- name : Change Snakefile lines | |
run: | | |
cd ../pypsa-earth | |
sed -i 's\os.system("snakemake -j all solve_all_networks --rerun-incomplete")\os.system(f"snakemake -j1 networks/{wildcards.scenario_name}/base.nc")\g' Snakefile | |
sed -i 's,os.system("snakemake -j1 make_statistics --force"),os.system("cp pypsa-kz-data/data/custom_powerplants.csv data/custom_powerplants.csv")\n\tos.system("snakemake -j1 solve_everything --rerun-incomplete"),g' Snakefile | |
- name: Replace Default config | |
run: | | |
cd ../pypsa-earth | |
cp pypsa-kz-data/config.kz_default.yaml config.default.yaml | |
cp config.default.yaml config.yaml | |
- name: Prepare KZ-scenarios | |
run: | | |
cd ../pypsa-earth | |
snakemake -j1 prepare_kz_scenarios | |
cat configs/scenarios/config.kz_2013.yaml | |
- name: Run all scenarios | |
run: | | |
cd ../pypsa-earth | |
snakemake -j1 run_all_scenarios | |