Skip to content

Commit 0d40ee5

Browse files
Copilotmmcky
andcommitted
Add direct page preview functionality to Netlify deployments
- Add workflow input to manually specify preview page (e.g., aiyagari.html) - Auto-detect changed lecture files and generate direct preview URLs - Include direct links in deployment messages and action output - Support both PR and manual deployment workflows Co-authored-by: mmcky <8263752+mmcky@users.noreply.github.com>
1 parent 3c82602 commit 0d40ee5

File tree

1 file changed

+91
-2
lines changed

1 file changed

+91
-2
lines changed

.github/workflows/ci.yml

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ name: Build Project [using jupyter-book]
22
on:
33
pull_request:
44
workflow_dispatch:
5+
inputs:
6+
preview_page:
7+
description: 'Specific page to preview (e.g., aiyagari.html)'
8+
required: false
9+
type: string
510
jobs:
611
preview:
712
runs-on: "runs-on=${{ github.run_id }}/family=g4dn.2xlarge/image=quantecon_ubuntu2404/disk=large"
@@ -85,26 +90,110 @@ jobs:
8590
sudo apt-get update
8691
sudo apt-get install -y nodejs npm
8792
sudo npm install -g netlify-cli
93+
- name: Detect Changed Lecture Files
94+
id: detect-changes
95+
shell: bash -l {0}
96+
run: |
97+
if [ "${{ github.event_name }}" = "pull_request" ]; then
98+
echo "Detecting changed lecture files..."
99+
100+
# Get changed files in the lectures directory
101+
changed_files=$(git diff --name-only ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} | grep '^lectures/.*\.md$' | grep -v '^lectures/_' || true)
102+
103+
if [ ! -z "$changed_files" ]; then
104+
echo "Changed lecture files:"
105+
echo "$changed_files"
106+
107+
# Convert .md files to .html and create preview URLs
108+
preview_urls=""
109+
for file in $changed_files; do
110+
# Extract filename without path and extension
111+
basename=$(basename "$file" .md)
112+
html_file="${basename}.html"
113+
preview_urls="${preview_urls}https://deploy-preview-${{ github.event.pull_request.number }}--sunny-cactus-210e3e.netlify.app/${html_file}\n"
114+
done
115+
116+
echo "preview_urls<<EOF" >> $GITHUB_OUTPUT
117+
echo -e "$preview_urls" >> $GITHUB_OUTPUT
118+
echo "EOF" >> $GITHUB_OUTPUT
119+
120+
echo "changed_files<<EOF" >> $GITHUB_OUTPUT
121+
echo "$changed_files" >> $GITHUB_OUTPUT
122+
echo "EOF" >> $GITHUB_OUTPUT
123+
else
124+
echo "No lecture files changed"
125+
echo "preview_urls=" >> $GITHUB_OUTPUT
126+
echo "changed_files=" >> $GITHUB_OUTPUT
127+
fi
128+
else
129+
echo "Not a PR, skipping change detection"
130+
echo "preview_urls=" >> $GITHUB_OUTPUT
131+
echo "changed_files=" >> $GITHUB_OUTPUT
132+
fi
88133
- name: Preview Deploy to Netlify
89134
shell: bash -l {0}
90135
run: |
91136
if [ "${{ github.event_name }}" = "pull_request" ]; then
137+
# Construct deployment message with preview URLs
138+
deploy_message="Preview Deploy from GitHub Actions PR #${{ github.event.pull_request.number }} (commit: ${{ github.sha }})"
139+
140+
# Add manual preview page if specified
141+
if [ ! -z "${{ github.event.inputs.preview_page }}" ]; then
142+
deploy_message="${deploy_message}\n\n🎯 Manual Preview Page: https://deploy-preview-${{ github.event.pull_request.number }}--sunny-cactus-210e3e.netlify.app/${{ github.event.inputs.preview_page }}"
143+
fi
144+
145+
# Add changed lecture pages
146+
if [ ! -z "${{ steps.detect-changes.outputs.changed_files }}" ]; then
147+
deploy_message="${deploy_message}\n\n📚 Changed Lecture Pages:"
148+
deploy_message="${deploy_message}\n${{ steps.detect-changes.outputs.preview_urls }}"
149+
fi
150+
92151
netlify deploy \
93152
--dir _build/html/ \
94153
--site ${{ secrets.NETLIFY_SITE_ID }} \
95154
--auth ${{ secrets.NETLIFY_AUTH_TOKEN }} \
96155
--context deploy-preview \
97-
--message "Preview Deploy from GitHub Actions PR #${{ github.event.pull_request.number }} (commit: ${{ github.sha }})" \
156+
--message "${deploy_message}" \
98157
--json
158+
159+
echo "✅ Deployment completed!"
160+
echo "🌐 Preview URL: https://deploy-preview-${{ github.event.pull_request.number }}--sunny-cactus-210e3e.netlify.app/"
161+
162+
# Display preview URLs for changed files
163+
if [ ! -z "${{ steps.detect-changes.outputs.preview_urls }}" ]; then
164+
echo ""
165+
echo "📚 Direct links to changed lecture pages:"
166+
echo -e "${{ steps.detect-changes.outputs.preview_urls }}"
167+
fi
168+
169+
# Display manual preview page if specified
170+
if [ ! -z "${{ github.event.inputs.preview_page }}" ]; then
171+
echo ""
172+
echo "🎯 Manual preview page: https://deploy-preview-${{ github.event.pull_request.number }}--sunny-cactus-210e3e.netlify.app/${{ github.event.inputs.preview_page }}"
173+
fi
99174
else
175+
# Handle manual deployment
176+
deploy_message="Manual Deploy from GitHub Actions (commit: ${{ github.sha }})"
177+
178+
if [ ! -z "${{ github.event.inputs.preview_page }}" ]; then
179+
deploy_message="${deploy_message}\n\n🎯 Preview Page: https://manual-${{ github.run_id }}--sunny-cactus-210e3e.netlify.app/${{ github.event.inputs.preview_page }}"
180+
fi
181+
100182
netlify deploy \
101183
--dir _build/html/ \
102184
--site ${{ secrets.NETLIFY_SITE_ID }} \
103185
--auth ${{ secrets.NETLIFY_AUTH_TOKEN }} \
104186
--alias manual-${{ github.run_id }} \
105187
--context dev \
106-
--message "Manual Deploy from GitHub Actions (commit: ${{ github.sha }})" \
188+
--message "${deploy_message}" \
107189
--json
190+
191+
echo "✅ Manual deployment completed!"
192+
echo "🌐 Preview URL: https://manual-${{ github.run_id }}--sunny-cactus-210e3e.netlify.app/"
193+
194+
if [ ! -z "${{ github.event.inputs.preview_page }}" ]; then
195+
echo "🎯 Preview page: https://manual-${{ github.run_id }}--sunny-cactus-210e3e.netlify.app/${{ github.event.inputs.preview_page }}"
196+
fi
108197
fi
109198
env:
110199
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}

0 commit comments

Comments
 (0)