@@ -98,17 +98,48 @@ jobs:
9898 run : |
9999 if [ "${{ github.event_name }}" = "pull_request" ]; then
100100 echo "Detecting changed lecture files..."
101+ echo "Base SHA: ${{ github.event.pull_request.base.sha }}"
102+ echo "Head SHA: ${{ github.event.pull_request.head.sha }}"
101103
102- # Get changed files in the lectures directory
103- 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)
104+ # Get changed files in the lectures directory with better validation
105+ all_changed=$(git diff --name-only ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} || true)
106+ echo "All changed files:"
107+ echo "$all_changed"
108+
109+ changed_files=$(echo "$all_changed" | grep '^lectures/.*\.md$' | grep -v '^lectures/_' | grep -v '^lectures/intro\.md$' || true)
104110
105111 if [ ! -z "$changed_files" ]; then
106- echo "Changed lecture files:"
112+ echo "Filtered lecture files:"
107113 echo "$changed_files"
108114
109- echo "changed_files<<EOF" >> $GITHUB_OUTPUT
110- echo "$changed_files" >> $GITHUB_OUTPUT
111- echo "EOF" >> $GITHUB_OUTPUT
115+ # Validate that these files actually exist and contain changes
116+ validated_files=""
117+ while IFS= read -r file; do
118+ if [ ! -z "$file" ] && [ -f "$file" ]; then
119+ # Check if the file actually has changes
120+ if git diff --quiet ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} -- "$file"; then
121+ echo "Warning: $file shows no actual changes, skipping"
122+ else
123+ echo "Confirmed changes in: $file"
124+ if [ -z "$validated_files" ]; then
125+ validated_files="$file"
126+ else
127+ validated_files="$validated_files"$'\n'"$file"
128+ fi
129+ fi
130+ fi
131+ done <<< "$changed_files"
132+
133+ if [ ! -z "$validated_files" ]; then
134+ echo "Final validated changed files:"
135+ echo "$validated_files"
136+ echo "changed_files<<EOF" >> $GITHUB_OUTPUT
137+ echo "$validated_files" >> $GITHUB_OUTPUT
138+ echo "EOF" >> $GITHUB_OUTPUT
139+ else
140+ echo "No lecture files with actual changes found"
141+ echo "changed_files=" >> $GITHUB_OUTPUT
142+ fi
112143 else
113144 echo "No lecture files changed"
114145 echo "changed_files=" >> $GITHUB_OUTPUT
@@ -232,20 +263,28 @@ jobs:
232263 }
233264
234265 // Add direct links to changed lecture pages
235- if (changedFiles) {
236- const files = changedFiles.split('\n').filter(f => f.trim());
266+ if (changedFiles && changedFiles.trim()) {
267+ console.log('Raw changedFiles:', JSON.stringify(changedFiles));
268+ const files = changedFiles.split('\n').filter(f => f.trim() && f.includes('lectures/') && f.endsWith('.md'));
269+ console.log('Filtered files:', files);
270+
237271 if (files.length > 0) {
238272 comment += `📚 **Changed Lecture Pages:** `;
239273
240274 const pageLinks = [];
241275 for (const file of files) {
242- if (file.trim()) {
243- const fileName = file.replace('lectures/', '').replace('.md', '');
276+ const cleanFile = file.trim();
277+ if (cleanFile && cleanFile.startsWith('lectures/') && cleanFile.endsWith('.md')) {
278+ const fileName = cleanFile.replace('lectures/', '').replace('.md', '');
279+ console.log(`Processing file: ${cleanFile} -> ${fileName}`);
244280 const pageUrl = `${deployUrl}/${fileName}.html`;
245281 pageLinks.push(`[${fileName}](${pageUrl})`);
246282 }
247283 }
248- comment += pageLinks.join(', ') + '\n\n';
284+
285+ if (pageLinks.length > 0) {
286+ comment += pageLinks.join(', ') + '\n\n';
287+ }
249288 }
250289 }
251290
0 commit comments