-
-
Notifications
You must be signed in to change notification settings - Fork 1
ci: per-PR rendered previews on GitHub Pages (lecture-python-programming) #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| # PR preview on GitHub Pages — self-contained (GITHUB_TOKEN only, no org secrets). | ||
| # | ||
| # Builds a real lecture site (QuantEcon/lecture-python-programming) with the | ||
| # PR's theme via a static `myst build --html` — the production export path the | ||
| # Playwright harness (live `myst start`) never exercises — and deploys it to | ||
| # the gh-pages branch under pr-preview/pr-<n>/. A sticky PR comment links the | ||
| # preview; closing the PR tears the subdirectory down. | ||
| # | ||
| # The content repo is a legacy Jupyter Book (_config.yml/_toc.yml): `myst init` | ||
| # performs the JB→MyST upgrade at build time, so the preview doubles as a | ||
| # continuous migration-readiness check for the lecture content (PLAN.md open | ||
| # question 4). Content is cloned at full depth so the git-metadata plugin | ||
| # (plugins/git-metadata.mjs, PR #83) renders real per-page history. | ||
| name: PR Preview | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, reopened, synchronize, closed] | ||
|
|
||
| concurrency: | ||
| group: pr-preview-${{ github.event.number }} | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: | ||
| contents: write # push the rendered site to the gh-pages branch | ||
| pull-requests: write # sticky preview-link comment | ||
|
|
||
| env: | ||
| CONTENT_REPO: QuantEcon/lecture-python-programming | ||
| CONTENT_DIR: lectures | ||
|
|
||
| jobs: | ||
| preview: | ||
| name: Build & deploy preview (gh-pages) | ||
| # Same-repo PRs only, like update-snapshots.yml (fork PRs get a read-only | ||
| # GITHUB_TOKEN and could not deploy anyway). | ||
| if: github.event.pull_request.head.repo.full_name == github.repository | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v5 | ||
| - uses: actions/setup-node@v5 | ||
| if: github.event.action != 'closed' | ||
| with: | ||
| node-version: 24 | ||
| cache: npm | ||
| - name: Install dependencies | ||
| if: github.event.action != 'closed' | ||
| run: npm ci | ||
| - name: Install mystmd CLI | ||
| if: github.event.action != 'closed' | ||
| run: npm install -g mystmd | ||
| # Builds the candidate theme from this branch into .deploy/quantecon-theme. | ||
| - name: Build theme template | ||
| if: github.event.action != 'closed' | ||
| run: make build-theme | ||
| - name: Checkout lecture content (full history for git metadata) | ||
| if: github.event.action != 'closed' | ||
| uses: actions/checkout@v5 | ||
| with: | ||
| repository: ${{ env.CONTENT_REPO }} | ||
| path: preview-content | ||
| fetch-depth: 0 | ||
| - name: Convert content to MyST and point it at the PR theme | ||
| if: github.event.action != 'closed' | ||
| working-directory: preview-content/${{ env.CONTENT_DIR }} | ||
| env: | ||
| THEME_DIR: ${{ github.workspace }}/.deploy/quantecon-theme | ||
| PLUGIN: ${{ github.workspace }}/plugins/git-metadata.mjs | ||
| CONTENT_GITHUB: https://github.com/${{ env.CONTENT_REPO }} | ||
| run: | | ||
| # `myst init` upgrades the legacy Jupyter Book to myst.yml. With | ||
| # piped (non-TTY) stdin it exits non-zero on its follow-up | ||
| # "run myst start now?" prompt after the config is written — | ||
| # tolerate that, then assert the upgrade actually happened. | ||
| printf 'y\nn\n' | myst init || true | ||
| test -f myst.yml | ||
| yq -i '.site.template = env(THEME_DIR)' myst.yml | ||
| yq -i '.project.github = env(CONTENT_GITHUB)' myst.yml | ||
| # The git-metadata plugin ships with the theme from PR #83 onward; | ||
| # guard so previews still build on branches that predate it. | ||
| if [ -f "$PLUGIN" ]; then | ||
| yq -i '.project.plugins = [env(PLUGIN)]' myst.yml | ||
| fi | ||
| - name: Build static site | ||
| if: github.event.action != 'closed' | ||
| working-directory: preview-content/${{ env.CONTENT_DIR }} | ||
| env: | ||
| # Must match the Pages subpath the deploy step publishes to. | ||
| BASE_URL: /quantecon-theme.mystmd/pr-preview/pr-${{ github.event.number }} | ||
| run: myst build --html | ||
| # auto mode: deploys on opened/reopened/synchronize, removes the | ||
| # pr-preview/pr-<n>/ subdirectory on closed, and maintains the sticky | ||
| # comment. Root .nojekyll on gh-pages (seeded once) keeps Pages from | ||
| # eating the underscore-prefixed asset paths (build/_assets/...). | ||
| - name: Deploy / teardown preview | ||
| uses: rossjrw/pr-preview-action@v1 | ||
| with: | ||
| source-dir: preview-content/${{ env.CONTENT_DIR }}/_build/html | ||
| action: auto | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.