1
+ # Copyright 2025 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ name : " docs"
16
+
17
+ permissions :
18
+ contents : write
19
+ pull-requests : write
20
+
21
+ # This Workflow depends on 'github.event.number',
22
+ # not compatible with branch or manual triggers.
23
+ on :
24
+ pull_request :
25
+ # Sync with github_actions_preview_fallback.yml on.pull_request.paths-ignore
26
+ paths :
27
+ - ' docs/**'
28
+ - ' github/workflows/docs**'
29
+ - ' .hugo'
30
+
31
+ jobs :
32
+ preview :
33
+ runs-on : ubuntu-24.04
34
+ defaults :
35
+ run :
36
+ working-directory : .hugo
37
+ concurrency :
38
+ # Shared concurrency group wih preview cleanup.
39
+ group : " preview-${{ github.event.number }}"
40
+ cancel-in-progress : true
41
+ steps :
42
+ - uses : actions/checkout@v4
43
+ with :
44
+ fetch-depth : 0 # Fetch all history for .GitInfo and .Lastmod
45
+
46
+ - name : Setup Hugo
47
+ uses : peaceiris/actions-hugo@v3
48
+ with :
49
+ hugo-version : " latest"
50
+ extended : true
51
+
52
+ - name : Setup Node
53
+ uses : actions/setup-node@v4
54
+ with :
55
+ node-version : " 22"
56
+
57
+ - name : Cache dependencies
58
+ uses : actions/cache@v4
59
+ with :
60
+ path : ~/.npm
61
+ key : ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
62
+ restore-keys : |
63
+ ${{ runner.os }}-node-
64
+
65
+ - run : npm ci
66
+ - run : hugo --minify
67
+ env :
68
+ # HUGO_BASEURL: https://${{ github.repository_owner }}.github.io/${{ github.repository }}/previews/PR-${{ github.event.number }}/
69
+ # While private, GitHub uses an obfuscated url instead:
70
+ HUGO_BASEURL : https://vigilant-guacamole-plnwrm9.pages.github.io/previews/PR-${{ github.event.number }}/
71
+ HUGO_ENVIRONMENT : preview
72
+ HUGO_RELATIVEURLS : false
73
+
74
+ - name : Deploy
75
+ # If run from a fork, GitHub write operations will fail.
76
+ if : ${{ !github.event.pull_request.head.repo.fork }}
77
+ uses : peaceiris/actions-gh-pages@v4
78
+ with :
79
+ github_token : ${{ secrets.GITHUB_TOKEN }}
80
+ publish_dir : .hugo/public
81
+ destination_dir : ./previews/PR-${{ github.event.number }}
82
+ commit_message : " stage: PR-${{ github.event.number }}: ${{ github.event.head_commit.message }}"
83
+
84
+ - name : Comment
85
+ # If run from a fork, GitHub write operations will fail.
86
+ if : ${{ !github.event.pull_request.head.repo.fork }}
87
+ uses : actions/github-script@v7
88
+ with :
89
+ script : |
90
+ github.rest.issues.createComment({
91
+ issue_number: context.payload.number,
92
+ owner: context.repo.owner,
93
+ repo: context.repo.repo,
94
+ body: "🔎 Preview at https://vigilant-guacamole-plnwrm9.pages.github.io/previews/PR-${{ github.event.number }}/"
95
+ })
0 commit comments