Skip to content

Commit 6ac9473

Browse files
committed
ci: auto generate skills on toolbox version update
Adds a Cloud Build pipeline and script to regenerate skills when toolbox_version.txt changes. Skill generation reads only the upstream prebuilt config, so no database connection is required.
1 parent 5b9bc21 commit 6ac9473

2 files changed

Lines changed: 204 additions & 0 deletions

File tree

.ci/scripts/generate_skills.sh

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Ensure VERSION is passed from the environment
5+
if [ -z "$VERSION" ]; then
6+
echo "Error: VERSION environment variable is not set."
7+
exit 1
8+
fi
9+
10+
# SKILL CONFIGURATION
11+
# Format: "toolset" "description"
12+
# The skill name is automatically generated as "cloud-sql-postgres-<toolset>"
13+
SKILLS=(
14+
"admin"
15+
"Use these skills when you need to provision new Cloud SQL instances, create databases and users, clone existing environments, and monitor the progress of long-running operations."
16+
17+
"lifecycle"
18+
"Use these skills when you need to manage the lifecycle of your instances, including performing backups and restores, checking major version upgrade compatibility, and monitoring overall instance status."
19+
20+
"data"
21+
"Use these skills when you need to explore the database structure, discover schema objects like views or stored procedures, and execute custom SQL queries to interact with your data."
22+
23+
"health"
24+
"Use these skills when you need to audit database health, identify storage bloat, find invalid indexes, analyze table statistics, and manage maintenance configurations like autovacuum."
25+
26+
"monitor"
27+
"Use these skills when you need to troubleshoot performance bottlenecks, analyze query execution plans, identify resource-heavy processes, and monitor system-level PromQL metrics."
28+
29+
"view-config"
30+
"Use these skills when you need to discover and manage PostgreSQL extensions or fine-tune engine-level settings such as memory allocation and server configuration parameters."
31+
32+
"replication"
33+
"Use these skills when you need to monitor replication health, manage sync states between nodes, and audit database roles and security settings to ensure environment integrity."
34+
35+
"vectorassist"
36+
"Use these skills to set up and optimize production-ready vector workloads by simply expressing your intent and performance requirements"
37+
)
38+
39+
echo "VALIDATING TOOLSETS BEFORE GENERATION"
40+
41+
# Dynamically build the SUPPORTED_TOOLSETS array from the SKILLS array.
42+
# We use 'set --' to process the array in chunks without index arithmetic.
43+
SUPPORTED_TOOLSETS=()
44+
set -- "${SKILLS[@]}"
45+
while [ $# -gt 0 ]; do
46+
SUPPORTED_TOOLSETS+=("$1")
47+
shift 2
48+
done
49+
50+
echo "Currently Supported Toolsets: ${SUPPORTED_TOOLSETS[*]}"
51+
52+
# Fetch the upstream source of truth YAML for this specific version
53+
RAW_URL="https://raw.githubusercontent.com/googleapis/mcp-toolbox/v${VERSION}/internal/prebuiltconfigs/tools/cloud-sql-postgres.yaml"
54+
echo "Fetching upstream config from: $RAW_URL"
55+
UPSTREAM_YAML=$(curl -sL --fail "$RAW_URL" || { echo "Error: Could not fetch upstream YAML for v$VERSION"; exit 1; })
56+
57+
# Extract the list of toolsets
58+
UPSTREAM_TOOLSETS=$(echo "$UPSTREAM_YAML" | awk '/^toolsets:/{flag=1; next} flag && /^ [a-zA-Z0-9_-]+:/{print $1}' | sed 's/://g')
59+
60+
# Compare upstream toolsets against our supported list
61+
MISSING_TOOLSETS=false
62+
63+
for upstream_tool in $UPSTREAM_TOOLSETS; do
64+
if [ -z "$upstream_tool" ] || [ "$upstream_tool" == "-" ]; then continue; fi
65+
66+
if [[ ! " ${SUPPORTED_TOOLSETS[*]} " =~ " ${upstream_tool} " ]]; then
67+
echo "ERROR: Upstream configuration contains a new toolset: '$upstream_tool'"
68+
MISSING_TOOLSETS=true
69+
fi
70+
done
71+
72+
if [ "$MISSING_TOOLSETS" = true ]; then
73+
echo "PIPELINE FAILED: Missing Toolset Generators"
74+
echo "The source of truth file has toolsets that your script does not support."
75+
echo "Please update the SKILLS array in generate_skills.sh to include generators"
76+
echo "for the missing toolsets above, then commit your changes to unblock this PR."
77+
exit 1
78+
fi
79+
80+
echo "Validation passed. All upstream toolsets are supported."
81+
82+
echo "BEGINNING SKILL GENERATION"
83+
84+
LICENSE_HEADER="// Copyright 2026 Google LLC
85+
//
86+
// Licensed under the Apache License, Version 2.0 (the \"License\");
87+
// you may not use this file except in compliance with the License.
88+
// You may obtain a copy of the License at
89+
//
90+
// http://www.apache.org/licenses/LICENSE-2.0
91+
//
92+
// Unless required by applicable law or agreed to in writing, software
93+
// distributed under the License is distributed on an \"AS IS\" BASIS,
94+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
95+
// See the License for the specific language governing permissions and
96+
// limitations under the License."
97+
98+
ADDITIONAL_NOTES="Note: The scripts automatically load the environment variables from various .env files. Do not ask the user to set vars unless skill executions fails due to env var absence."
99+
100+
# Base Command Function
101+
generate_skill() {
102+
local TOOLSET="$1"
103+
local SKILL_DESC="$2"
104+
local SKILL_NAME="cloud-sql-postgres-$TOOLSET"
105+
106+
echo "Generating skill: $SKILL_NAME..."
107+
108+
npx "@toolbox-sdk/server@${VERSION}" --prebuilt cloud-sql-postgres skills-generate \
109+
--name "$SKILL_NAME" \
110+
--description "$SKILL_DESC" \
111+
--toolset="$TOOLSET" \
112+
--license-header "$LICENSE_HEADER" \
113+
--additional-notes="$ADDITIONAL_NOTES"
114+
}
115+
116+
set -- "${SKILLS[@]}"
117+
while [ $# -gt 0 ]; do
118+
generate_skill "$1" "$2"
119+
shift 2
120+
done
121+
122+
echo "All skills generated successfully!"

.ci/skills-gen.cloudbuild.yaml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Copyright 2026 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+
steps:
16+
- id: "setup-ssh"
17+
name: "gcr.io/cloud-builders/git"
18+
entrypoint: "bash"
19+
secretEnv:
20+
- "GITHUB_TOKEN"
21+
volumes:
22+
- name: "ssh-keys"
23+
path: /root/.ssh
24+
args:
25+
- -c
26+
- |
27+
# Write the secret key to the shared volume and secure it
28+
printf "%s\n" "$$GITHUB_TOKEN" > /root/.ssh/id_ed25519
29+
chmod 400 /root/.ssh/id_ed25519
30+
31+
# Scan GitHub's server to prevent interactive prompts
32+
ssh-keyscan -t rsa github.com > /root/.ssh/known_hosts
33+
34+
- id: "generate-skills"
35+
name: "node:20"
36+
waitFor: ["setup-ssh"]
37+
entrypoint: "bash"
38+
args:
39+
- -c
40+
- |
41+
export VERSION=$$(cat toolbox_version.txt | tr -d '\n')
42+
echo "Detected toolbox version: $$VERSION"
43+
44+
chmod +x ./.ci/scripts/generate_skills.sh
45+
./.ci/scripts/generate_skills.sh
46+
47+
- id: "commit-and-push"
48+
name: "gcr.io/cloud-builders/git"
49+
waitFor: ["generate-skills"]
50+
entrypoint: "bash"
51+
volumes:
52+
- name: "ssh-keys"
53+
path: /root/.ssh
54+
args:
55+
- -c
56+
- |
57+
git config --global --add safe.directory '*'
58+
59+
if [ -z "$$(git status --porcelain)" ]; then
60+
echo "No new files generated. Exiting without committing."
61+
exit 0
62+
fi
63+
64+
echo "Changes detected. Preparing to commit..."
65+
git config user.name "release-please[bot]"
66+
git config user.email "55107282+release-please[bot]@users.noreply.github.com"
67+
68+
git remote set-url origin git@github.com:gemini-cli-extensions/cloud-sql-postgresql.git
69+
git add .
70+
git commit -m "chore: auto-generate skills based on toolbox_version.txt update"
71+
git push origin HEAD:$_HEAD_BRANCH
72+
73+
availableSecrets:
74+
secretManager:
75+
- versionName: projects/$PROJECT_ID/secrets/github_token_cloud_sql_postgresql/versions/latest
76+
env: "GITHUB_TOKEN"
77+
78+
options:
79+
logging: CLOUD_LOGGING_ONLY
80+
automapSubstitutions: true
81+
substitutionOption: "ALLOW_LOOSE"
82+
dynamicSubstitutions: true

0 commit comments

Comments
 (0)