1- name : Build and Preview Site
1+ name : Build and Preview Gatsby Site
22
33on :
44 pull_request_target :
@@ -15,21 +15,20 @@ concurrency:
1515
1616jobs :
1717 build-and-deploy-preview :
18- runs-on : ubuntu-24.04
18+ runs-on : ubuntu-latest
19+
1920 steps :
2021 - name : Checkout PR
2122 if : github.event.action != 'closed'
22- uses : actions/checkout@v6
23+ uses : actions/checkout@v4
2324 with :
2425 ref : ${{ github.event.pull_request.head.sha }}
25- fetch-depth : 0
2626
27- - name : Checkout base branch for cleanup
27+ - name : Checkout for cleanup
2828 if : github.event.action == 'closed'
29- uses : actions/checkout@v6
29+ uses : actions/checkout@v4
3030 with :
31- ref : ${{ github.event.pull_request.base.ref }}
32- fetch-depth : 1
31+ ref : gh-pages
3332
3433 - name : Setup Node
3534 if : github.event.action != 'closed'
@@ -39,61 +38,18 @@ jobs:
3938
4039 - name : Install dependencies
4140 if : github.event.action != 'closed'
42- run : " [[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true"
43-
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- PUBLIC_SITE_URL : ${{ vars.PUBLIC_SITE_URL }}
50- run : |
51- owner="${GITHUB_REPOSITORY%%/*}"
52- repo_name="${GITHUB_REPOSITORY#*/}"
53- pr="pr-${{ github.event.pull_request.number }}"
54- base="${PREVIEW_SITE_URL:-${PUBLIC_SITE_URL:-}}"
55-
56- if [[ -n "$base" ]]; then
57- base="${base%/}"
58- pages_origin="$(printf '%s' "$base" | sed -E 's|(https?://[^/]+).*|\1|')"
59- base_path="$(printf '%s' "$base" | sed -E 's|https?://[^/]+||' | sed 's|^/||;s|/$||')"
60- if [[ -n "$base_path" ]]; then
61- path_prefix="${base_path}/pr-preview/${pr}"
62- preview_url="${pages_origin}/${base_path}/pr-preview/${pr}/"
63- else
64- path_prefix="pr-preview/${pr}"
65- preview_url="${pages_origin}/pr-preview/${pr}/"
66- fi
67- else
68- pages_origin="https://${owner}.github.io"
69- if [[ "$repo_name" == "${owner}.github.io" ]]; then
70- path_prefix="pr-preview/${pr}"
71- preview_url="${pages_origin}/pr-preview/${pr}/"
72- else
73- path_prefix="${repo_name}/pr-preview/${pr}"
74- preview_url="${pages_origin}/${repo_name}/pr-preview/${pr}/"
75- fi
76- fi
77-
78- echo "pages_origin=${pages_origin}" >> "$GITHUB_OUTPUT"
79- echo "path_prefix=${path_prefix}" >> "$GITHUB_OUTPUT"
80- echo "preview_url=${preview_url}" >> "$GITHUB_OUTPUT"
41+ run : npm ci
8142
8243 - name : Build PR preview
8344 if : github.event.action != 'closed'
84- env :
85- GATSBY_PREVIEW : " true"
86- GATSBY_SITE_URL : ${{ steps.preview-vars.outputs.pages_origin }}
87- PATH_PREFIX : ${{ steps.preview-vars.outputs.path_prefix }}
8845 run : |
89- npm run build:preview
46+ npm run build
9047
91- # Block all crawlers from indexing PR previews.
48+ # Prevent indexing
9249 cat > public/robots.txt <<'EOF'
9350 User-agent: *
9451 Disallow: /
9552 EOF
96- touch public/.nojekyll
9753
9854 - name : Deploy PR preview
9955 if : github.event.action != 'closed'
11470 message : |
11571 🚀 **Preview deployment for PR #${{ github.event.pull_request.number }}**
11672
117- 🌐 **Preview URL**: ${{ steps. preview-vars.outputs.preview_url }}
73+ 🌐 **Preview URL**: https:// ${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr- preview/pr-${{ github.event.pull_request.number }}/
11874
11975 _This preview will be updated automatically when you push new commits to this PR._
12076
0 commit comments