Skip to content

Commit c1957d1

Browse files
committed
chore: Add workflows to deploy to cloudflare
1 parent 9c31d4a commit c1957d1

File tree

7 files changed

+543
-0
lines changed

7 files changed

+543
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: "Sync v1 docsite to Cloudflare"
2+
3+
concurrency:
4+
group: cloudflare-sync
5+
cancel-in-progress: true
6+
7+
on:
8+
workflow_run:
9+
workflows: ["CF: Deploy Dev Docs", "CF: Deploy Versioned Docs", "CF: Deploy Previous Version Docs"]
10+
types: [completed]
11+
12+
jobs:
13+
deploy:
14+
runs-on: ubuntu-latest
15+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
ref: 'cloudflare-pages'
20+
- name: Cleanup
21+
run: |
22+
rm -rf .git
23+
- name: Cloudflare Deploy
24+
uses: cloudflare/wrangler-action@v3
25+
with:
26+
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
27+
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
28+
command: pages deploy . --project-name=toolbox-docs --branch=main
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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: "CF: Deploy Dev Docs"
16+
17+
permissions:
18+
contents: write
19+
20+
on:
21+
push:
22+
branches:
23+
- main
24+
paths:
25+
- 'docs/**'
26+
- 'github/workflows/docs**'
27+
- '.hugo/**'
28+
29+
# Allow triggering manually.
30+
workflow_dispatch:
31+
32+
jobs:
33+
deploy:
34+
runs-on: ubuntu-24.04
35+
defaults:
36+
run:
37+
working-directory: .hugo
38+
# This shared concurrency group ensures only one docs deployment runs at a time.
39+
concurrency:
40+
group: cf-docs-update
41+
cancel-in-progress: false
42+
steps:
43+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
44+
with:
45+
fetch-depth: 0
46+
submodules: recursive
47+
48+
- name: Patch Config and Templates for Cloudflare
49+
run: |
50+
# Strip GitHub domain from config
51+
sed -i 's|https://googleapis.github.io/genai-toolbox/|/|g' hugo.toml
52+
# Strip prefix from navbar partial
53+
if [ -f "layouts/partials/navbar-version-selector.html" ]; then
54+
sed -i 's|/genai-toolbox/|/|g' layouts/partials/navbar-version-selector.html
55+
fi
56+
# Disable the migration banner for the new live site
57+
if [ -f "static/js/migration-banner.js" ]; then
58+
echo "" > static/js/migration-banner.js
59+
fi
60+
61+
- name: Setup Hugo
62+
uses: peaceiris/actions-hugo@75d2e84710de30f6ff7268e08f310b60ef14033f # v3
63+
with:
64+
hugo-version: "0.145.0"
65+
extended: true
66+
67+
- name: Setup Node
68+
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6
69+
with:
70+
node-version: "22"
71+
72+
- name: Cache dependencies
73+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5
74+
with:
75+
path: ~/.npm
76+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
77+
restore-keys: |
78+
${{ runner.os }}-node-
79+
80+
- run: npm ci
81+
- run: hugo --minify
82+
env:
83+
HUGO_BASEURL: https://mcp-toolbox.dev/dev/
84+
HUGO_RELATIVEURLS: false
85+
86+
- name: Create Staging Directory
87+
run: |
88+
mkdir staging
89+
mv public staging/dev
90+
mv staging/dev/releases.releases staging/releases.releases
91+
92+
- name: Push to Cloudflare Branch
93+
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4
94+
with:
95+
github_token: ${{ secrets.GITHUB_TOKEN }}
96+
publish_dir: ./.hugo/staging
97+
publish_branch: cloudflare-pages
98+
keep_files: true
99+
commit_message: "deploy: ${{ github.event.head_commit.message }}"
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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: "CF: Deploy Previous Version Docs"
16+
17+
on:
18+
workflow_dispatch:
19+
inputs:
20+
version_tag:
21+
description: 'The old version tag to build docs for (e.g., v0.15.0)'
22+
required: true
23+
type: string
24+
25+
jobs:
26+
build_and_deploy:
27+
runs-on: ubuntu-latest
28+
permissions:
29+
contents: write
30+
31+
steps:
32+
- name: Checkout main branch (for latest templates and theme)
33+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
34+
with:
35+
ref: 'main'
36+
submodules: 'recursive'
37+
fetch-depth: 0
38+
39+
- name: Checkout old content from tag into a temporary directory
40+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
41+
with:
42+
ref: ${{ github.event.inputs.version_tag }}
43+
path: 'old_version_source' # Checkout into a temp subdir
44+
# Sparse checkout to only get the content directory
45+
sparse-checkout: |
46+
docs
47+
48+
- name: Replace content with old version
49+
run: |
50+
# Remove the current content directory from the main branch checkout
51+
rm -rf docs/
52+
# Move the old content directory into place
53+
mv ./old_version_source/docs docs
54+
55+
- name: Patch Config and Templates for Cloudflare
56+
run: |
57+
# Strip the GitHub domain from the Hugo config
58+
sed -i 's|https://googleapis.github.io/genai-toolbox/|/|g' .hugo/hugo.toml
59+
60+
# Strip the hardcoded path prefix from the navbar selector
61+
if [ -f ".hugo/layouts/partials/navbar-version-selector.html" ]; then
62+
sed -i 's|/genai-toolbox/|/|g' .hugo/layouts/partials/navbar-version-selector.html
63+
fi
64+
65+
# Disable the migration banner for the new live site
66+
if [ -f ".hugo/static/js/migration-banner.js" ]; then
67+
echo "" > .hugo/static/js/migration-banner.js
68+
fi
69+
70+
- name: Setup Hugo and Node
71+
uses: peaceiris/actions-hugo@75d2e84710de30f6ff7268e08f310b60ef14033f # v3
72+
with:
73+
hugo-version: "0.145.0"
74+
extended: true
75+
- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6
76+
with:
77+
node-version: "22"
78+
79+
- name: Install Dependencies
80+
run: npm ci
81+
working-directory: .hugo
82+
83+
- name: Build Hugo Site for Archived Version
84+
run: hugo --minify
85+
working-directory: .hugo
86+
env:
87+
HUGO_BASEURL: https://mcp-toolbox.dev/${{ github.event.inputs.version_tag }}/
88+
HUGO_RELATIVEURLS: false
89+
90+
- name: Deploy to cloudflare-pages
91+
uses: peaceiris/actions-gh-pages@v4
92+
with:
93+
github_token: ${{ secrets.GITHUB_TOKEN }}
94+
publish_dir: .hugo/public
95+
publish_branch: cloudflare-pages
96+
destination_dir: ./${{ github.event.inputs.version_tag }}
97+
keep_files: true
98+
allow_empty_commit: true
99+
commit_message: "docs(backport): deploy docs for ${{ github.event.inputs.version_tag }}"
100+
101+
- name: Clean Build Directory
102+
run: rm -rf .hugo/public
103+
104+
- name: Build Hugo Site
105+
run: hugo --minify
106+
working-directory: .hugo
107+
env:
108+
HUGO_BASEURL: https://mcp-toolbox.dev/
109+
HUGO_RELATIVEURLS: false
110+
111+
- name: Deploy to root
112+
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4
113+
with:
114+
github_token: ${{ secrets.GITHUB_TOKEN }}
115+
publish_dir: .hugo/public
116+
publish_branch: cloudflare-pages
117+
keep_files: true
118+
allow_empty_commit: true
119+
commit_message: "deploy: docs to root for ${{ github.event.inputs.version_tag }}"
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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: "CF: Deploy Versioned Docs"
16+
17+
permissions:
18+
contents: write
19+
20+
on:
21+
release:
22+
types: [published]
23+
24+
jobs:
25+
deploy:
26+
runs-on: ubuntu-24.04
27+
# This shared concurrency group ensures only one docs deployment runs at a time.
28+
concurrency:
29+
group: cf-docs-update
30+
cancel-in-progress: false
31+
steps:
32+
- name: Checkout Code at Tag
33+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
34+
with:
35+
ref: ${{ github.event.release.tag_name }}
36+
37+
- name: Get Version from Release Tag
38+
id: get_version
39+
env:
40+
RELEASE_TAG: ${{ github.event.release.tag_name }}
41+
run: echo "VERSION=${RELEASE_TAG}" >> "$GITHUB_OUTPUT"
42+
43+
- name: Patch Config and Templates for Cloudflare
44+
run: |
45+
# Strip the GitHub domain from the Hugo config
46+
sed -i 's|https://googleapis.github.io/genai-toolbox/|/|g' .hugo/hugo.toml
47+
48+
# Strip the hardcoded path prefix from the navbar selector
49+
if [ -f ".hugo/layouts/partials/navbar-version-selector.html" ]; then
50+
sed -i 's|/genai-toolbox/|/|g' .hugo/layouts/partials/navbar-version-selector.html
51+
fi
52+
53+
# Disable the migration banner for the new live site
54+
if [ -f ".hugo/static/js/migration-banner.js" ]; then
55+
echo "" > .hugo/static/js/migration-banner.js
56+
fi
57+
58+
- name: Setup Hugo
59+
uses: peaceiris/actions-hugo@75d2e84710de30f6ff7268e08f310b60ef14033f # v3
60+
with:
61+
hugo-version: "0.145.0"
62+
extended: true
63+
64+
- name: Setup Node
65+
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6
66+
with:
67+
node-version: "22"
68+
69+
- name: Install Dependencies
70+
run: npm ci
71+
working-directory: .hugo
72+
73+
- name: Build Hugo Site
74+
run: hugo --minify
75+
working-directory: .hugo
76+
env:
77+
HUGO_BASEURL: https://mcp-toolbox.dev/${{ steps.get_version.outputs.VERSION }}/
78+
HUGO_RELATIVEURLS: false
79+
80+
- name: Deploy
81+
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4
82+
with:
83+
github_token: ${{ secrets.GITHUB_TOKEN }}
84+
publish_dir: .hugo/public
85+
publish_branch: cloudflare-pages
86+
destination_dir: ./${{ steps.get_version.outputs.VERSION }}
87+
keep_files: true
88+
commit_message: "deploy: docs for ${{ steps.get_version.outputs.VERSION }}"
89+
90+
- name: Clean Build Directory
91+
run: rm -rf .hugo/public
92+
93+
- name: Build Hugo Site
94+
run: hugo --minify
95+
working-directory: .hugo
96+
env:
97+
HUGO_BASEURL: https://mcp-toolbox.dev/
98+
HUGO_RELATIVEURLS: false
99+
100+
- name: Deploy to root
101+
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4
102+
with:
103+
github_token: ${{ secrets.GITHUB_TOKEN }}
104+
publish_dir: .hugo/public
105+
publish_branch: cloudflare-pages
106+
keep_files: true
107+
allow_empty_commit: true
108+
commit_message: "deploy: docs to root for ${{ steps.get_version.outputs.VERSION }}"

0 commit comments

Comments
 (0)