Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions .ci/update_docs_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/usr/bin/env python3
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import re
import sys

def main():
# Read version from command line argument if provided, otherwise from cmd/version.txt
if len(sys.argv) > 1 and sys.argv[1].strip():
version_raw = sys.argv[1].strip()
else:
version_file_path = os.path.join(os.path.dirname(__file__), '../cmd/version.txt')
if not os.path.exists(version_file_path):
print(f"Error: Version file {version_file_path} not found.")
sys.exit(1)

with open(version_file_path, 'r') as f:
version_raw = f.read().strip()

if not version_raw:
print("Error: Version file is empty.")
sys.exit(1)

# Ensure it starts with 'v'
version = version_raw if version_raw.startswith('v') else f'v{version_raw}'
print(f"Target version: {version}")

hugo_dir = os.path.join(os.path.dirname(__file__), '../.hugo')
hugo_cf_toml_path = os.path.join(hugo_dir, 'hugo.cloudflare.toml')

# Update hugo.cloudflare.toml
if os.path.exists(hugo_cf_toml_path):
update_toml_file(hugo_cf_toml_path, version, remove_oldest=True)
else:
print(f"Warning: {hugo_cf_toml_path} not found.")

def update_toml_file(file_path, version, remove_oldest):
print(f"Processing {file_path}...")
with open(file_path, 'r') as f:
content = f.read()

# Check if version already exists
version_pattern = f'version\\s*=\\s*"{version}"'
Comment thread
dishaprakash marked this conversation as resolved.
Outdated
if re.search(version_pattern, content):
print(f"Version {version} already exists in {os.path.basename(file_path)}. No change needed.")
return

# Insert new version block right after the specific comment
comment_marker = '# The order of versions in this file is mirrored into the dropdown'
if comment_marker not in content:
print(f"Error: Could not find comment marker in {os.path.basename(file_path)}.")
sys.exit(1)

new_block = f'[[params.versions]]\n version = "{version}"\n url = "https://mcp-toolbox.dev/{version}/"'
target_str = comment_marker
replacement_str = f"{comment_marker}\n\n{new_block}"

updated_content = content.replace(target_str, replacement_str, 1)

if remove_oldest:
# We need to remove the last [[params.versions]] block.
version_block_pattern = r'\[\[params\.versions\]\]\s+version\s*=\s*"[^"]+"\s+url\s*=\s*"[^"]+"'
Comment thread
dishaprakash marked this conversation as resolved.
Outdated
matches = list(re.finditer(version_block_pattern, updated_content))
print(f"Found {len(matches)} version blocks in {os.path.basename(file_path)}.")

# We keep at most 8 version blocks (dev + 7 released versions).
if len(matches) > 8:
last_match = matches[-1]
start, end = last_match.span()
before = updated_content[:start]
after = updated_content[end:]

before = before.rstrip() + '\n\n'
after = after.lstrip()

updated_content = before + after
print(f"Removed the oldest version block from {os.path.basename(file_path)}.")

with open(file_path, 'w') as f:
f.write(updated_content)
print(f"Successfully updated {os.path.basename(file_path)}.")

if __name__ == '__main__':
main()
62 changes: 62 additions & 0 deletions .github/workflows/update_release_docs_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: "CF: Update Release Docs Config"

on:
pull_request:
branches:
- main
workflow_dispatch:
inputs:
version:
description: 'Version to add (e.g., v1.6.0). If left empty, the version is automatically read from cmd/version.txt.'
required: false
type: string
default: ''

permissions:
contents: write

jobs:
update-docs-config:
runs-on: ubuntu-latest
# Run automatically if it's a release-please PR, OR if manually dispatched
if: ${{ github.event_name == 'workflow_dispatch' || startsWith(github.head_ref, 'release-please--') }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
# If triggered by PR, checkout the PR branch; otherwise checkout the dispatched branch
ref: ${{ github.event.pull_request.head.ref || github.ref }}

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Update TOML version configurations
run: python3 .ci/update_docs_versions.py "${{ github.event.inputs.version }}"

- name: Commit and Push Changes
run: |
git config user.name "github-actions[bot]"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't use the Github action bot to commit changes since it can not sign the CLA (go/cla). @twishabansal has a solution to update the release please PR using that identity

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git config user.email "github-actions[bot]@users.noreply.github.com"
git add .hugo/hugo.cloudflare.toml
if git diff --quiet && git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "chore: update documentation version list for release"
git push
fi
Loading