Skip to content

Commit 85c9d04

Browse files
authored
Merge pull request #56 from AmberLee2427/main
Add CI workflow for Nexus artefacts
2 parents bd99f84 + 3665e55 commit 85c9d04

File tree

7 files changed

+118
-62
lines changed

7 files changed

+118
-62
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Manual Notebook CI
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
profile:
7+
description: "Execution profile"
8+
required: true
9+
default: "fast"
10+
type: choice
11+
options:
12+
- fast
13+
- full
14+
15+
jobs:
16+
execute-notebooks:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Check out repository
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
submodules: true
25+
26+
- name: Setup micromamba
27+
uses: mamba-org/setup-micromamba@v2
28+
with:
29+
environment-file: env.yml
30+
environment-name: rges-pit-dc
31+
cache-environment: true
32+
33+
- name: Install runner + transformer deps
34+
shell: bash -l {0}
35+
run: |
36+
python -m pip install --upgrade pip
37+
python -m pip install pyyaml nbclient nbformat
38+
39+
- name: Rebuild Nexus-ready notebooks (RRN/build)
40+
shell: bash -l {0}
41+
run: |
42+
rm -rf RRN/build
43+
python scripts/notebook_transformer.py --force
44+
45+
- name: Execute notebooks
46+
shell: bash -l {0}
47+
run: |
48+
SKIP_TAGS=""
49+
if [ "${{ inputs.profile }}" = "fast" ]; then
50+
SKIP_TAGS="slow,ci-skip"
51+
else
52+
SKIP_TAGS="ci-skip"
53+
fi
54+
55+
python scripts/execute_notebooks_ci.py \
56+
--glob "RRN/build/*.ipynb" \
57+
--skip-tags "$SKIP_TAGS" \
58+
--timeout 1800

.github/workflows/publish.yml

Lines changed: 17 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ jobs:
5656
contents: write
5757
pull-requests: write
5858
steps:
59-
- name: Install jq
60-
run: sudo apt-get update && sudo apt-get install -y jq
61-
6259
- name: Download site bundle
6360
uses: actions/download-artifact@v4
6461
with:
@@ -68,7 +65,7 @@ jobs:
6865
- name: Check out site repository
6966
uses: actions/checkout@v4
7067
with:
71-
repository: rges-pit/rges-pit.github.io-dc-copy
68+
repository: rges-pit/rges-pit.github.io
7269
token: ${{ secrets.SITE_SYNC_PAT }}
7370
path: site
7471

@@ -86,11 +83,10 @@ jobs:
8683
git config user.name "github-actions[bot]"
8784
git config user.email "github-actions[bot]@users.noreply.github.com"
8885
89-
# Use upstream main as base (read-only) and create/update branch on fork
90-
git remote add upstream https://github.com/rges-pit/rges-pit.github.io.git
91-
git fetch upstream main
92-
SYNC_BRANCH="chore/data-challenge-sync-dc-copy"
93-
git checkout -B "$SYNC_BRANCH" upstream/main
86+
# Create/update a branch on the upstream repo
87+
git fetch origin main
88+
SYNC_BRANCH="chore/data-challenge-sync"
89+
git checkout -B "$SYNC_BRANCH" origin/main
9490
9591
# Stage and Commit
9692
git add docs/_pages/
@@ -100,59 +96,30 @@ jobs:
10096
fi
10197
git commit -m "chore: sync data-challenge workshop pages"
10298
103-
# Push branch to fork (dc-copy)
99+
# Push branch to upstream
104100
git push -f origin "$SYNC_BRANCH"
105101
106-
# Create PR against upstream.
107-
# Use REST API so we can disambiguate same-owner forks via "<fork-repo>:<branch>".
108-
BASE_REPO_OWNER="rges-pit"
109-
BASE_REPO_NAME="rges-pit.github.io"
110-
HEAD_REPO_OWNER="rges-pit"
111-
HEAD_REPO_NAME="rges-pit.github.io-dc-copy"
102+
# Create PR against upstream (same repo)
103+
BASE_REPO="rges-pit/rges-pit.github.io"
112104
HEAD_BRANCH="$SYNC_BRANCH"
113105
BASE_BRANCH="main"
114106
PR_TITLE="Draft: Sync data-challenge notebooks"
115107
PR_BODY="Automated sync of generated workshop documentation from \`data-challenge-notebooks\`."
116108
117-
# Find an existing open PR from this fork branch.
118-
PULLS_JSON=$(gh api \
119-
--paginate \
120-
-H "Accept: application/vnd.github+json" \
121-
"/repos/$BASE_REPO_OWNER/$BASE_REPO_NAME/pulls?state=open&per_page=100")
122-
123-
EXISTING_PR=$(echo "$PULLS_JSON" | jq -r '.[] | select(.head.ref=="'"$HEAD_BRANCH"'" and .head.repo.name=="'"$HEAD_REPO_NAME"'") | .html_url' | head -n 1)
124-
if [ -n "$EXISTING_PR" ] && [ "$EXISTING_PR" != "null" ]; then
109+
EXISTING_PR=$(gh pr list --repo "$BASE_REPO" --head "$HEAD_BRANCH" --state open --json url --jq '.[0].url')
110+
if [ -n "$EXISTING_PR" ]; then
125111
echo "PR already exists: $EXISTING_PR"
126112
exit 0
127113
fi
128114
129115
echo "Creating new PR..."
130-
set +e
131-
CREATE_PR_JSON=$(gh api \
132-
-H "Accept: application/vnd.github+json" \
133-
-X POST \
134-
"/repos/$BASE_REPO_OWNER/$BASE_REPO_NAME/pulls" \
135-
-f title="$PR_TITLE" \
136-
-f body="$PR_BODY" \
137-
-f head="$HEAD_REPO_OWNER:$HEAD_BRANCH" \
138-
-f base="$BASE_BRANCH" \
139-
-F draft=true 2>&1)
140-
CREATE_STATUS=$?
141-
set -e
142-
143-
if [ $CREATE_STATUS -ne 0 ]; then
144-
echo "PR creation failed (exit $CREATE_STATUS). Full response:"
145-
echo "$CREATE_PR_JSON"
146-
exit 1
147-
fi
148-
149-
NEW_PR_URL=$(echo "$CREATE_PR_JSON" | jq -r '.html_url')
150-
if [ -z "$NEW_PR_URL" ] || [ "$NEW_PR_URL" = "null" ]; then
151-
echo "PR creation did not return a URL. Full response:"
152-
echo "$CREATE_PR_JSON" | jq -r '.'
153-
exit 1
154-
fi
155-
echo "Created PR: $NEW_PR_URL"
116+
gh pr create \
117+
--repo "$BASE_REPO" \
118+
--head "$HEAD_BRANCH" \
119+
--base "$BASE_BRANCH" \
120+
--title "$PR_TITLE" \
121+
--body "$PR_BODY" \
122+
--draft
156123
157124
nexus-publish:
158125
needs: build-pages

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,14 @@ Before submitting a pull request, please check whether an existing issue or disc
9292

9393
## Syncing Notebooks to the Roman Research Nexus
9494

95-
Syncing notebooks from canonical sources in this repo with the STScI `roman_notebooks` repository is an automated process handled by GitHub Actions when a pull request is merged.
95+
Syncing Nexus-ready notebook artifacts is an automated process handled by GitHub Actions when a pull request is merged.
9696

9797
The workflow will:
98-
- Copy the notebook to the appropriate location in the `roman_notebooks` repository.
99-
- Validate that relative paths in the notebook are correct for the RRN structure.
100-
- Correct style and contents to satisfy Nexus-specific requirements.
101-
- Copy any associated `requirements.txt` or `env.yml` files.
98+
- Rebuild Nexus-ready notebook artifacts into `RRN/build/` using `scripts/notebook_transformer.py` and `notebooks_manifest.yml`.
99+
- Export those artifacts into the dedicated `rges-pit/nexus-notebooks` repository via the `RRN/export_submodule/` submodule.
100+
- Force-push the artifact branch (`main`) because the destination repository is treated as export-only.
101+
102+
For a manual, on-demand execution check of the build artifacts, see `RRN/README.md` (Manual Notebook CI).
102103

103104
## Notes on Using and Contributing from Colab
104105

RRN/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,19 @@
99
Notebooks in this directory are managed by GitHub workflow `.github/workflows/publish.yml`.
1010

1111
See notebooks_manifest for canonical source file: `source_path:`.
12+
13+
### Manual Notebook CI (Build Artifacts)
14+
15+
This repository includes a manual (workflow-dispatch) CI job that rebuilds the
16+
Nexus-ready notebook artifacts in `RRN/build/` and then executes them.
17+
18+
- Workflow: `.github/workflows/manual-notebook-ci.yml`
19+
- Profiles:
20+
- **fast**: skips cells tagged `slow` or `ci-skip`
21+
- **full**: skips only `ci-skip`
22+
23+
Notes:
24+
- The workflow deletes `RRN/build/` before rebuilding to avoid executing stale
25+
notebooks (for example, notebooks marked `nexus_support: false` in the
26+
manifest).
27+
- Cell tags can be edited in the notebook UI (cell metadata tags).

TODO.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@
2828
- `reges-pit/nexus-notebooks`
2929
- [ ] add global `refdata_dependencies.yaml` (match `spacetelescope/roman_notebooks` format)
3030
- [ ] decide notebook discovery regexes (paths/substrings STScI wrangler should scan)
31-
- [ ] organize notebooks in directories where each dir has its own `requirements.txt`
32-
- [ ] add optional top-level `environment.yml` (mamba spec for non-pip / low-level deps only)
33-
- [ ] move any per-notebook helper `.py` into the same notebook directories
34-
- [ ] if using shared modules, create a top-level shared dir + symlink into each notebook dir that imports it
35-
- [ ] update automation: publish/update the Nexus repo from `RRN/export/` (no PRs to `roman_notebooks`)
31+
- `notebooks/*.ipynb`
32+
- [-] organize notebooks in directories where each dir has its own `requirements.txt`
33+
- [x] add optional top-level `environment.yml` (mamba spec for non-pip / low-level deps only)
34+
- [-] move any per-notebook helper `.py` into the same notebook directories
35+
- they are downloaded in cells
36+
- [-] if using shared modules, create a top-level shared dir + symlink into each notebook dir that imports it
37+
- [x] update automation: publish/update the Nexus repo from `RRN/export_submodule/` (no PRs to `roman_notebooks`)
3638
- [ ] send STScI the repo URL + chosen regex list + any notes on expected execution order
3739

3840
## Nexus
@@ -44,6 +46,8 @@
4446
- [-] edit the tools notebook to match the Colab/RRN freindly style
4547
- [ ] add Citations sections in all notebooks (is this already done?)
4648
- [ ] delete the `roman_notebooks` PR + fork
49+
- [ ] test that the notebooks run using the provided yaml
50+
- [ ] tag long cells to avoid in quick tests
4751

4852
## Microlensing Tools Notebook
4953
- [ ] table formatting
@@ -59,4 +63,10 @@
5963
- [ ] proof read
6064
- [ ] test run
6165
- [ ] check data import functions
62-
- [ ] Add to nexus export list
66+
- [ ] Add to nexus export list
67+
68+
## Website
69+
- [ ] remove mention of workshop sign-up
70+
- [ ] update with real data links
71+
- [x] change PR from fork to PR from branch
72+
- [ ] delete website fork (dc-copy)

scripts/export_rrn_to_repo.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ def export_rrn_notebooks(
7575
# for requirements.txt placement).
7676
notebook_dirs: set[Path] = set()
7777
for entry in notebooks:
78+
if not entry.get("nexus_support", False):
79+
continue
7880
target = entry.get("rrn_target")
7981
nb_id = entry.get("id")
8082
if not nb_id or not target:
@@ -89,6 +91,8 @@ def export_rrn_notebooks(
8991
shutil.rmtree(nb_dir)
9092

9193
for entry in notebooks:
94+
if not entry.get("nexus_support", False):
95+
continue
9296
nb_id = entry.get("id")
9397
target = entry.get("rrn_target")
9498
if not nb_id or not target:

0 commit comments

Comments
 (0)