Skip to content

Commit

Permalink
Use service account for CI (#56)
Browse files Browse the repository at this point in the history
* Use service account for CI tests

* Include service account secret

* Parse project_id from service account key data
  • Loading branch information
aazuspan authored Jan 29, 2025
1 parent 3215f13 commit eecc5d9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
12 changes: 4 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 17 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os
import warnings
from collections import UserDict
from pathlib import Path
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit eecc5d9

Please sign in to comment.