Skip to content

Commit 38ab73d

Browse files
authored
ci: auto-generate skills on toolbox version updates (gemini-cli-extensions#177)
1 parent 336e909 commit 38ab73d

2 files changed

Lines changed: 181 additions & 0 deletions

File tree

.github/scripts/generate_skills.sh

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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. Each toolset is its own YAML document:
58+
# kind: toolset
59+
# name: <toolset>
60+
UPSTREAM_TOOLSETS=$(echo "$UPSTREAM_YAML" | awk '$1=="kind:" && $2=="toolset"{f=1; next} f && $1=="name:"{print $2; f=0}')
61+
62+
# Compare upstream toolsets against our supported list
63+
MISSING_TOOLSETS=false
64+
65+
for upstream_tool in $UPSTREAM_TOOLSETS; do
66+
if [ -z "$upstream_tool" ] || [ "$upstream_tool" == "-" ]; then continue; fi
67+
68+
if [[ ! " ${SUPPORTED_TOOLSETS[*]} " =~ " ${upstream_tool} " ]]; then
69+
echo "ERROR: Upstream configuration contains a new toolset: '$upstream_tool'"
70+
MISSING_TOOLSETS=true
71+
fi
72+
done
73+
74+
if [ "$MISSING_TOOLSETS" = true ]; then
75+
echo "PIPELINE FAILED: Missing Toolset Generators"
76+
echo "The source of truth file has toolsets that your script does not support."
77+
echo "Please update the SKILLS array in generate_skills.sh to include generators"
78+
echo "for the missing toolsets above, then commit your changes to unblock this PR."
79+
exit 1
80+
fi
81+
82+
echo "Validation passed. All upstream toolsets are supported."
83+
84+
echo "BEGINNING SKILL GENERATION"
85+
86+
LICENSE_HEADER="// Copyright 2026 Google LLC
87+
//
88+
// Licensed under the Apache License, Version 2.0 (the \"License\");
89+
// you may not use this file except in compliance with the License.
90+
// You may obtain a copy of the License at
91+
//
92+
// http://www.apache.org/licenses/LICENSE-2.0
93+
//
94+
// Unless required by applicable law or agreed to in writing, software
95+
// distributed under the License is distributed on an \"AS IS\" BASIS,
96+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
97+
// See the License for the specific language governing permissions and
98+
// limitations under the License."
99+
100+
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."
101+
102+
# Base Command Function
103+
generate_skill() {
104+
local TOOLSET="$1"
105+
local SKILL_DESC="$2"
106+
local SKILL_NAME="cloud-sql-postgres-$TOOLSET"
107+
108+
echo "Generating skill: $SKILL_NAME..."
109+
110+
npx "@toolbox-sdk/server@${VERSION}" --prebuilt cloud-sql-postgres skills-generate \
111+
--name "$SKILL_NAME" \
112+
--description "$SKILL_DESC" \
113+
--toolset="$TOOLSET" \
114+
--license-header "$LICENSE_HEADER" \
115+
--additional-notes="$ADDITIONAL_NOTES"
116+
}
117+
118+
set -- "${SKILLS[@]}"
119+
while [ $# -gt 0 ]; do
120+
generate_skill "$1" "$2"
121+
shift 2
122+
done
123+
124+
echo "All skills generated successfully!"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
name: Generate Skills
16+
17+
on:
18+
pull_request:
19+
paths:
20+
- "toolbox_version.txt"
21+
22+
jobs:
23+
generate-skills:
24+
# Only run for same-repo PRs (e.g. renovate's toolbox bump), where the
25+
# built-in GITHUB_TOKEN can push back to the PR branch.
26+
if: github.event.pull_request.head.repo.full_name == github.repository
27+
runs-on: ubuntu-latest
28+
permissions:
29+
contents: write
30+
steps:
31+
- name: Check out PR branch
32+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
33+
with:
34+
ref: ${{ github.head_ref }}
35+
36+
- name: Generate skills
37+
run: |
38+
VERSION="$(tr -d '\n' < toolbox_version.txt)"
39+
echo "Detected toolbox version: $VERSION"
40+
export VERSION
41+
chmod +x ./.github/scripts/generate_skills.sh
42+
./.github/scripts/generate_skills.sh
43+
44+
- name: Commit and push regenerated skills
45+
run: |
46+
if [ -z "$(git status --porcelain)" ]; then
47+
echo "No skill changes generated. Nothing to commit."
48+
exit 0
49+
fi
50+
51+
echo "Changes detected. Committing regenerated skills..."
52+
git config user.name "release-please[bot]"
53+
git config user.email "55107282+release-please[bot]@users.noreply.github.com"
54+
55+
git add .
56+
git commit -m "chore: auto-generate skills for toolbox v$(tr -d '\n' < toolbox_version.txt)"
57+
git push

0 commit comments

Comments
 (0)