diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 2e761be..3089b1a 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -31,6 +31,8 @@ jobs: fail-fast: false matrix: python-version: ["3.9", "3.10", "3.11"] + permissions: + id-token: write # This is required for requesting the JWT. steps: - name: Cancel previous uses: styfle/cancel-workflow-action@0.7.0 @@ -55,10 +57,13 @@ jobs: - name: Install Xee run: | pip install -e .[tests] + - uses: 'actions/checkout@v4' + - id: 'auth' + name: 'Authenticate to Google Cloud' + uses: 'google-github-actions/auth@v1' + with: + service_account: ${{ secrets.SERVICE_ACCOUNT }} + workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }} - name: Run unit tests run: | pytest xee - - name: Run scripts tests - # The scripts may define some of the same flags, so we run pytest in separate processes. - run: | - for test in examples/*_test.py; do pytest $test; done diff --git a/setup.py b/setup.py index 9d8a433..ab6ce73 100644 --- a/setup.py +++ b/setup.py @@ -46,7 +46,12 @@ description="A Google Earth Engine extension for Xarray.", long_description=open("README.md", "r", encoding="utf-8").read(), long_description_content_type="text/markdown", - install_requires=["xarray", "earthengine-api>=0.1.374", "pyproj", "affine"], + install_requires=[ + "xarray[parallel]", + "earthengine-api>=0.1.374", + "pyproj", + "affine", + ], extras_require={ "tests": tests_requires, "examples": examples_require, diff --git a/xee/ext_integration_test.py b/xee/ext_integration_test.py index 8e36d4d..e340f52 100644 --- a/xee/ext_integration_test.py +++ b/xee/ext_integration_test.py @@ -13,9 +13,12 @@ # limitations under the License. # ============================================================================== r"""Integration tests for the Google Earth Engine backend for Xarray.""" +import json +import os import pathlib from absl.testing import absltest +from google.auth import identity_pool import numpy as np import xarray as xr from xarray.core import indexing @@ -23,9 +26,26 @@ import ee +_CREDENTIALS_PATH_KEY = 'GOOGLE_APPLICATION_CREDENTIALS' +_SCOPES = [ + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/earthengine', +] + + +def _read_identity_pool_creds() -> identity_pool.Credentials: + credentials_path = os.environ[_CREDENTIALS_PATH_KEY] + with open(credentials_path) as file: + json_file = json.load(file) + credentials = identity_pool.Credentials.from_info(json_file) + return credentials.with_scopes(_SCOPES) + def init_ee_for_tests(): - ee.Initialize(opt_url='https://earthengine-highvolume.googleapis.com') + ee.Initialize( + credentials=_read_identity_pool_creds(), + opt_url=ee.data.HIGH_VOLUME_API_BASE_URL, + ) class EEBackendArrayTest(absltest.TestCase): @@ -337,7 +357,7 @@ def test_parses_ee_url(self): scale=25.0, # in degrees n_images=3, ) - self.assertEqual(dict(ds.dims), {'time': 3, 'lon': 15, 'lat': 7}) + self.assertEqual(dict(ds.dims), {'time': 3, 'lon': 15, 'lat': 8}) ds = self.entry.open_dataset( 'ee:LANDSAT/LC08/C01/T1', drop_variables=tuple(f'B{i}' for i in range(3, 12)),