Skip to content

Commit cc7fa04

Browse files
authored
Merge pull request #126 from CodexRaunak/add-deployment-gh-pages
Update deployment site/preview gh pages
2 parents 87a58f6 + 5297409 commit cc7fa04

File tree

5 files changed

+179
-80
lines changed

5 files changed

+179
-80
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Build and Deploy Site
2+
3+
on:
4+
push:
5+
branches: [master]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
11+
defaults:
12+
run:
13+
shell: bash
14+
15+
jobs:
16+
build-and-deploy-site:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v6
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Setup Go
26+
uses: actions/setup-go@v5
27+
with:
28+
go-version-file: go.mod
29+
cache: true
30+
31+
- name: Setup Hugo Extended
32+
uses: peaceiris/actions-hugo@v3
33+
with:
34+
hugo-version: '0.158.0'
35+
extended: true
36+
37+
- name: Setup Node
38+
uses: actions/setup-node@v4
39+
with:
40+
node-version: '20'
41+
cache: 'npm'
42+
43+
- name: Setup site dependencies
44+
run: make setup
45+
46+
- name: Build site
47+
run: make build-production BASE_URL="https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/"
48+
49+
- name: Prepare Pages output
50+
run: touch public/.nojekyll
51+
52+
- name: Deploy site to GitHub Pages
53+
uses: peaceiris/actions-gh-pages@v4
54+
with:
55+
github_token: ${{ secrets.GITHUB_TOKEN }}
56+
publish_branch: gh-pages
57+
publish_dir: ./public
58+
keep_files: true
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: Build and Preview Site
2+
3+
on:
4+
pull_request_target:
5+
branches: [master]
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
15+
16+
defaults:
17+
run:
18+
shell: bash
19+
20+
jobs:
21+
build-and-deploy-preview:
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- name: Checkout PR code
26+
if: github.event.action != 'closed'
27+
uses: actions/checkout@v6
28+
with:
29+
repository: ${{ github.event.pull_request.head.repo.full_name }}
30+
ref: ${{ github.event.pull_request.head.sha }}
31+
persist-credentials: false
32+
fetch-depth: 0
33+
34+
- name: Checkout for cleanup
35+
if: github.event.action == 'closed'
36+
uses: actions/checkout@v6
37+
with:
38+
ref: gh-pages
39+
fetch-depth: 0
40+
41+
- name: Setup Go
42+
if: github.event.action != 'closed'
43+
uses: actions/setup-go@v5
44+
with:
45+
go-version-file: go.mod
46+
cache: true
47+
48+
- name: Setup Hugo Extended
49+
if: github.event.action != 'closed'
50+
uses: peaceiris/actions-hugo@v3
51+
with:
52+
hugo-version: '0.158.0'
53+
extended: true
54+
55+
- name: Setup Node
56+
if: github.event.action != 'closed'
57+
uses: actions/setup-node@v4
58+
with:
59+
node-version: '20'
60+
cache: 'npm'
61+
62+
- name: Setup site dependencies
63+
if: github.event.action != 'closed'
64+
run: make setup
65+
66+
- name: Build PR preview
67+
if: github.event.action != 'closed'
68+
run: |
69+
make build-preview BASE_URL="https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.pull_request.number }}/"
70+
touch public/.nojekyll
71+
72+
- name: Deploy PR preview
73+
if: github.event.action != 'closed'
74+
uses: rossjrw/pr-preview-action@v1.6.3
75+
with:
76+
source-dir: ./public
77+
preview-branch: gh-pages
78+
umbrella-dir: pr-preview
79+
action: auto
80+
comment: false
81+
82+
- name: Comment PR with Preview URL
83+
if: github.event.action != 'closed'
84+
uses: marocchino/sticky-pull-request-comment@v2
85+
with:
86+
header: pr-preview
87+
message: |
88+
🚀 **Preview deployment for PR #${{ github.event.pull_request.number }}**
89+
90+
🌐 **Preview URL**: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.pull_request.number }}/
91+
92+
_This preview will be updated automatically when you push new commits to this PR._
93+
94+
- name: Cleanup PR preview on close
95+
if: github.event.action == 'closed'
96+
uses: rossjrw/pr-preview-action@v1.6.3
97+
with:
98+
preview-branch: gh-pages
99+
umbrella-dir: pr-preview
100+
action: remove

.github/workflows/gh-pages.yml

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

Makefile

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,32 @@ include .github/build/Makefile.show-help.mk
1818
#----------------------------------------------------------------------------
1919
# Academy
2020
# ---------------------------------------------------------------------------
21-
.PHONY: setup build site clean check-go theme-update
21+
.PHONY: setup build build-production build-preview site clean check-go theme-update
22+
23+
BASE_URL ?=
2224

2325
## ------------------------------------------------------------
2426
----LOCAL_BUILDS: Show help for available targets
2527

2628
## Local: Install site dependencies
2729
setup:
28-
npm i
30+
@if [ -f package-lock.json ] || [ -f npm-shrinkwrap.json ]; then \
31+
npm ci; \
32+
else \
33+
npm i; \
34+
fi
2935

3036
## Local: Build site for local consumption
3137
build:
32-
hugo build
38+
BASE_URL="$(BASE_URL)" npm run build
39+
40+
## CI: Build production site output
41+
build-production:
42+
BASE_URL="$(BASE_URL)" npm run build:production
43+
44+
## CI: Build preview site output and mark it non-indexable
45+
build-preview:
46+
BASE_URL="$(BASE_URL)" npm run build:preview
3347

3448
## Local: Build and run site locally with draft and future content enabled.
3549
site: check-go

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,22 @@
1010
"bugs": "https://github.com/google/docsy-example/issues",
1111
"spelling": "cSpell:ignore docsy hugo htmltest precheck postbuild rtlcss -",
1212
"scripts": {
13-
"_build": "npm run _hugo-dev --",
1413
"_check:links": "echo IMPLEMENTATION PENDING for check-links; echo",
1514
"_hugo": "hugo --cleanDestinationDir",
1615
"_hugo-dev": "npm run _hugo -- -e dev -DFE",
1716
"_local": "npx cross-env HUGO_MODULE_WORKSPACE=docsy.work",
1817
"_serve": "npm run _hugo-dev -- --minify serve --renderToMemory",
19-
"build:preview": "npm run _hugo-dev -- --minify --baseURL \"${DEPLOY_PRIME_URL:-/}\"",
20-
"build:production": "npm run _hugo -- --minify",
21-
"build": "npm run _build -- ",
18+
"build": "sh -c 'hugo build --cleanDestinationDir ${BASE_URL:+--baseURL \"$BASE_URL\"}'",
19+
"build:preview": "cross-env HUGO_ENVIRONMENT=production HUGO_ENV=production HUGO_PREVIEW=true sh -c 'hugo build -D --gc --buildFuture --cleanDestinationDir --minify ${BASE_URL:+--baseURL \"$BASE_URL\"}'",
20+
"build:production": "cross-env HUGO_ENVIRONMENT=production HUGO_ENV=production sh -c 'hugo build -D --gc --buildFuture --cleanDestinationDir --minify ${BASE_URL:+--baseURL \"$BASE_URL\"}'",
2221
"check:links:all": "HTMLTEST_ARGS= npm run _check:links",
2322
"check:links": "npm run _check:links",
2423
"clean": "rm -Rf public/* resources",
2524
"local": "npm run _local -- npm run",
2625
"make:public": "git init -b main public",
2726
"precheck:links:all": "npm run build",
2827
"precheck:links": "npm run build",
29-
"postbuild:preview": "npm run _check:links",
28+
"postbuild:preview": "printf 'User-agent: *\\nDisallow: /\\n' > public/robots.txt && find public -name '*.html' -exec perl -0pi -e 's|<meta name=robots content=\"index, follow\">|<meta name=robots content=\"noindex, nofollow\">|g; s|<meta name=\"robots\" content=\"index, follow\">|<meta name=\"robots\" content=\"noindex, nofollow\">|g; s|</head>|<meta name=\"robots\" content=\"noindex, nofollow\"></head>|i unless /<meta[^>]+name=\"?robots\"?[^>]+noindex, nofollow/i' {} +",
3029
"postbuild:production": "npm run _check:links",
3130
"serve": "npm run _serve",
3231
"test": "npm run check:links",

0 commit comments

Comments
 (0)