diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b12ee2..4ff6c1c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,16 +19,12 @@ jobs: run: | python -m pip install --upgrade pip pip install hatch - - name: Write persistent EE credentials - env: - EE_TOKEN: ${{ secrets.EE_TOKEN }} - run: | - mkdir -p /home/runner/.config/earthengine - echo $EE_TOKEN > /home/runner/.config/earthengine/credentials - name: Test with pytest + env: + EE_SERVICE_ACCOUNT: ${{ secrets.EE_SERVICE_ACCOUNT }} run: | - hatch run test:all - + hatch run test:all + lint: runs-on: ubuntu-latest diff --git a/tests/conftest.py b/tests/conftest.py index f07ca23..433ae29 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,5 @@ import json +import os import warnings from collections import UserDict from pathlib import Path @@ -65,7 +66,22 @@ def object_cache(): def pytest_sessionstart(session): - ee.Initialize() + _init_ee_for_tests() + + +def _init_ee_for_tests(): + # Use the Github Service Account for CI tests + if os.environ.get("GITHUB_ACTIONS"): + key_data = os.environ.get("EE_SERVICE_ACCOUNT") + project_id = json.loads(key_data).get("project_id") + credentials = ee.ServiceAccountCredentials(None, key_data=key_data) + # Use stored persistent credentials for local tests + else: + # Project should be parsed from credentials + project_id = None + credentials = "persistent" + + ee.Initialize(credentials, project=project_id) @pytest.fixture(autouse=True)