@@ -104,95 +104,86 @@ jobs:
104104 echo "Changed lecture files:"
105105 echo "$changed_files"
106106
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-
120107 echo "changed_files<<EOF" >> $GITHUB_OUTPUT
121108 echo "$changed_files" >> $GITHUB_OUTPUT
122109 echo "EOF" >> $GITHUB_OUTPUT
123110 else
124111 echo "No lecture files changed"
125- echo "preview_urls=" >> $GITHUB_OUTPUT
126112 echo "changed_files=" >> $GITHUB_OUTPUT
127113 fi
128114 else
129115 echo "Not a PR, skipping change detection"
130- echo "preview_urls=" >> $GITHUB_OUTPUT
131116 echo "changed_files=" >> $GITHUB_OUTPUT
132117 fi
133118 - name : Preview Deploy to Netlify
119+ id : netlify-deploy
134120 shell : bash -l {0}
135121 run : |
136122 if [ "${{ github.event_name }}" = "pull_request" ]; then
137- # Construct deployment message with preview URLs
123+ # Deploy to Netlify and capture the response
138124 deploy_message="Preview Deploy from GitHub Actions PR #${{ github.event.pull_request.number }} (commit: ${{ github.sha }})"
139125
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-
151- netlify deploy \
126+ netlify_output=$(netlify deploy \
152127 --dir _build/html/ \
153128 --site ${{ secrets.NETLIFY_SITE_ID }} \
154129 --auth ${{ secrets.NETLIFY_AUTH_TOKEN }} \
155130 --context deploy-preview \
156131 --message "${deploy_message}" \
157- --json
132+ --json)
158133
134+ echo "Netlify deployment output:"
135+ echo "$netlify_output"
136+
137+ # Extract the actual deploy URL from the JSON response
138+ deploy_url=$(echo "$netlify_output" | jq -r '.deploy_url')
139+
140+ echo "deploy_url=$deploy_url" >> $GITHUB_OUTPUT
159141 echo "✅ Deployment completed!"
160- echo "🌐 Preview URL: https://deploy-preview-${{ github.event.pull_request.number }}--sunny-cactus-210e3e.netlify.app/ "
142+ echo "🌐 Actual Deploy URL: $deploy_url "
161143
162- # Display preview URLs for changed files
163- if [ ! -z "${{ steps.detect-changes.outputs.preview_urls }}" ]; then
144+ # Generate preview URLs for changed files using the actual deploy URL
145+ if [ ! -z "${{ steps.detect-changes.outputs.changed_files }}" ]; then
164146 echo ""
165147 echo "📚 Direct links to changed lecture pages:"
166- echo -e "${{ steps.detect-changes.outputs.preview_urls }}"
148+ while read -r file; do
149+ if [ ! -z "$file" ]; then
150+ basename=$(basename "$file" .md)
151+ html_file="${basename}.html"
152+ echo "- ${basename}: ${deploy_url}/${html_file}"
153+ fi
154+ done <<< "${{ steps.detect-changes.outputs.changed_files }}"
167155 fi
168156
169157 # Display manual preview page if specified
170158 if [ ! -z "${{ github.event.inputs.preview_page }}" ]; then
171159 echo ""
172- echo "🎯 Manual preview page: https://deploy-preview-${{ github.event.pull_request.number }}--sunny-cactus-210e3e.netlify.app /${{ github.event.inputs.preview_page }}"
160+ echo "🎯 Manual preview page: ${deploy_url} /${{ github.event.inputs.preview_page }}"
173161 fi
174162 else
175163 # Handle manual deployment
176164 deploy_message="Manual Deploy from GitHub Actions (commit: ${{ github.sha }})"
177165
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-
182- netlify deploy \
166+ netlify_output=$(netlify deploy \
183167 --dir _build/html/ \
184168 --site ${{ secrets.NETLIFY_SITE_ID }} \
185169 --auth ${{ secrets.NETLIFY_AUTH_TOKEN }} \
186170 --alias manual-${{ github.run_id }} \
187171 --context dev \
188172 --message "${deploy_message}" \
189- --json
173+ --json)
190174
175+ echo "Netlify deployment output:"
176+ echo "$netlify_output"
177+
178+ # Extract the actual deploy URL from the JSON response
179+ deploy_url=$(echo "$netlify_output" | jq -r '.deploy_url')
180+
181+ echo "deploy_url=$deploy_url" >> $GITHUB_OUTPUT
191182 echo "✅ Manual deployment completed!"
192- echo "🌐 Preview URL: https://manual-${{ github.run_id }}--sunny-cactus-210e3e.netlify.app/ "
183+ echo "🌐 Actual Deploy URL: $deploy_url "
193184
194185 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 }}"
186+ echo "🎯 Preview page: ${deploy_url} /${{ github.event.inputs.preview_page }}"
196187 fi
197188 fi
198189 env :
@@ -204,30 +195,30 @@ jobs:
204195 with :
205196 script : |
206197 const changedFiles = `${{ steps.detect-changes.outputs.changed_files }}`;
207- const previewUrls = `${{ steps.detect-changes.outputs.preview_urls }}`;
208198 const manualPage = `${{ github.event.inputs.preview_page }}`;
199+ const deployUrl = `${{ steps.netlify-deploy.outputs.deploy_url }}`;
209200 const prNumber = ${{ github.event.pull_request.number }};
210- const baseUrl = `https://deploy-preview-${prNumber}--sunny-cactus-210e3e.netlify.app`;
211201
212202 let comment = `## 📖 Netlify Preview Ready!\n\n`;
213- comment += `**Preview URL:** ${baseUrl }\n\n`;
203+ comment += `**Preview URL:** ${deployUrl }\n\n`;
214204
215205 // Add manual preview page if specified
216206 if (manualPage) {
217- comment += `🎯 **Manual Preview:** [${manualPage}](${baseUrl }/${manualPage})\n\n`;
207+ comment += `🎯 **Manual Preview:** [${manualPage}](${deployUrl }/${manualPage})\n\n`;
218208 }
219209
220210 // Add direct links to changed lecture pages
221- if (changedFiles && previewUrls) {
222- comment += `📚 **Changed Lecture Pages:**\n`;
211+ if (changedFiles) {
223212 const files = changedFiles.split('\n').filter(f => f.trim());
224- const urls = previewUrls.split('\n').filter(u => u.trim());
225-
226- for (let i = 0; i < files.length && i < urls.length; i++) {
227- const fileName = files[i].replace('lectures/', '').replace('.md', '');
228- const url = urls[i].trim();
229- if (url) {
230- comment += `- [${fileName}](${url})\n`;
213+ if (files.length > 0) {
214+ comment += `📚 **Changed Lecture Pages:**\n`;
215+
216+ for (const file of files) {
217+ if (file.trim()) {
218+ const fileName = file.replace('lectures/', '').replace('.md', '');
219+ const pageUrl = `${deployUrl}/${fileName}.html`;
220+ comment += `- [${fileName}](${pageUrl})\n`;
221+ }
231222 }
232223 }
233224 }
0 commit comments