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/.gitignore b/.gitignore index 60744de..bdc368c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ _site/ example_data/ *.h5 *.nc +_freeze 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 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`. -" ] }, {