diff --git a/.github/workflows/ci-tutorials.yml b/.github/workflows/ci-tutorials.yml new file mode 100644 index 0000000..587a422 --- /dev/null +++ b/.github/workflows/ci-tutorials.yml @@ -0,0 +1,92 @@ +name: Test notebooks +on: + workflow_dispatch: + push: + branches: + - main + pull_request: + branches: + - main + schedule: + # Run every monday at 7am EST + - cron: '0 12 * * 1' + +concurrency: + # Cancel intermediate builds only on pull requests + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} + +defaults: + run: + shell: bash -l {0} + +jobs: + run-notebook: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + + - name: Install Conda environment with Micromamba + uses: mamba-org/setup-micromamba@v3 + with: + environment-file: binder/environment.yml + environment-name: Earthdata2026 + create-args: >- + conda + cache-environment: true + + - name: Install dependencies for testing + run: | + which python + python --version + pip install jupyter nbconvert + + - name: Create EDL .netrc file + run: | + cat < $HOME/.netrc + machine urs.earthdata.nasa.gov + login ${{ secrets.EDL_USERNAME }} + password ${{ secrets.EDL_PASSWORD }} + EOF + chmod 600 $HOME/.netrc + + - name: Test each notebook sequentially + run: | + # Loop over all notebooks and count how many fail to complete + NUM_FAILED=0 + NUM_TOTAL=0 + for file in ./binder/*.ipynb; do + ((NUM_TOTAL++)) + echo "" + echo "*****************************" + echo "Running notebook \"$file\"..." + jupyter nbconvert --to notebook --execute $file --output executed_notebook.ipynb + if [ $? -eq 0 ]; then + echo "...$file succeeded!" + else + echo "...$file failed" + ((NUM_FAILED++)) + fi + + # Clean up! + rm -f ./binder/data/*.nc4 + + echo "*****************************" + echo "" + done + + echo "" + echo "*****************************" + echo "*****************************" + echo "" + + if [[ $NUM_FAILED > 1 ]]; then + echo "$NUM_FAILED of $NUM_TOTAL notebooks failed." + exit 1 + elif [[ $NUM_FAILED = 1 ]]; then + echo "$NUM_FAILED of $NUM_TOTAL notebooks failed; this is expected until MERRA2 notebook is fixed" + echo "See https://github.com/OPENDAP/NASA-tutorials/issues/28; remove this elif clause and update first check to NUM_FAILED > 0 when fixed." + else + echo "$NUM_TOTAL notebooks succeeded." + fi + diff --git a/.gitignore b/.gitignore index 9cd04e8..105ff94 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,4 @@ stare/pystare/ ## any data *.nc *.sqlite - +*.nc4 diff --git a/README.md b/README.md index 5a59c1f..fb2295d 100644 --- a/README.md +++ b/README.md @@ -52,13 +52,13 @@ $ conda activate 3. Build the virtual environment for the tutorials ``` -$ conda env create -f binder/environment.yml` +$ conda env create -f binder/environment.yml ``` 4. After a few minutes, activate the new environment ``` -$ conda activate Earthdata2026` +$ conda activate Earthdata2026 ``` 5. Run `jupyter lab` and the notebooks will appear in your running/default diff --git a/binder/Authenticate.ipynb b/binder/Authenticate.ipynb index 0036bee..3f30ef9 100644 --- a/binder/Authenticate.ipynb +++ b/binder/Authenticate.ipynb @@ -52,10 +52,14 @@ "metadata": {}, "outputs": [], "source": [ - "auth = earthaccess.login(strategy=\"interactive\", persist=True) # you will be promted to add your EDL credentials\n", + "from earthaccess.exceptions import LoginStrategyUnavailable\n", + "try:\n", + " auth = earthaccess.login(strategy=\"netrc\", persist=True) # you will be promted to add your EDL credentials\n", + "except LoginStrategyUnavailable:\n", + " auth = earthaccess.login(strategy=\"interactive\", persist=True)\n", "\n", "# pass Token Authorization to a new Session.\n", - "my_session = auth.get_session()" + "my_session = session=auth.get_session()" ] }, { diff --git a/binder/environment.yml b/binder/environment.yml index c788bc3..36143c1 100644 --- a/binder/environment.yml +++ b/binder/environment.yml @@ -22,4 +22,4 @@ dependencies: - pyresample - xarray=2026.1 - pip: - - git+https://github.com/pydap/pydap.git + - git+https://github.com/pydap/pydap.git \ No newline at end of file