Skip to content

Commit 6b7a832

Browse files
authored
Merge pull request #7595 from saurabhraghuvanshii/build
Removing Pr-Preview from netlify, moving to GitHub page
2 parents b6c0dd1 + 12ea90c commit 6b7a832

File tree

6 files changed

+157
-136
lines changed

6 files changed

+157
-136
lines changed
Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,43 @@
1-
name: Build and Deploy Site
1+
name: Deploy Gatsby site to Pages
2+
23
on:
34
push:
45
branches: [master]
5-
paths-ignore:
6-
- .github/*
7-
86
workflow_dispatch:
9-
workflow_call:
10-
7+
8+
permissions:
9+
contents: write
10+
11+
concurrency:
12+
group: "pages-deployment"
13+
cancel-in-progress: true
14+
1115
jobs:
12-
build-and-deploy:
13-
runs-on: ubuntu-latest
16+
deploy:
17+
runs-on: ubuntu-24.04
18+
1419
steps:
15-
- name: Checkout 🛎️
16-
uses: actions/checkout@master
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
23+
- name: Setup Node
24+
uses: actions/setup-node@v4
1725
with:
18-
fetch-depth: 1
19-
20-
# - name: Cache Gatsby .cache and public folders
21-
# uses: actions/cache@v5
22-
# id: gatsby-cache
23-
# with:
24-
# path: |
25-
# public
26-
# .cache
27-
# key: ${{ runner.os }}-gatsby-${{ hashFiles('**/package-lock.json') }}
28-
# restore-keys: |
29-
# ${{ runner.os }}-gatsby-
30-
31-
- name: Install 🔧
32-
run: make setup
33-
34-
- name: Build 🏗️
35-
# Always run the full production build explicitly.
36-
# Do NOT use `make clean` here — that target is a developer convenience
37-
# command whose recipe has changed multiple times, causing blog posts and
38-
# other collections to be silently excluded from the deployed site when
39-
# it ran a lite/dev build instead of the full production build.
40-
# `npm run build` is the canonical, stable production build command:
41-
# cross-env BUILD_FULL_SITE=true gatsby build
42-
run: npm run build
43-
44-
- name: Deploy 🚀
45-
uses: JamesIves/github-pages-deploy-action@v4
26+
node-version: "20"
27+
28+
- name: Install dependencies
29+
run: npm ci
30+
31+
- name: Build Gatsby site
32+
run: |
33+
npm run build
34+
echo "layer5.io" > public/CNAME
35+
touch public/.nojekyll
36+
37+
- name: Deploy to GitHub Pages
38+
uses: peaceiris/actions-gh-pages@v4
4639
with:
47-
branch: site # The branch the action should deploy to.
48-
folder: public # The folder the action should deploy.
49-
clean: true
40+
github_token: ${{ secrets.GITHUB_TOKEN }}
41+
publish_dir: ./public
42+
publish_branch: gh-pages
43+
keep_files: true
Lines changed: 75 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,86 @@
1-
name: Build and Preview Site
1+
name: PR Preview Deployment (Gatsby + GitHub Pages)
2+
23
on:
3-
pull_request:
4+
pull_request_target:
45
branches: [master]
5-
types: [opened, synchronize, reopened]
6+
types: [opened, synchronize, reopened, closed]
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
concurrency:
13+
group: preview-${{ github.event.pull_request.number || github.run_id }}
14+
cancel-in-progress: true
615

716
jobs:
8-
site-preview:
17+
preview:
918
runs-on: ubuntu-latest
19+
1020
steps:
11-
- name: Checkout 🛎️
12-
uses: actions/checkout@master
21+
22+
- name: Checkout PR
23+
if: github.event.action != 'closed'
24+
uses: actions/checkout@v4
25+
with:
26+
ref: ${{ github.event.pull_request.head.sha }}
27+
28+
- name: Checkout gh-pages for cleanup
29+
if: github.event.action == 'closed'
30+
uses: actions/checkout@v4
31+
with:
32+
ref: gh-pages
33+
34+
- name: Setup Node
35+
if: github.event.action != 'closed'
36+
uses: actions/setup-node@v4
37+
with:
38+
node-version: "20"
39+
40+
- name: Install dependencies
41+
if: github.event.action != 'closed'
42+
run: npm ci
43+
44+
- name: Set PATH_PREFIX for preview
45+
if: github.event.action != 'closed'
46+
run: |
47+
echo "PATH_PREFIX=pr-preview/pr-${{ github.event.pull_request.number }}" >> $GITHUB_ENV
48+
49+
- name: Build PR preview
50+
if: github.event.action != 'closed'
51+
env:
52+
GATSBY_PREVIEW: "true"
53+
GATSBY_SITE_URL: https://${{ github.repository_owner }}.github.io
54+
run: |
55+
PATH_PREFIX=$PATH_PREFIX npm run build:preview
56+
57+
# Prevent indexing
58+
echo -e "User-agent: *\nDisallow: /" > public/robots.txt
59+
60+
- name: Deploy PR preview
61+
if: github.event.action != 'closed'
62+
uses: rossjrw/pr-preview-action@v1.6.3
1363
with:
14-
persist-credentials: false
15-
fetch-depth: 1
16-
17-
- name: Install 🔧
18-
run: make setup
19-
20-
- name: Build 🏗️
21-
# Always run the full production build explicitly.
22-
# Do NOT use `make clean` here — that target is a developer convenience
23-
# command whose recipe has changed multiple times, causing blog posts and
24-
# other collections to be silently excluded from the deployed site when
25-
# it ran a lite/dev build instead of the full production build.
26-
# `npm run build` is the canonical, stable production build command:
27-
# cross-env BUILD_FULL_SITE=true gatsby build
28-
run: npm run build
29-
30-
- name: Broken Link Check 🔗
31-
uses: technote-space/broken-link-checker-action@v2
64+
source-dir: ./public
65+
preview-branch: gh-pages
66+
umbrella-dir: pr-preview
67+
action: auto
68+
comment: false
69+
70+
- name: Comment PR with Preview URL
71+
if: github.event.action != 'closed'
72+
uses: marocchino/sticky-pull-request-comment@v2
3273
with:
33-
target: ./public/**/*.html
74+
header: pr-preview
75+
message: |
76+
🚀 **Preview for PR #${{ github.event.pull_request.number }}**
3477
35-
- name: Zip Site
36-
run: bash ./script.sh
78+
🌐 https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.pull_request.number }}/
3779
38-
- name: Upload files
39-
uses: actions/upload-artifact@v6
80+
- name: Cleanup PR preview
81+
if: github.event.action == 'closed'
82+
uses: rossjrw/pr-preview-action@v1.6.3
4083
with:
41-
name: public-dir
42-
path: ./public-dir.zip
43-
retention-days: 1
44-
- name: Trigger Inner workflow
45-
run: echo "triggering inner workflow"
84+
preview-branch: gh-pages
85+
umbrella-dir: pr-preview
86+
action: remove

.github/workflows/preview-site.yml

Lines changed: 0 additions & 48 deletions
This file was deleted.

gatsby-config.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ const {
88

99
const isDevelopment = process.env.NODE_ENV === "development";
1010
const isProduction = process.env.NODE_ENV === "production";
11+
const isPreviewBuild = process.env.GATSBY_PREVIEW === "true";
12+
const siteOrigin = (process.env.GATSBY_SITE_URL || "https://layer5.io").replace(
13+
/\/$/,
14+
"",
15+
);
16+
const rawPathPrefix = process.env.PATH_PREFIX || "";
17+
const pathPrefix = rawPathPrefix
18+
? `/${rawPathPrefix.replace(/^\/+|\/+$/g, "")}`
19+
: "";
20+
const siteRootUrl = `${siteOrigin}${pathPrefix}`.replace(/\/$/, "");
1121
const shouldBuildFullSite = isFullSiteBuild();
1222
const isLiteDevBuild = isDevelopment && !shouldBuildFullSite;
1323
const excludedCollections = getExcludedCollections({
@@ -34,11 +44,12 @@ module.exports = {
3444
description:
3545
"Expect more from your infrastructure. Cloud native, open source software for your internal development platforms, your DevOps, platform engineering and site reliability engineering teams. Less finger-pointing and more collaborating. Allowing developers to focus on business logic, not infrastructure concerns. Empowering operators to confidently run modern infrastructure.",
3646
author: "Layer5 Authors",
37-
permalink: "https://layer5.io",
38-
siteUrl: "https://layer5.io",
47+
permalink: siteRootUrl,
48+
siteUrl: siteRootUrl,
3949
image: "/images/layer5-gradient.webp",
4050
twitterUsername: "@layer5",
4151
},
52+
...(pathPrefix ? { pathPrefix } : {}),
4253
flags: {
4354
FAST_DEV: false,
4455
DEV_SSR: false,
@@ -560,14 +571,18 @@ module.exports = {
560571
query: "allMdx",
561572
},
562573
},
563-
{
564-
resolve: "gatsby-plugin-robots-txt",
565-
options: {
566-
host: "https://layer5.io",
567-
sitemap: "https://layer5.io/sitemap-index.xml",
568-
policy: [{ userAgent: "*", allow: "/" }],
569-
},
570-
},
574+
...(!isPreviewBuild
575+
? [
576+
{
577+
resolve: "gatsby-plugin-robots-txt",
578+
options: {
579+
host: siteRootUrl,
580+
sitemap: `${siteRootUrl}/sitemap-index.xml`,
581+
policy: [{ userAgent: "*", allow: "/" }],
582+
},
583+
},
584+
]
585+
: []),
571586
"gatsby-plugin-meta-redirect",
572587
// make sure this is always the last one
573588
],

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
},
1212
"scripts": {
1313
"build": "cross-env BUILD_FULL_SITE=true NODE_OPTIONS=--max-old-space-size=8192 gatsby build",
14+
"build:gh-pages": "cross-env BUILD_FULL_SITE=true NODE_OPTIONS=--max-old-space-size=8192 gatsby build --prefix-paths",
15+
"build:preview": "cross-env BUILD_FULL_SITE=true GATSBY_PREVIEW=true NODE_OPTIONS=--max-old-space-size=8192 gatsby build --prefix-paths",
1416
"clean": "gatsby clean",
1517
"clean:all": "gatsby clean && rimraf node_modules",
1618
"develop": "cross-env BUILD_FULL_SITE=true GATSBY_CPU_COUNT=4 SHARP_CONCURRENCY=4 UV_THREADPOOL_SIZE=4 NODE_OPTIONS=--max-old-space-size=8192 env-cmd -f .env.development gatsby develop",

src/components/seo.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,32 @@ const SEO = ({
3232
children,
3333
}) => {
3434
const { pathname } = useLocation();
35+
const isPreviewBuild = process.env.GATSBY_PREVIEW === "true";
3536
const {
3637
title: defaultTitle,
3738
description: defaultDescription,
3839
image: siteMetadataImage,
3940
siteUrl,
4041
twitterUsername,
4142
} = useSiteMetadata();
43+
const toAbsoluteUrl = (value) => {
44+
if (!value) return value;
45+
if (/^(?:[a-z]+:)?\/\//i.test(value)) return value;
46+
return new URL(value.replace(/^\//, ""), `${siteUrl}/`).toString();
47+
};
4248
const seo = {
4349
title: title || defaultTitle,
4450
description: description || defaultDescription,
45-
image: `${siteUrl}${image || siteMetadataImage}`,
46-
url: `${siteUrl}${pathname.replace(".html", "") || ""}`.replace(/\/$/, ""),
51+
image: toAbsoluteUrl(image || siteMetadataImage),
52+
url: new URL(
53+
(pathname.replace(".html", "") || "/").replace(/^\//, ""),
54+
`${siteUrl}/`,
55+
)
56+
.toString()
57+
.replace(/\/$/, ""),
4758
twitterUsername,
4859
};
49-
if (!canonical) {
60+
if (!canonical || isPreviewBuild) {
5061
canonical = seo.url;
5162
}
5263

@@ -60,6 +71,12 @@ const SEO = ({
6071
<meta name="description" content={seo.description} />
6172
<meta name="image" content={seo.image} />
6273
<meta name="author" content="Layer5, Inc." />
74+
{isPreviewBuild && (
75+
<>
76+
<meta name="robots" content="noindex, nofollow" />
77+
<meta name="googlebot" content="noindex, nofollow" />
78+
</>
79+
)}
6380

6481
{/* OpenGraph Meta Tags (Facebook, LinkedIn, etc.) */}
6582
<meta property="og:type" content="website" />

0 commit comments

Comments
 (0)