Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
18bb586
Initial plan
Copilot Sep 9, 2025
a756d9d
Add node_modules and package-lock.json to .gitignore
Copilot Sep 9, 2025
9e45559
Replace nwtgck/actions-netlify@v3 with netlify-cli in CI workflow
Copilot Sep 9, 2025
1b82b7d
Update collab.yml workflow to use netlify-cli for consistency
Copilot Sep 9, 2025
c599088
Remove Netlify preview deployment from collab.yml workflow
Copilot Sep 9, 2025
b5b588e
Fix npm command not found error by installing Node.js via conda
Copilot Sep 9, 2025
3d779d6
Merge branch 'main' into copilot/adjust-ci-to-use-netlify-cli
mmcky Sep 9, 2025
eab5331
Use apt to install Node.js and npm instead of conda-forge
Copilot Sep 9, 2025
e849ac8
Fix npm global install permissions by adding sudo to netlify-cli inst…
Copilot Sep 9, 2025
3c82602
Use Netlify's default deploy-preview URL structure by removing custom…
Copilot Sep 9, 2025
0d40ee5
Add direct page preview functionality to Netlify deployments
Copilot Sep 9, 2025
c2d6079
Add automatic PR comment posting for preview links
Copilot Sep 9, 2025
31dfce9
Fix Netlify preview URLs by using actual deploy_url from JSON response
Copilot Sep 10, 2025
ac4de70
Fix duplicate PR comments by updating existing Netlify preview commen…
Copilot Sep 10, 2025
b75a64d
Fix PR preview URLs to use deploy-preview format by adding alias para…
Copilot Sep 10, 2025
a9c273b
Revert to creating new PR comments per commit instead of updating exi…
Copilot Sep 10, 2025
f9d666f
tst: add test change to aiyagari
mmcky Sep 10, 2025
8551d26
Fix git diff revision range error by adding fetch-depth: 0 to checkou…
Copilot Sep 10, 2025
c375d02
tst: another change
mmcky Sep 10, 2025
b9dce47
Merge branch 'copilot/adjust-ci-to-use-netlify-cli' of https://github…
mmcky Sep 10, 2025
f46f0c9
Make PR comment format more compact per feedback
Copilot Sep 10, 2025
6980883
tst: revert test changes
mmcky Sep 10, 2025
4a05647
Fix false positive change detection for lecture files
Copilot Sep 10, 2025
f0b3207
Fix false positive change detection and duplicate PR comments issues
Copilot Sep 10, 2025
b5dedf7
Revert unintentional changes to lectures/mle.md file
Copilot Sep 10, 2025
a2c83f4
Revert modifications to lectures/mle.md from commit b5dedf7
Copilot Sep 10, 2025
2285e16
Merge branch 'main' into copilot/adjust-ci-to-use-netlify-cli
mmcky Sep 10, 2025
289bdd4
Fix commit SHA mismatch in Netlify PR comments by using pull_request.…
Copilot Sep 10, 2025
ba28d05
Merge branch 'main' into copilot/adjust-ci-to-use-netlify-cli
mmcky Sep 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
261 changes: 255 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
name: Build Project [using jupyter-book]
on:
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:
inputs:
preview_page:
description: 'Specific page to preview (e.g., aiyagari.html)'
required: false
type: string
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 }}
fetch-depth: 0
- name: Setup Anaconda
uses: conda-incubator/setup-miniconda@v3
with:
Expand Down Expand Up @@ -78,13 +85,255 @@ jobs:
with:
name: execution-reports
path: _build/html/reports
- name: Install Node.js and Netlify CLI
shell: bash -l {0}
run: |
# Install Node.js via system package manager since conda-forge doesn't have npm
sudo apt-get update
sudo apt-get install -y nodejs npm
sudo npm install -g netlify-cli
- name: Detect Changed Lecture Files
id: detect-changes
shell: bash -l {0}
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
echo "Detecting changed lecture files..."
echo "Base SHA: ${{ github.event.pull_request.base.sha }}"
echo "Head SHA: ${{ github.event.pull_request.head.sha }}"

# Ensure we have both base and head commits available
git fetch origin ${{ github.event.pull_request.base.sha }}:refs/remotes/origin/pr-base || true
git fetch origin ${{ github.event.pull_request.head.sha }}:refs/remotes/origin/pr-head || true

# Get changed files using git diff with status to see the type of change
echo "Getting diff between commits..."
all_changed=$(git diff --name-status ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} 2>/dev/null || echo "")

if [ -z "$all_changed" ]; then
echo "No changes detected or error in git diff"
echo "changed_files=" >> $GITHUB_OUTPUT
exit 0
fi

echo "All changed files with status:"
echo "$all_changed"

# Filter for lecture files that are Added or Modified (not Deleted)
# Format: M lectures/file.md or A lectures/file.md
changed_lecture_files=""
while IFS=$'\t' read -r status file; do
# Skip if empty line
[ -z "$status" ] && continue

echo "Processing: status='$status' file='$file'"

# Only include Added (A) or Modified (M) files, skip Deleted (D)
if [[ "$status" =~ ^[AM] ]] && [[ "$file" =~ ^lectures/.*\.md$ ]] && [[ ! "$file" =~ ^lectures/_ ]] && [[ "$file" != "lectures/intro.md" ]]; then
# Double-check that the file exists and has real content changes
if [ -f "$file" ]; then
# Use git show to check if there are actual content changes (not just metadata)
content_diff=$(git diff ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} -- "$file" | grep -E '^[+-]' | grep -v '^[+-]{3}' | wc -l)
if [ "$content_diff" -gt 0 ]; then
echo "✓ Confirmed content changes in: $file"
if [ -z "$changed_lecture_files" ]; then
changed_lecture_files="$file"
else
changed_lecture_files="$changed_lecture_files"$'\n'"$file"
fi
else
echo "⚠ No content changes found in: $file (possibly metadata only)"
fi
else
echo "⚠ File not found in working directory: $file"
fi
else
echo "⚠ Skipping: $file (status: $status, doesn't match lecture file pattern or is excluded)"
fi
done <<< "$all_changed"

if [ ! -z "$changed_lecture_files" ]; then
echo ""
echo "Final validated changed lecture files:"
echo "$changed_lecture_files"
echo "changed_files<<EOF" >> $GITHUB_OUTPUT
echo "$changed_lecture_files" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
else
echo "No lecture files with actual content changes found"
echo "changed_files=" >> $GITHUB_OUTPUT
fi
else
echo "Not a PR, skipping change detection"
echo "changed_files=" >> $GITHUB_OUTPUT
fi
- name: Preview Deploy to Netlify
uses: nwtgck/actions-netlify@v3
with:
publish-dir: '_build/html/'
production-branch: main
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy-message: "Preview Deploy from GitHub Actions"
id: netlify-deploy
shell: bash -l {0}
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
# Deploy to Netlify and capture the response
deploy_message="Preview Deploy from GitHub Actions PR #${{ github.event.pull_request.number }} (commit: ${{ github.event.pull_request.head.sha }})"

netlify_output=$(netlify deploy \
--dir _build/html/ \
--site ${{ secrets.NETLIFY_SITE_ID }} \
--auth ${{ secrets.NETLIFY_AUTH_TOKEN }} \
--context deploy-preview \
--alias deploy-preview-${{ github.event.pull_request.number }} \
--message "${deploy_message}" \
--json)

echo "Netlify deployment output:"
echo "$netlify_output"

# Extract the actual deploy URL from the JSON response
deploy_url=$(echo "$netlify_output" | jq -r '.deploy_url')

echo "deploy_url=$deploy_url" >> $GITHUB_OUTPUT
echo "✅ Deployment completed!"
echo "🌐 Actual Deploy URL: $deploy_url"

# Generate preview URLs for changed files using the actual deploy URL
if [ ! -z "${{ steps.detect-changes.outputs.changed_files }}" ]; then
echo ""
echo "📚 Direct links to changed lecture pages:"
while read -r file; do
if [ ! -z "$file" ]; then
basename=$(basename "$file" .md)
html_file="${basename}.html"
echo "- ${basename}: ${deploy_url}/${html_file}"
fi
done <<< "${{ steps.detect-changes.outputs.changed_files }}"
fi

# Display manual preview page if specified
if [ ! -z "${{ github.event.inputs.preview_page }}" ]; then
echo ""
echo "🎯 Manual preview page: ${deploy_url}/${{ github.event.inputs.preview_page }}"
fi
else
# Handle manual deployment
deploy_message="Manual Deploy from GitHub Actions (commit: ${{ github.sha }})"

netlify_output=$(netlify deploy \
--dir _build/html/ \
--site ${{ secrets.NETLIFY_SITE_ID }} \
--auth ${{ secrets.NETLIFY_AUTH_TOKEN }} \
--alias manual-${{ github.run_id }} \
--context dev \
--message "${deploy_message}" \
--json)

echo "Netlify deployment output:"
echo "$netlify_output"

# Extract the actual deploy URL from the JSON response
deploy_url=$(echo "$netlify_output" | jq -r '.deploy_url')

echo "deploy_url=$deploy_url" >> $GITHUB_OUTPUT
echo "✅ Manual deployment completed!"
echo "🌐 Actual Deploy URL: $deploy_url"

if [ ! -z "${{ github.event.inputs.preview_page }}" ]; then
echo "🎯 Preview page: ${deploy_url}/${{ github.event.inputs.preview_page }}"
fi
fi
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
- name: Post PR Comment with Preview Links
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const changedFiles = `${{ steps.detect-changes.outputs.changed_files }}`;
const manualPage = `${{ github.event.inputs.preview_page }}`;
const deployUrl = `${{ steps.netlify-deploy.outputs.deploy_url }}`;
const prNumber = ${{ github.event.pull_request.number }};
const commitSha = `${{ github.event.pull_request.head.sha }}`;
const shortSha = commitSha.substring(0, 7);

console.log(`Checking for existing comments for commit: ${commitSha}`);
console.log(`Deploy URL: ${deployUrl}`);
console.log(`Changed files: ${changedFiles}`);

// Get all comments on this PR to check for duplicates
const comments = await github.rest.issues.listComments({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
});

console.log(`Found ${comments.data.length} comments on PR`);

// Look for existing comment with this exact commit SHA and deploy URL
const duplicateComment = comments.data.find(comment => {
const hasMarker = comment.body.includes('**📖 Netlify Preview Ready!**');
const hasCommitSha = comment.body.includes(`([${shortSha}]`);
const hasDeployUrl = comment.body.includes(deployUrl);

console.log(`Comment ${comment.id}: hasMarker=${hasMarker}, hasCommitSha=${hasCommitSha}, hasDeployUrl=${hasDeployUrl}`);

return hasMarker && hasCommitSha && hasDeployUrl;
});

if (duplicateComment) {
console.log(`Duplicate comment found (${duplicateComment.id}) for commit ${shortSha} and deploy URL ${deployUrl}, skipping...`);
return;
}

console.log(`No duplicate found, creating new comment for commit ${shortSha}`);

const commitUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${commitSha}`;

let comment = `**📖 Netlify Preview Ready!**\n\n`;
comment += `**Preview URL:** ${deployUrl} ([${shortSha}](${commitUrl}))\n\n`;

// Add manual preview page if specified
if (manualPage) {
comment += `🎯 **Manual Preview:** [${manualPage}](${deployUrl}/${manualPage})\n\n`;
}

// Add direct links to changed lecture pages
if (changedFiles && changedFiles.trim()) {
console.log('Processing changed files for preview links...');
const files = changedFiles.split('\n').filter(f => f.trim() && f.includes('lectures/') && f.endsWith('.md'));
console.log('Filtered lecture files:', files);

if (files.length > 0) {
comment += `📚 **Changed Lecture Pages:** `;

const pageLinks = [];
for (const file of files) {
const cleanFile = file.trim();
if (cleanFile && cleanFile.startsWith('lectures/') && cleanFile.endsWith('.md')) {
const fileName = cleanFile.replace('lectures/', '').replace('.md', '');
console.log(`Creating preview link: ${cleanFile} -> ${fileName}.html`);
const pageUrl = `${deployUrl}/${fileName}.html`;
pageLinks.push(`[${fileName}](${pageUrl})`);
}
}

if (pageLinks.length > 0) {
comment += pageLinks.join(', ') + '\n\n';
} else {
console.log('No valid page links created');
}
} else {
console.log('No lecture files in changed files list');
}
} else {
console.log('No changed files detected');
}

console.log('Final comment:', comment);

// Post the comment
await github.rest.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});

console.log('Comment posted successfully');
10 changes: 0 additions & 10 deletions .github/workflows/collab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,3 @@ jobs:
title: "Weekly Colab Execution Check Failed - ${{ github.run_id }}"
content-filepath: execution-failure-report.md
labels: execution-failure, automated-issue, colab
- name: Preview Deploy to Netlify
uses: nwtgck/actions-netlify@v3
with:
publish-dir: '_build/html/'
production-branch: main
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy-message: "Preview Deploy from GitHub Actions"
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
_build/
lectures/_build/
.ipynb_checkpoints/
.virtual_documents/
.virtual_documents/
node_modules/
package-lock.json
Loading