Skip to content

MAINT: use netlify-cli for sending html to netlify #1489

MAINT: use netlify-cli for sending html to netlify

MAINT: use netlify-cli for sending html to netlify #1489

Workflow file for this run

name: Build Project [using jupyter-book]
on:
pull_request:
workflow_dispatch:
jobs:
preview:
runs-on: "runs-on=${{ github.run_id }}/family=g4dn.2xlarge/image=quantecon_ubuntu2404/disk=large"
steps:
- uses: actions/checkout@v5
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup Anaconda
uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
auto-activate-base: true
miniconda-version: 'latest'
python-version: "3.13"
environment-file: environment.yml
activate-environment: quantecon
- name: Install JAX, Numpyro, PyTorch
shell: bash -l {0}
run: |
pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu128
pip install pyro-ppl
pip install --upgrade "jax[cuda12-local]==0.6.2"
pip install numpyro pyro-ppl
python scripts/test-jax-install.py
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
- name: Install Netlify CLI
run: npm install -g netlify-cli
- name: Check nvidia Drivers
shell: bash -l {0}
run: nvidia-smi
- name: Display Conda Environment Versions
shell: bash -l {0}
run: conda list
- name: Display Pip Versions
shell: bash -l {0}
run: pip list
- name: Download "build" folder (cache)
uses: dawidd6/action-download-artifact@v11
with:
workflow: cache.yml
branch: main
name: build-cache
path: _build
# Build Assets (Download Notebooks and PDF via LaTeX)
- name: Build Download Notebooks (sphinx-tojupyter)
shell: bash -l {0}
run: |
jb build lectures -n -W --keep-going --path-output ./ --builder=custom --custom-builder=jupyter
mkdir -p _build/html/_notebooks
cp -u _build/jupyter/*.ipynb _build/html/_notebooks
- name: Upload Execution Reports (Download Notebooks)
uses: actions/upload-artifact@v4
if: failure()
with:
name: execution-reports-notebooks
path: _build/jupyter/reports
- name: Build PDF from LaTeX
shell: bash -l {0}
run: |
jb build lectures --builder pdflatex --path-output ./ -W --keep-going
mkdir -p _build/html/_pdf
cp -u _build/latex/*.pdf _build/html/_pdf
- name: Upload Execution Reports (LaTeX)
uses: actions/upload-artifact@v4
if: failure()
with:
name: execution-reports
path: _build/latex/reports
# Final Build of HTML
- name: Build HTML
shell: bash -l {0}
run: |
jb build lectures --path-output ./ -n -W --keep-going
- name: Upload Execution Reports (HTML)
uses: actions/upload-artifact@v4
if: failure()
with:
name: execution-reports
path: _build/html/reports
- name: Deploy to Netlify
id: netlify-deploy
run: |
# Deploy to Netlify and capture the deploy URL
DEPLOY_URL=$(netlify deploy \
--dir=_build/html \
--site=${{ secrets.NETLIFY_SITE_ID }} \
--auth=${{ secrets.NETLIFY_AUTH_TOKEN }} \
--json | jq -r '.deploy_url')
echo "DEPLOY_URL=$DEPLOY_URL" >> $GITHUB_OUTPUT
echo "Preview URL: $DEPLOY_URL"
- name: Comment PR with preview link
uses: actions/github-script@v7
with:
script: |
const deployUrl = '${{ steps.netlify-deploy.outputs.DEPLOY_URL }}';
const comment = `🚀 **Preview deployed!**
Preview URL: ${deployUrl}
Built from commit: ${context.sha.substring(0, 7)}`;
// Check if we already commented on this PR
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('Preview deployed!')
);
if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: comment
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: comment
});
}
- name: Update deployment status
uses: actions/github-script@v7
if: always()
with:
script: |
const deployUrl = '${{ steps.netlify-deploy.outputs.DEPLOY_URL }}';
const state = '${{ job.status }}' === 'success' ? 'success' : 'failure';
if (context.payload.deployment?.id) {
await github.rest.repos.createDeploymentStatus({
owner: context.repo.owner,
repo: context.repo.repo,
deployment_id: context.payload.deployment.id,
state: state,
environment_url: deployUrl,
description: state === 'success' ? 'Preview deployed successfully' : 'Preview deployment failed'
});
} else {
console.log('No deployment ID found; skipping deployment status update.');
}