From 00023e22740fc39caaad25b89cede1c1e2688e6a Mon Sep 17 00:00:00 2001 From: Lukas Trippe Date: Wed, 8 Jan 2025 17:12:39 +0100 Subject: [PATCH] add pypsa-eur model tests (#405) --- .github/workflows/test-models.yml | 111 ++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 .github/workflows/test-models.yml diff --git a/.github/workflows/test-models.yml b/.github/workflows/test-models.yml new file mode 100644 index 00000000..43d5906e --- /dev/null +++ b/.github/workflows/test-models.yml @@ -0,0 +1,111 @@ +name: Test models + +on: + push: + branches: + - master + pull_request: + branches: + - master + schedule: + - cron: "0 5 * * *" + +# Cancel any in-progress runs when a new run is triggered +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + test-pypsa-eur: + name: PyPSA-Eur + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + version: + - master + # - latest # Activate when v0.14.0 is released + + defaults: + run: + shell: bash -l {0} + + steps: + - uses: actions/checkout@v4 + with: + repository: PyPSA/pypsa-eur + ref: master + + - name: Check out latest release + if: matrix.version == 'latest' + run: | + git fetch --tags + latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`) + git checkout $latest_tag + + # Only run check if package is not pinned + - name: Check if inhouse package is pinned + run: | + grep_line=$(grep -- '- pypsa' envs/environment.yaml) + 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 + + - uses: actions/cache@v4 + if: env.pinned == 'false' + with: + path: | + data + cutouts + key: data-cutouts-${{ env.week }} + + - 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-pypsa-eur-${{ env.week }}-${{ hashFiles('envs/linux-pinned.yaml') }} + id: cache-env + + - name: Update environment + if: env.pinned == 'false' && steps.cache-env.outputs.cache-hit != 'true' + run: conda env update -n pypsa-eur -f envs/linux-pinned.yaml + + - name: Install package from ref + if: env.pinned == 'false' + run: | + python -m pip install git+https://github.com/${{ github.repository }}@${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + + - name: Run snakemake test workflows + if: env.pinned == 'false' + run: | + make test + + - name: Run unit tests + if: env.pinned == 'false' + run: | + make unit-test + + - name: Upload artifacts + if: env.pinned == 'false' + uses: actions/upload-artifact@v4 + with: + name: results-pypsa-eur-${{ matrix.version }} + path: | + logs + .snakemake/log + results + retention-days: 3