From d8a69d6e050710de01bd66e402aaacb9a5c555c3 Mon Sep 17 00:00:00 2001 From: betolink Date: Mon, 14 Jul 2025 15:34:33 -0500 Subject: [PATCH 1/4] add PR actions to render previews as in ReadtheDocs --- .github/workflows/pr-pub.yml | 140 +++++++++++++++++++++++++++++++++++ environment.yml | 15 ++-- 2 files changed, 149 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/pr-pub.yml diff --git a/.github/workflows/pr-pub.yml b/.github/workflows/pr-pub.yml new file mode 100644 index 0000000..76d93ed --- /dev/null +++ b/.github/workflows/pr-pub.yml @@ -0,0 +1,140 @@ +on: + pull_request: + branches: [main] + types: [opened, synchronize, closed] + +jobs: + deploy-preview: + runs-on: ubuntu-latest + permissions: + contents: read + pages: write + id-token: write + pull-requests: write + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup micromamba + if: github.event.action != 'closed' + uses: mamba-org/setup-micromamba@v2 + with: + environment-file: environment.yml + init-shell: bash + cache-environment: true + + - name: Setup Quarto + if: github.event.action != 'closed' + uses: quarto-dev/quarto-actions/setup@v2 + + - name: Get commit info + id: commit + run: | + echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + echo "full_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT + echo "commit_message=$(git log -1 --pretty=format:'%s')" >> $GITHUB_OUTPUT + + - name: Render Quarto Project + if: github.event.action != 'closed' + shell: micromamba-shell {0} + run: quarto render + + - name: Deploy to GitHub Pages + if: github.event.action != 'closed' + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./_site + destination_dir: commit-${{ steps.commit.outputs.short_sha }} + keep_files: true + + - name: Find existing preview comment + if: github.event.action != 'closed' + uses: actions/github-script@v6 + id: find-comment + with: + script: | + const comments = await github.rest.issues.listComments({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + }); + + const previewComment = comments.data.find(comment => + comment.user.type === 'Bot' && + comment.body.includes('') + ); + + return previewComment ? previewComment.id : null; + + - name: Create or update preview comment + if: github.event.action != 'closed' + uses: actions/github-script@v6 + with: + script: | + const shortSha = '${{ steps.commit.outputs.short_sha }}'; + const fullSha = '${{ steps.commit.outputs.full_sha }}'; + const commitMessage = '${{ steps.commit.outputs.commit_message }}'; + const previewUrl = `https://${context.repo.owner}.github.io/${context.repo.repo}/commit-${shortSha}/`; + const commitUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${fullSha}`; + const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; + + const body = ` + ## 📖 Quarto Preview + + | | | + |---|---| + | **Latest commit** | [\`${shortSha}\`](${commitUrl}) | + | **Commit message** | ${commitMessage} | + | **Preview URL** | ${previewUrl} | + | **Build log** | [View workflow run](${runUrl}) | + + > The preview will be updated automatically when you push new commits to this PR.`; + + const commentId = ${{ steps.find-comment.outputs.result }}; + + if (commentId) { + await github.rest.issues.updateComment({ + comment_id: commentId, + owner: context.repo.owner, + repo: context.repo.repo, + body: body + }); + } else { + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: body + }); + } + + - name: Clean up preview comment on PR close + if: github.event.action == 'closed' + uses: actions/github-script@v6 + with: + script: | + const comments = await github.rest.issues.listComments({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + }); + + const previewComment = comments.data.find(comment => + comment.user.type === 'Bot' && + comment.body.includes('') + ); + + if (previewComment) { + await github.rest.issues.updateComment({ + comment_id: previewComment.id, + owner: context.repo.owner, + repo: context.repo.repo, + body: ` + ## 📖 Quarto Preview + + ~~Preview was removed when PR was closed.~~` + }); + } diff --git a/environment.yml b/environment.yml index b14c925..7ca1ad2 100644 --- a/environment.yml +++ b/environment.yml @@ -1,15 +1,12 @@ name: nsidc_data_cookbook channels: - conda-forge - - default dependencies: - - python ~=3.10 - + - python ~=3.13 ################################################### # Imported dependencies and extensions # ################################################### - - - jupyterlab + - jupyterlab<=4.2 - matplotlib - cartopy - dask @@ -18,7 +15,13 @@ dependencies: - xarray - rioxarray - pandas + - geopandas - pytest - earthaccess - h5py - + - h5netcdf + - hvplot + - geoviews + - ipyleaflet + - virtualizarr + - fsspec From 608b46e5d486e4727c2f791e86b1619183708480 Mon Sep 17 00:00:00 2001 From: betolink Date: Mon, 14 Jul 2025 16:39:51 -0500 Subject: [PATCH 2/4] update gitignore --- .gitignore | 1 + tutorials/hdf5_formatting.ipynb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 60744de..bdc368c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ _site/ example_data/ *.h5 *.nc +_freeze diff --git a/tutorials/hdf5_formatting.ipynb b/tutorials/hdf5_formatting.ipynb index 95e0939..096d054 100755 --- a/tutorials/hdf5_formatting.ipynb +++ b/tutorials/hdf5_formatting.ipynb @@ -71,7 +71,7 @@ "id": "e70aa9a5-58dc-44e7-a600-a1f9db2027d5", "metadata": {}, "source": [ - "Create some dimension variables. The dimension scales need to be in the group so that they can found by `xarray`." + "Create some dimension variables. The dimension scales need to be in the group so that they can found by `xarray`. -" ] }, { From 4b7a6bc7763c801215faa18245429d9bb8dfeee2 Mon Sep 17 00:00:00 2001 From: betolink Date: Mon, 14 Jul 2025 17:44:01 -0500 Subject: [PATCH 3/4] update workflows --- .github/workflows/pr-pub.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-pub.yml b/.github/workflows/pr-pub.yml index 76d93ed..697409b 100644 --- a/.github/workflows/pr-pub.yml +++ b/.github/workflows/pr-pub.yml @@ -7,7 +7,7 @@ jobs: deploy-preview: runs-on: ubuntu-latest permissions: - contents: read + contents: write pages: write id-token: write pull-requests: write From 0ed250d865b84bec2eccd497e7f3523428e481fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20L=C3=B3pez?= Date: Tue, 15 Jul 2025 11:14:55 -0500 Subject: [PATCH 4/4] Update hdf5_formatting.ipynb --- tutorials/hdf5_formatting.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/hdf5_formatting.ipynb b/tutorials/hdf5_formatting.ipynb index 096d054..95e0939 100755 --- a/tutorials/hdf5_formatting.ipynb +++ b/tutorials/hdf5_formatting.ipynb @@ -71,7 +71,7 @@ "id": "e70aa9a5-58dc-44e7-a600-a1f9db2027d5", "metadata": {}, "source": [ - "Create some dimension variables. The dimension scales need to be in the group so that they can found by `xarray`. -" + "Create some dimension variables. The dimension scales need to be in the group so that they can found by `xarray`." ] }, {