@@ -2,6 +2,11 @@ name: Build Project [using jupyter-book]
22on :
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
510jobs :
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