Skip to content

Commit ece3164

Browse files
committed
Update deployment site/preview gh pages
Signed-off-by: Raunak Madan <madanraunak24@gmail.com>
1 parent 87a58f6 commit ece3164

File tree

4 files changed

+177
-75
lines changed

4 files changed

+177
-75
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: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,34 @@ 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+
hugo build $(if $(BASE_URL),--baseURL $(BASE_URL),)
39+
40+
## CI: Build production site output
41+
build-production:
42+
HUGO_ENVIRONMENT=production HUGO_ENV=production hugo build -D --gc --buildFuture --minify $(if $(BASE_URL),--baseURL $(BASE_URL),)
43+
44+
## CI: Build preview site output and mark it non-indexable
45+
build-preview:
46+
HUGO_ENVIRONMENT=production HUGO_ENV=production HUGO_PREVIEW=true hugo build -D --gc --buildFuture --minify $(if $(BASE_URL),--baseURL $(BASE_URL),)
47+
@printf 'User-agent: *\nDisallow: /\n' > public/robots.txt
48+
@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' {} +
3349

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

0 commit comments

Comments
 (0)