-
Notifications
You must be signed in to change notification settings - Fork 38
110 lines (94 loc) · 3.97 KB
/
Copy pathbuild-and-preview-site.yml
File metadata and controls
110 lines (94 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
name: Build and Preview Site
on:
pull_request_target:
branches: [master]
types: [opened, synchronize, reopened, closed]
permissions:
contents: write
pull-requests: write
concurrency:
group: preview-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: true
defaults:
run:
shell: bash
jobs:
build-and-deploy-preview:
runs-on: ubuntu-latest
steps:
- name: Checkout PR code
if: github.event.action != 'closed'
uses: actions/checkout@v6
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.sha }}
persist-credentials: false
fetch-depth: 0
- name: Checkout for cleanup
if: github.event.action == 'closed'
uses: actions/checkout@v6
with:
ref: gh-pages
fetch-depth: 0
- name: Setup Go
if: github.event.action != 'closed'
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
- name: Setup Hugo Extended
if: github.event.action != 'closed'
uses: peaceiris/actions-hugo@v3
with:
hugo-version: '0.158.0'
extended: true
- name: Setup Node
if: github.event.action != 'closed'
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Setup site dependencies
if: github.event.action != 'closed'
run: make setup
# The GitHub Pages preview URL is a per-PR subpath, so it is passed here
# directly rather than via the standardized scripts (whose build:preview
# targets Netlify's DEPLOY_PRIME_URL, not GitHub Pages).
# Mirrors 'npm run build:preview' (hugo --cleanDestinationDir -e dev -DFE --minify).
- name: Build PR preview
if: github.event.action != 'closed'
run: |
PR_BASE_URL="https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.pull_request.number }}/"
hugo --cleanDestinationDir -e dev -DFE --minify --baseURL "${PR_BASE_URL}"
touch public/.nojekyll
# Preview URLs are public GitHub Pages. Mark the whole deployment
# non-indexable so search engines don't crawl preview content.
- name: Make preview non-indexable
if: github.event.action != 'closed'
run: |
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' {} +
- name: Deploy PR preview
if: github.event.action != 'closed'
uses: rossjrw/pr-preview-action@v1.6.3
with:
source-dir: ./public
preview-branch: gh-pages
umbrella-dir: pr-preview
action: auto
comment: false
- name: Comment PR with Preview URL
if: github.event.action != 'closed'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-preview
message: |
🚀 Preview deployment: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.pull_request.number }}/
> *Note: Preview may take a moment (GitHub Pages deployment in progress). Please wait and refresh. Track deployment [here](https://github.com/${{ github.repository }}/actions/workflows/pages/pages-build-deployment)*
- name: Cleanup PR preview on close
if: github.event.action == 'closed'
uses: rossjrw/pr-preview-action@v1.6.3
with:
preview-branch: gh-pages
umbrella-dir: pr-preview
action: remove