Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub actions for unit testing in Petals #114

Merged
merged 24 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bbd5bc8
Add GitHub CI workflow for building environment and testing
peanutfun Feb 21, 2024
77ae975
Init shell explicitly and always enter Petals directory
peanutfun Feb 21, 2024
f5a9758
Change shell setup
peanutfun Feb 21, 2024
c3d6a2c
ci: Bash should be initialized by default
peanutfun Feb 21, 2024
c75d2dc
ci: Fix environment name for update
peanutfun Feb 21, 2024
04be0c4
ci: Fix paths
peanutfun Feb 21, 2024
34b5dfa
Specify coverage output files and dirs in Makefile
peanutfun Feb 21, 2024
239e755
Fix working directory for unit tests
peanutfun Feb 21, 2024
d8078c1
Try two environment spec files in one go
peanutfun Feb 21, 2024
6b8c0c0
ci: Fix workdir syntax
peanutfun Feb 21, 2024
ba36b70
ci: Fix issue where wrong branches were checked out
peanutfun Feb 21, 2024
2c7c60a
ci: Fix environment file path
peanutfun Feb 21, 2024
7d3fba4
ci: Use latest micromamba
peanutfun Feb 21, 2024
ff923de
ci: Revert to separate step for environment update
peanutfun Feb 21, 2024
db04f26
Create reusable workflow
peanutfun Feb 21, 2024
295e426
Create caller workflow triggering on push
peanutfun Feb 21, 2024
003689d
ci: Add name to caller workflow
peanutfun Feb 21, 2024
19c4afe
ci: Output a pip freeze for debugging
peanutfun Feb 22, 2024
39e0e94
ci: Explicitly state repo to check out
peanutfun Feb 22, 2024
de345fb
ci: Do not freeze or upgrade with pip
peanutfun Feb 23, 2024
d35f8b3
Merge branch 'develop' into github-actions
peanutfun Apr 5, 2024
5465beb
Update .github/workflows/testing.yml
peanutfun Apr 5, 2024
b8dcf5f
Rename tests and test results
peanutfun Apr 5, 2024
7bc628a
Merge branch 'github-actions' of https://github.com/CLIMADA-project/c…
peanutfun Apr 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: GitHub CI

on: [push]

jobs:
ci:
name: Petals
uses: ./.github/workflows/testing.yml
with:
petals_branch: ${{ github.ref }}
permissions:
# For publishing results
checks: write
99 changes: 99 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Petals Testing

# 'Reusable workflow', can be triggered from other workflows
on:
workflow_call:
inputs:
petals_branch:
description: Branch of CLIMADA Petals to check out
type: string
default: develop
required: false
core_branch:
description: Branch of CLIMADA Core to test against
type: string
default: develop
required: false


# Use bash explicitly for being able to enter the conda environment
defaults:
run:
shell: bash -el {0}

jobs:
build-and-test:
name: Unit Tests
runs-on: ubuntu-latest
permissions:
# For publishing results
checks: write

# Run this test for different Python versions
strategy:
# Do not abort other tests if only a single one fails
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]

steps:
-
name: Checkout Petals
uses: actions/checkout@v4
with:
repository: CLIMADA-project/climada_petals
path: climada_petals
ref: ${{ inputs.petals_branch }}
-
name: Checkout Core
uses: actions/checkout@v4
with:
repository: CLIMADA-project/climada_python
path: climada_python
ref: ${{ inputs.core_branch }}
-
# Store the current date to use it as cache key for the environment
name: Get current date
id: date
run: echo "date=$(date +%Y-%m-%d)" >> "${GITHUB_OUTPUT}"
-
name: Create Environment with Mamba
uses: mamba-org/setup-micromamba@v1
with:
environment-name: climada_env_${{ matrix.python-version }}
environment-file: climada_python/requirements/env_climada.yml
# NOTE: Might be able to give second spec file in create-args in future
# micromamba version
create-args: >-
python=${{ matrix.python-version }}
make
# Persist environment for branch, Python version, single day
cache-environment-key: env-${{ github.ref }}-${{ matrix.python-version }}-${{ steps.date.outputs.date }}
-
name: Update Environment for Petals
run: |
micromamba update -n climada_env_${{ matrix.python-version }} -f climada_petals/requirements/env_climada.yml
-
name: Install CLIMADA Core and Petals
run: |
python -m pip install "./climada_python[test]" "./climada_petals"
-
name: Run Unit Tests
working-directory: climada_petals/
run: |
make unit_test
-
name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
junit_files: climada_petals/tests_xml/tests.xml
check_name: "Petals / Unit Test Results (${{ matrix.python-version }})"
comment_mode: "off"
-
name: Upload Coverage Reports
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-report-petals-unittests-py${{ matrix.python-version }}
path: climada_petals/coverage/
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
PYTEST_JUNIT_ARGS = --junitxml=tests_xml/tests.xml

PYTEST_COV_ARGS = \
--cov --cov-config=.coveragerc --cov-report html --cov-report xml \
--cov-report term:skip-covered
--cov --cov-config=.coveragerc --cov-report html:coverage \
--cov-report xml:coverage.xml --cov-report term:skip-covered

PYTEST_ARGS = $(PYTEST_JUNIT_ARGS) $(PYTEST_COV_ARGS)

Expand Down