Skip to content

Commit 910ebac

Browse files
fix preview build
Signed-off-by: saurabhraghuvanshii <saurabhsraghuvanshi@gmail.com>
1 parent 44d4bfe commit 910ebac

File tree

4 files changed

+273
-216
lines changed

4 files changed

+273
-216
lines changed

.github/workflows/build-and-preview-site.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,28 @@ jobs:
4141
if: github.event.action != 'closed'
4242
run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true"
4343

44+
- name: Resolve preview URLs
45+
if: github.event.action != 'closed'
46+
id: preview-vars
47+
env:
48+
PREVIEW_SITE_URL: ${{ vars.PREVIEW_SITE_URL }}
49+
run: |
50+
repo_name="${GITHUB_REPOSITORY#*/}"
51+
base_url="${PREVIEW_SITE_URL:-https://${GITHUB_REPOSITORY_OWNER}.github.io/${repo_name}}"
52+
base_url="${base_url%/}"
53+
path_prefix="/pr-preview/pr-${{ github.event.pull_request.number }}"
54+
55+
echo "base_url=${base_url}" >> "$GITHUB_OUTPUT"
56+
echo "path_prefix=${path_prefix}" >> "$GITHUB_OUTPUT"
57+
4458
- name: Build PR preview
4559
if: github.event.action != 'closed'
60+
env:
61+
GATSBY_PREVIEW: "true"
62+
GATSBY_SITE_URL: ${{ steps.preview-vars.outputs.base_url }}
63+
PATH_PREFIX: ${{ steps.preview-vars.outputs.path_prefix }}
4664
run: |
47-
npm run build
65+
npm run build:preview
4866
4967
# Block all crawlers from indexing PR previews.
5068
cat > public/robots.txt <<'EOF'
@@ -72,7 +90,7 @@ jobs:
7290
message: |
7391
🚀 **Preview deployment for PR #${{ github.event.pull_request.number }}**
7492
75-
🌐 **Preview URL**: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.pull_request.number }}/
93+
🌐 **Preview URL**: ${{ steps.preview-vars.outputs.base_url }}/pr-preview/pr-${{ github.event.pull_request.number }}/
7694
7795
_This preview will be updated automatically when you push new commits to this PR._
7896

0 commit comments

Comments
 (0)