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 a65d0cd..1f1bba2 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -1,9 +1,17 @@ -name: Pull Request Build Check +name: Pull Request Build Check & Preview on: pull_request: branches: [ production, main, master ] +# 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: runs-on: ubuntu-latest @@ -15,16 +23,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 @@ -34,6 +48,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 }} @@ -42,4 +61,84 @@ 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 + with: + # Ensure we have access to the PR context + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + 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 + + - name: Build website for preview + run: | + 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 }} + + - 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 }} + + - 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 = `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({ + 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...'); + } \ No newline at end of file