Skip to content

Commit 44d4bfe

Browse files
move build to github page
Signed-off-by: saurabhraghuvanshii <saurabhsraghuvanshi@gmail.com>
1 parent b6c0dd1 commit 44d4bfe

File tree

3 files changed

+113
-119
lines changed

3 files changed

+113
-119
lines changed
Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,51 @@
11
name: Build and Deploy Site
2+
23
on:
34
push:
45
branches: [master]
56
paths-ignore:
67
- .github/*
7-
8+
89
workflow_dispatch:
910
workflow_call:
10-
11+
12+
permissions:
13+
contents: write
14+
15+
concurrency:
16+
group: "pages-deployment"
17+
cancel-in-progress: true
18+
19+
defaults:
20+
run:
21+
shell: bash
22+
1123
jobs:
12-
build-and-deploy:
13-
runs-on: ubuntu-latest
24+
deploy:
25+
runs-on: ubuntu-24.04
1426
steps:
15-
- name: Checkout 🛎️
16-
uses: actions/checkout@master
27+
- name: Checkout
28+
uses: actions/checkout@v6
1729
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
30+
fetch-depth: 0
31+
32+
- name: Setup Node
33+
uses: actions/setup-node@v4
34+
with:
35+
node-version: "20"
36+
37+
- name: Install dependencies
38+
run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true"
39+
40+
- name: Build site
41+
run: |
42+
npm run build
43+
touch public/.nojekyll
44+
45+
- name: Deploy to GitHub Pages
46+
uses: peaceiris/actions-gh-pages@v4
4647
with:
47-
branch: site # The branch the action should deploy to.
48-
folder: public # The folder the action should deploy.
49-
clean: true
48+
github_token: ${{ secrets.GITHUB_TOKEN }}
49+
publish_dir: ./public
50+
publish_branch: gh-pages
51+
keep_files: true
Lines changed: 74 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,85 @@
11
name: Build and Preview Site
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:
9-
runs-on: ubuntu-latest
17+
build-and-deploy-preview:
18+
runs-on: ubuntu-24.04
1019
steps:
11-
- name: Checkout 🛎️
12-
uses: actions/checkout@master
20+
- name: Checkout PR
21+
if: github.event.action != 'closed'
22+
uses: actions/checkout@v6
23+
with:
24+
ref: ${{ github.event.pull_request.head.sha }}
25+
fetch-depth: 0
26+
27+
- name: Checkout for cleanup
28+
if: github.event.action == 'closed'
29+
uses: actions/checkout@v6
30+
with:
31+
ref: gh-pages
32+
fetch-depth: 0
33+
34+
- name: Setup Node
35+
if: github.event.action != 'closed'
36+
uses: actions/setup-node@v4
1337
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
38+
node-version: "20"
39+
40+
- name: Install dependencies
41+
if: github.event.action != 'closed'
42+
run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true"
43+
44+
- name: Build PR preview
45+
if: github.event.action != 'closed'
46+
run: |
47+
npm run build
48+
49+
# Block all crawlers from indexing PR previews.
50+
cat > public/robots.txt <<'EOF'
51+
User-agent: *
52+
Disallow: /
53+
EOF
54+
touch public/.nojekyll
55+
56+
- name: Deploy PR preview
57+
if: github.event.action != 'closed'
58+
id: deploy-preview
59+
uses: rossjrw/pr-preview-action@v1.6.3
3260
with:
33-
target: ./public/**/*.html
61+
source-dir: ./public
62+
preview-branch: gh-pages
63+
umbrella-dir: pr-preview
64+
action: auto
65+
comment: false
66+
67+
- name: Comment PR with Preview URL
68+
if: github.event.action != 'closed'
69+
uses: marocchino/sticky-pull-request-comment@v2
70+
with:
71+
header: pr-preview
72+
message: |
73+
🚀 **Preview deployment for PR #${{ github.event.pull_request.number }}**
74+
75+
🌐 **Preview URL**: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.pull_request.number }}/
3476
35-
- name: Zip Site
36-
run: bash ./script.sh
77+
_This preview will be updated automatically when you push new commits to this PR._
3778
38-
- name: Upload files
39-
uses: actions/upload-artifact@v6
79+
- name: Cleanup PR preview on close
80+
if: github.event.action == 'closed'
81+
uses: rossjrw/pr-preview-action@v1.6.3
4082
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"
83+
preview-branch: gh-pages
84+
umbrella-dir: pr-preview
85+
action: remove

.github/workflows/preview-site.yml

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

0 commit comments

Comments
 (0)