From 89faf683082ff942f163c8bec9c555e15db3b54c Mon Sep 17 00:00:00 2001 From: Steven Feng Date: Sun, 10 Aug 2025 23:40:40 -0700 Subject: [PATCH 1/9] preview deployment --- .github/workflows/pr-check.yml | 59 ++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index a65d0cd..8435b56 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -1,4 +1,4 @@ -name: Pull Request Build Check +name: Pull Request Build Check & Preview on: pull_request: @@ -42,4 +42,59 @@ jobs: run: | echo "āœ… Build completed successfully!" echo "šŸ“ Build output size: $(du -sh public | cut -f1)" - echo "šŸ“„ Number of pages built: $(find public -name "*.html" | wc -l)" \ No newline at end of file + echo "šŸ“„ Number of pages built: $(find public -name "*.html" | wc -l)" + + preview-deploy: + runs-on: ubuntu-latest + needs: build-check + if: github.event_name == 'pull_request' + + steps: + - name: Checkout source code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + cache: 'npm' + + - name: Install dependencies + run: npm install --legacy-peer-deps + + - name: Install native dependencies explicitly + run: | + npm install @parcel/watcher --legacy-peer-deps + npm rebuild @parcel/watcher + + - name: Clean Gatsby cache + run: npx gatsby clean + + - name: Build website for preview + run: | + export GATSBY_DISABLE_FILE_WATCHER=true + export GATSBY_DISABLE_WATCHER=true + export NODE_ENV=production + npm run build + env: + GATSBY_GA_MEASUREMENT_ID: ${{ secrets.GATSBY_GA_MEASUREMENT_ID }} + + - name: Deploy to preview branch + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./public + destination_dir: preview/pr-${{ github.event.number }} + force_orphan: true + + - name: Comment preview URL + uses: actions/github-script@v7 + with: + script: | + const previewUrl = `https://stevenf7.github.io/preview/pr-${context.event.number}/`; + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: `šŸŽ‰ **Preview Deployment Ready!**\n\nYour changes are now available for preview at:\nšŸ”— **${previewUrl}**\n\nThis preview will be automatically cleaned up when the PR is closed or merged.` + }); \ No newline at end of file From 4acc51607aeeebde451ae46026026b3daacb9cff Mon Sep 17 00:00:00 2001 From: Steven Feng Date: Sun, 10 Aug 2025 23:52:30 -0700 Subject: [PATCH 2/9] fix config --- .github/workflows/pr-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 8435b56..81aa4aa 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -91,7 +91,7 @@ jobs: uses: actions/github-script@v7 with: script: | - const previewUrl = `https://stevenf7.github.io/preview/pr-${context.event.number}/`; + const previewUrl = `https://stevenf7.github.io/preview/pr-${context.issue.number}/`; github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, From 5abae2b11f1eaf293b7b29011c9133f4c9c9b4b3 Mon Sep 17 00:00:00 2001 From: "Ji Yuan \"Steven\" Feng" <34409734+stevenf7@users.noreply.github.com> Date: Sat, 16 Aug 2025 09:38:36 -0700 Subject: [PATCH 3/9] Update .github/workflows/pr-check.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/workflows/pr-check.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 81aa4aa..b8cda07 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -85,7 +85,6 @@ jobs: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./public destination_dir: preview/pr-${{ github.event.number }} - force_orphan: true - name: Comment preview URL uses: actions/github-script@v7 From d541e1c1d12681b640dd6684840bed1d4c15f647 Mon Sep 17 00:00:00 2001 From: "Ji Yuan \"Steven\" Feng" <34409734+stevenf7@users.noreply.github.com> Date: Sat, 16 Aug 2025 09:38:48 -0700 Subject: [PATCH 4/9] Update .github/workflows/pr-check.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/workflows/pr-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index b8cda07..9776412 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -90,7 +90,7 @@ jobs: uses: actions/github-script@v7 with: script: | - const previewUrl = `https://stevenf7.github.io/preview/pr-${context.issue.number}/`; + const previewUrl = `https://${context.repo.owner}.github.io/preview/pr-${context.issue.number}/`; github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, From 7db964e75d2bd9b068f37845477be0477e063b41 Mon Sep 17 00:00:00 2001 From: "Ji Yuan \"Steven\" Feng" <34409734+stevenf7@users.noreply.github.com> Date: Sat, 16 Aug 2025 09:39:08 -0700 Subject: [PATCH 5/9] Update .github/workflows/pr-check.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/workflows/pr-check.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 9776412..1498dce 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -62,11 +62,6 @@ jobs: - name: Install dependencies run: npm install --legacy-peer-deps - - name: Install native dependencies explicitly - run: | - npm install @parcel/watcher --legacy-peer-deps - npm rebuild @parcel/watcher - - name: Clean Gatsby cache run: npx gatsby clean From 65aca75acb02f347d253c1ea6bfc9fb05fe5bde6 Mon Sep 17 00:00:00 2001 From: Steven Feng Date: Sat, 16 Aug 2025 13:14:05 -0700 Subject: [PATCH 6/9] write permission --- .github/workflows/pr-check.yml | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 1498dce..d572724 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -4,6 +4,12 @@ on: pull_request: branches: [ production, main, master ] +# Add permissions for GitHub Pages +permissions: + contents: read + pages: write + id-token: write + jobs: build-check: runs-on: ubuntu-latest @@ -48,6 +54,9 @@ jobs: runs-on: ubuntu-latest needs: build-check if: github.event_name == 'pull_request' + environment: + name: preview + url: ${{ steps.deployment.outputs.page_url }} steps: - name: Checkout source code @@ -74,18 +83,25 @@ jobs: env: GATSBY_GA_MEASUREMENT_ID: ${{ secrets.GATSBY_GA_MEASUREMENT_ID }} - - name: Deploy to preview branch - uses: peaceiris/actions-gh-pages@v3 + - name: Setup Pages + uses: actions/configure-pages@v4 + + - name: Upload preview artifact + uses: actions/upload-pages-artifact@v3 + with: + path: './public' + + - name: Deploy preview + id: deployment + uses: actions/deploy-pages@v4 with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./public - destination_dir: preview/pr-${{ github.event.number }} + environment_name: preview - name: Comment preview URL uses: actions/github-script@v7 with: script: | - const previewUrl = `https://${context.repo.owner}.github.io/preview/pr-${context.issue.number}/`; + const previewUrl = `${{ steps.deployment.outputs.page_url }}`; github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, From c35c246615b3717d0ed5dd5b8df3ab163a499f79 Mon Sep 17 00:00:00 2001 From: Steven Feng Date: Sat, 16 Aug 2025 13:21:59 -0700 Subject: [PATCH 7/9] update github config --- .github/workflows/deploy.yml | 38 +++++++++++++++++++++++++++------- .github/workflows/pr-check.yml | 37 ++++++++++++++++++++++++++++----- 2 files changed, 62 insertions(+), 13 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index dce1c6b..2178c54 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -31,16 +31,22 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '18' + node-version: '20' # Use Node 20 for better native dependency support cache: 'npm' - name: Install dependencies run: npm install --legacy-peer-deps - - name: Install native dependencies explicitly + - name: Handle native dependencies run: | - npm install @parcel/watcher --legacy-peer-deps - npm rebuild @parcel/watcher + # Try to install @parcel/watcher, but don't fail if it doesn't work + npm install @parcel/watcher --legacy-peer-deps || echo "Warning: @parcel/watcher installation failed, continuing..." + # If installation succeeded, try to rebuild + if npm list @parcel/watcher > /dev/null 2>&1; then + npm rebuild @parcel/watcher || echo "Warning: @parcel/watcher rebuild failed, continuing..." + fi + # Alternative: try to install platform-specific version + npm install @parcel/watcher-linux-x64-glibc --legacy-peer-deps || echo "Warning: Linux-specific watcher installation failed, continuing..." - name: Clean Gatsby cache run: npx gatsby clean @@ -50,6 +56,11 @@ jobs: export GATSBY_DISABLE_FILE_WATCHER=true export GATSBY_DISABLE_WATCHER=true export NODE_ENV=production + # Set additional environment variables to avoid watcher issues + export GATSBY_EXPERIMENTAL_DEV_SSR=false + export GATSBY_EXPERIMENTAL_FAST_DEV=false + # Try to disable any remaining watcher functionality + export GATSBY_DISABLE_ESLINT_PLUGIN=true npm run build env: GATSBY_GA_MEASUREMENT_ID: ${{ secrets.GATSBY_GA_MEASUREMENT_ID }} @@ -69,16 +80,22 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '18' # Use Node 18 for better compatibility + node-version: '20' # Use Node 20 for better native dependency support cache: 'npm' - name: Install dependencies run: npm install --legacy-peer-deps - - name: Install native dependencies explicitly + - name: Handle native dependencies run: | - npm install @parcel/watcher --legacy-peer-deps - npm rebuild @parcel/watcher + # Try to install @parcel/watcher, but don't fail if it doesn't work + npm install @parcel/watcher --legacy-peer-deps || echo "Warning: @parcel/watcher installation failed, continuing..." + # If installation succeeded, try to rebuild + if npm list @parcel/watcher > /dev/null 2>&1; then + npm rebuild @parcel/watcher || echo "Warning: @parcel/watcher rebuild failed, continuing..." + fi + # Alternative: try to install platform-specific version + npm install @parcel/watcher-linux-x64-glibc --legacy-peer-deps || echo "Warning: Linux-specific watcher installation failed, continuing..." - name: Clean Gatsby cache run: npx gatsby clean @@ -88,6 +105,11 @@ jobs: export GATSBY_DISABLE_FILE_WATCHER=true export GATSBY_DISABLE_WATCHER=true export NODE_ENV=production + # Set additional environment variables to avoid watcher issues + export GATSBY_EXPERIMENTAL_DEV_SSR=false + export GATSBY_EXPERIMENTAL_FAST_DEV=false + # Try to disable any remaining watcher functionality + export GATSBY_DISABLE_ESLINT_PLUGIN=true npm run build env: GATSBY_GA_MEASUREMENT_ID: ${{ secrets.GATSBY_GA_MEASUREMENT_ID }} diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index d572724..2a16985 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -21,16 +21,22 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '18' + node-version: '20' # Use Node 20 for better native dependency support cache: 'npm' - name: Install dependencies run: npm install --legacy-peer-deps - - name: Install native dependencies explicitly + - name: Handle native dependencies run: | - npm install @parcel/watcher --legacy-peer-deps - npm rebuild @parcel/watcher + # Try to install @parcel/watcher, but don't fail if it doesn't work + npm install @parcel/watcher --legacy-peer-deps || echo "Warning: @parcel/watcher installation failed, continuing..." + # If installation succeeded, try to rebuild + if npm list @parcel/watcher > /dev/null 2>&1; then + npm rebuild @parcel/watcher || echo "Warning: @parcel/watcher rebuild failed, continuing..." + fi + # Alternative: try to install platform-specific version + npm install @parcel/watcher-linux-x64-glibc --legacy-peer-deps || echo "Warning: Linux-specific watcher installation failed, continuing..." - name: Clean Gatsby cache run: npx gatsby clean @@ -40,6 +46,11 @@ jobs: export GATSBY_DISABLE_FILE_WATCHER=true export GATSBY_DISABLE_WATCHER=true export NODE_ENV=production + # Set additional environment variables to avoid watcher issues + export GATSBY_EXPERIMENTAL_DEV_SSR=false + export GATSBY_EXPERIMENTAL_FAST_DEV=false + # Try to disable any remaining watcher functionality + export GATSBY_DISABLE_ESLINT_PLUGIN=true npm run build env: GATSBY_GA_MEASUREMENT_ID: ${{ secrets.GATSBY_GA_MEASUREMENT_ID }} @@ -65,12 +76,23 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '18' + node-version: '20' # Use Node 20 for better native dependency support cache: 'npm' - name: Install dependencies run: npm install --legacy-peer-deps + - name: Handle native dependencies + run: | + # Try to install @parcel/watcher, but don't fail if it doesn't work + npm install @parcel/watcher --legacy-peer-deps || echo "Warning: @parcel/watcher installation failed, continuing..." + # If installation succeeded, try to rebuild + if npm list @parcel/watcher > /dev/null 2>&1; then + npm rebuild @parcel/watcher || echo "Warning: @parcel/watcher rebuild failed, continuing..." + fi + # Alternative: try to install platform-specific version + npm install @parcel/watcher-linux-x64-glibc --legacy-peer-deps || echo "Warning: Linux-specific watcher installation failed, continuing..." + - name: Clean Gatsby cache run: npx gatsby clean @@ -79,6 +101,11 @@ jobs: export GATSBY_DISABLE_FILE_WATCHER=true export GATSBY_DISABLE_WATCHER=true export NODE_ENV=production + # Set additional environment variables to avoid watcher issues + export GATSBY_EXPERIMENTAL_DEV_SSR=false + export GATSBY_EXPERIMENTAL_FAST_DEV=false + # Try to disable any remaining watcher functionality + export GATSBY_DISABLE_ESLINT_PLUGIN=true npm run build env: GATSBY_GA_MEASUREMENT_ID: ${{ secrets.GATSBY_GA_MEASUREMENT_ID }} From 43e00f2a41530548f9ad77ffa48176343a6d28c0 Mon Sep 17 00:00:00 2001 From: Steven Feng Date: Sat, 16 Aug 2025 13:30:05 -0700 Subject: [PATCH 8/9] update preview to give write --- .github/workflows/pr-check.yml | 48 +++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 2a16985..6dcce9f 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -4,11 +4,13 @@ on: pull_request: branches: [ production, main, master ] -# Add permissions for GitHub Pages +# Add permissions for GitHub Pages and PR commenting permissions: contents: read pages: write id-token: write + pull-requests: write # Add permission to comment on PRs + issues: write # Add permission to comment on issues jobs: build-check: @@ -72,6 +74,9 @@ jobs: steps: - name: Checkout source code uses: actions/checkout@v4 + with: + # Ensure we have access to the PR context + token: ${{ secrets.GITHUB_TOKEN }} - name: Setup Node.js uses: actions/setup-node@v4 @@ -124,14 +129,39 @@ jobs: with: environment_name: preview - - name: Comment preview URL + - name: Comment preview URL (Primary Method) uses: actions/github-script@v7 with: + # Ensure we have the right permissions + github-token: ${{ secrets.GITHUB_TOKEN }} script: | - const previewUrl = `${{ steps.deployment.outputs.page_url }}`; - github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: `šŸŽ‰ **Preview Deployment Ready!**\n\nYour changes are now available for preview at:\nšŸ”— **${previewUrl}**\n\nThis preview will be automatically cleaned up when the PR is closed or merged.` - }); \ No newline at end of file + try { + const previewUrl = `${{ steps.deployment.outputs.page_url }}`; + console.log(`Attempting to comment with preview URL: ${previewUrl}`); + + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: `šŸŽ‰ **Preview Deployment Ready!**\n\nYour changes are now available for preview at:\nšŸ”— **${previewUrl}**\n\nThis preview will be automatically cleaned up when the PR is closed or merged.` + }); + + console.log('āœ… Comment added successfully!'); + } catch (error) { + console.error('āŒ Failed to add comment:', error.message); + // Don't fail the workflow if commenting fails + console.log('Continuing with deployment...'); + } + + - name: Comment preview URL (Fallback Method) + if: failure() && steps.deployment.outputs.page_url + run: | + echo "šŸŽ‰ **Preview Deployment Ready!**" > comment.md + echo "" >> comment.md + echo "Your changes are now available for preview at:" >> comment.md + echo "šŸ”— **${{ steps.deployment.outputs.page_url }}**" >> comment.md + echo "" >> comment.md + echo "This preview will be automatically cleaned up when the PR is closed or merged." >> comment.md + + # Try to use GitHub CLI as fallback + gh pr comment ${{ github.event.number }} --body-file comment.md || echo "Fallback commenting also failed, but deployment succeeded" \ No newline at end of file From 6a005d09356057f37ea197e405df403faebbc6b9 Mon Sep 17 00:00:00 2001 From: Steven Feng Date: Sat, 16 Aug 2025 13:42:23 -0700 Subject: [PATCH 9/9] update deployment path --- .github/workflows/pr-check.yml | 39 +++++++--------------------------- 1 file changed, 8 insertions(+), 31 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 6dcce9f..1f1bba2 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -67,9 +67,6 @@ jobs: runs-on: ubuntu-latest needs: build-check if: github.event_name == 'pull_request' - environment: - name: preview - url: ${{ steps.deployment.outputs.page_url }} steps: - name: Checkout source code @@ -115,28 +112,21 @@ jobs: env: GATSBY_GA_MEASUREMENT_ID: ${{ secrets.GATSBY_GA_MEASUREMENT_ID }} - - name: Setup Pages - uses: actions/configure-pages@v4 - - - name: Upload preview artifact - uses: actions/upload-pages-artifact@v3 - with: - path: './public' - - - name: Deploy preview - id: deployment - uses: actions/deploy-pages@v4 + - name: Deploy to preview branch + uses: peaceiris/actions-gh-pages@v3 with: - environment_name: preview + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./public + destination_dir: preview/pr-${{ github.event.number }} - - name: Comment preview URL (Primary Method) + - name: Comment preview URL uses: actions/github-script@v7 with: # Ensure we have the right permissions github-token: ${{ secrets.GITHUB_TOKEN }} script: | try { - const previewUrl = `${{ steps.deployment.outputs.page_url }}`; + const previewUrl = `https://${context.repo.owner}.github.io/${context.repo.repo}/preview/pr-${context.issue.number}/`; console.log(`Attempting to comment with preview URL: ${previewUrl}`); await github.rest.issues.createComment({ @@ -151,17 +141,4 @@ jobs: console.error('āŒ Failed to add comment:', error.message); // Don't fail the workflow if commenting fails console.log('Continuing with deployment...'); - } - - - name: Comment preview URL (Fallback Method) - if: failure() && steps.deployment.outputs.page_url - run: | - echo "šŸŽ‰ **Preview Deployment Ready!**" > comment.md - echo "" >> comment.md - echo "Your changes are now available for preview at:" >> comment.md - echo "šŸ”— **${{ steps.deployment.outputs.page_url }}**" >> comment.md - echo "" >> comment.md - echo "This preview will be automatically cleaned up when the PR is closed or merged." >> comment.md - - # Try to use GitHub CLI as fallback - gh pr comment ${{ github.event.number }} --body-file comment.md || echo "Fallback commenting also failed, but deployment succeeded" \ No newline at end of file + } \ No newline at end of file