Skip to content

Commit 59b1a0c

Browse files
authored
Merge pull request #27 from betolink/main
Adding Github action to execute and render PRs
2 parents 779c8a3 + b40ae43 commit 59b1a0c

File tree

3 files changed

+150
-6
lines changed

3 files changed

+150
-6
lines changed

.github/workflows/pr-pub.yml

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
on:
2+
pull_request:
3+
branches: [main]
4+
types: [opened, synchronize, closed]
5+
6+
jobs:
7+
deploy-preview:
8+
runs-on: ubuntu-latest
9+
permissions:
10+
contents: write
11+
pages: write
12+
id-token: write
13+
pull-requests: write
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Setup micromamba
21+
if: github.event.action != 'closed'
22+
uses: mamba-org/setup-micromamba@v2
23+
with:
24+
environment-file: environment.yml
25+
init-shell: bash
26+
cache-environment: true
27+
28+
- name: Setup Quarto
29+
if: github.event.action != 'closed'
30+
uses: quarto-dev/quarto-actions/setup@v2
31+
32+
- name: Get commit info
33+
id: commit
34+
run: |
35+
echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
36+
echo "full_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
37+
echo "commit_message=$(git log -1 --pretty=format:'%s')" >> $GITHUB_OUTPUT
38+
39+
- name: Render Quarto Project
40+
if: github.event.action != 'closed'
41+
shell: micromamba-shell {0}
42+
run: quarto render
43+
44+
- name: Deploy to GitHub Pages
45+
if: github.event.action != 'closed'
46+
uses: peaceiris/actions-gh-pages@v3
47+
with:
48+
github_token: ${{ secrets.GITHUB_TOKEN }}
49+
publish_dir: ./_site
50+
destination_dir: commit-${{ steps.commit.outputs.short_sha }}
51+
keep_files: true
52+
53+
- name: Find existing preview comment
54+
if: github.event.action != 'closed'
55+
uses: actions/github-script@v6
56+
id: find-comment
57+
with:
58+
script: |
59+
const comments = await github.rest.issues.listComments({
60+
issue_number: context.issue.number,
61+
owner: context.repo.owner,
62+
repo: context.repo.repo,
63+
});
64+
65+
const previewComment = comments.data.find(comment =>
66+
comment.user.type === 'Bot' &&
67+
comment.body.includes('<!-- quarto-preview-comment -->')
68+
);
69+
70+
return previewComment ? previewComment.id : null;
71+
72+
- name: Create or update preview comment
73+
if: github.event.action != 'closed'
74+
uses: actions/github-script@v6
75+
with:
76+
script: |
77+
const shortSha = '${{ steps.commit.outputs.short_sha }}';
78+
const fullSha = '${{ steps.commit.outputs.full_sha }}';
79+
const commitMessage = '${{ steps.commit.outputs.commit_message }}';
80+
const previewUrl = `https://${context.repo.owner}.github.io/${context.repo.repo}/commit-${shortSha}/`;
81+
const commitUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${fullSha}`;
82+
const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
83+
84+
const body = `<!-- quarto-preview-comment -->
85+
## 📖 Quarto Preview
86+
87+
| | |
88+
|---|---|
89+
| **Latest commit** | [\`${shortSha}\`](${commitUrl}) |
90+
| **Commit message** | ${commitMessage} |
91+
| **Preview URL** | ${previewUrl} |
92+
| **Build log** | [View workflow run](${runUrl}) |
93+
94+
> The preview will be updated automatically when you push new commits to this PR.`;
95+
96+
const commentId = ${{ steps.find-comment.outputs.result }};
97+
98+
if (commentId) {
99+
await github.rest.issues.updateComment({
100+
comment_id: commentId,
101+
owner: context.repo.owner,
102+
repo: context.repo.repo,
103+
body: body
104+
});
105+
} else {
106+
await github.rest.issues.createComment({
107+
issue_number: context.issue.number,
108+
owner: context.repo.owner,
109+
repo: context.repo.repo,
110+
body: body
111+
});
112+
}
113+
114+
- name: Clean up preview comment on PR close
115+
if: github.event.action == 'closed'
116+
uses: actions/github-script@v6
117+
with:
118+
script: |
119+
const comments = await github.rest.issues.listComments({
120+
issue_number: context.issue.number,
121+
owner: context.repo.owner,
122+
repo: context.repo.repo,
123+
});
124+
125+
const previewComment = comments.data.find(comment =>
126+
comment.user.type === 'Bot' &&
127+
comment.body.includes('<!-- quarto-preview-comment -->')
128+
);
129+
130+
if (previewComment) {
131+
await github.rest.issues.updateComment({
132+
comment_id: previewComment.id,
133+
owner: context.repo.owner,
134+
repo: context.repo.repo,
135+
body: `<!-- quarto-preview-comment -->
136+
## 📖 Quarto Preview
137+
138+
~~Preview was removed when PR was closed.~~`
139+
});
140+
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ _site/
33
example_data/
44
*.h5
55
*.nc
6+
_freeze

environment.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
name: nsidc_data_cookbook
22
channels:
33
- conda-forge
4-
- default
54
dependencies:
6-
- python ~=3.10
7-
5+
- python ~=3.13
86
###################################################
97
# Imported dependencies and extensions #
108
###################################################
11-
12-
- jupyterlab
9+
- jupyterlab<=4.2
1310
- matplotlib
1411
- cartopy
1512
- dask
@@ -18,7 +15,13 @@ dependencies:
1815
- xarray
1916
- rioxarray
2017
- pandas
18+
- geopandas
2119
- pytest
2220
- earthaccess
2321
- h5py
24-
22+
- h5netcdf
23+
- hvplot
24+
- geoviews
25+
- ipyleaflet
26+
- virtualizarr
27+
- fsspec

0 commit comments

Comments
 (0)