Skip to content

Commit 254286f

Browse files
committed
ci: auto-generate skills on toolbox version updates
1 parent fda5aac commit 254286f

2 files changed

Lines changed: 169 additions & 0 deletions

File tree

.github/scripts/generate_skills.sh

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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-mysql-<toolset>"
13+
SKILLS=(
14+
"admin"
15+
"Use these skills when you need to provision new Cloud SQL for MySQL instances, create databases and users, clone existing environments, and monitor the progress of infrastructure operations."
16+
17+
"data"
18+
"Use these skills when you need to explore your database schema, execute SQL queries to interact with your data, and inspect how MySQL plans to execute your statements."
19+
20+
"monitor"
21+
"Use these skills when you need to troubleshoot slow queries, analyze system-level PromQL metrics, and identify structural performance issues like table fragmentation or missing unique indexes."
22+
23+
"lifecycle"
24+
"Use these skills when you need to manage the durability and safety of your data by creating backups, restoring from previous states, or cloning instances for recovery and testing."
25+
)
26+
27+
echo "VALIDATING TOOLSETS BEFORE GENERATION"
28+
29+
# Dynamically build the SUPPORTED_TOOLSETS array from the SKILLS array.
30+
# We use 'set --' to process the array in chunks without index arithmetic.
31+
SUPPORTED_TOOLSETS=()
32+
set -- "${SKILLS[@]}"
33+
while [ $# -gt 0 ]; do
34+
SUPPORTED_TOOLSETS+=("$1")
35+
shift 2
36+
done
37+
38+
echo "Currently Supported Toolsets: ${SUPPORTED_TOOLSETS[*]}"
39+
40+
# Fetch the upstream source of truth YAML for this specific version
41+
RAW_URL="https://raw.githubusercontent.com/googleapis/mcp-toolbox/v${VERSION}/internal/prebuiltconfigs/tools/cloud-sql-mysql.yaml"
42+
echo "Fetching upstream config from: $RAW_URL"
43+
UPSTREAM_YAML=$(curl -sL --fail "$RAW_URL" || { echo "Error: Could not fetch upstream YAML for v$VERSION"; exit 1; })
44+
45+
# Extract the list of toolsets. Each toolset is its own YAML document:
46+
# kind: toolset
47+
# name: <toolset>
48+
UPSTREAM_TOOLSETS=$(echo "$UPSTREAM_YAML" | awk '$1=="kind:" && $2=="toolset"{f=1; next} f && $1=="name:"{print $2; f=0}')
49+
50+
# Compare upstream toolsets against our supported list
51+
MISSING_TOOLSETS=false
52+
53+
for upstream_tool in $UPSTREAM_TOOLSETS; do
54+
if [ -z "$upstream_tool" ] || [ "$upstream_tool" == "-" ]; then continue; fi
55+
56+
if [[ ! " ${SUPPORTED_TOOLSETS[*]} " =~ " ${upstream_tool} " ]]; then
57+
echo "ERROR: Upstream configuration contains a new toolset: '$upstream_tool'"
58+
MISSING_TOOLSETS=true
59+
fi
60+
done
61+
62+
if [ "$MISSING_TOOLSETS" = true ]; then
63+
echo "PIPELINE FAILED: Missing Toolset Generators"
64+
echo "The source of truth file has toolsets that your script does not support."
65+
echo "Please update the SKILLS array in generate_skills.sh to include generators"
66+
echo "for the missing toolsets above, then commit your changes to unblock this PR."
67+
exit 1
68+
fi
69+
70+
echo "Validation passed. All upstream toolsets are supported."
71+
72+
echo "BEGINNING SKILL GENERATION"
73+
74+
LICENSE_HEADER="// Copyright 2026 Google LLC
75+
//
76+
// Licensed under the Apache License, Version 2.0 (the \"License\");
77+
// you may not use this file except in compliance with the License.
78+
// You may obtain a copy of the License at
79+
//
80+
// http://www.apache.org/licenses/LICENSE-2.0
81+
//
82+
// Unless required by applicable law or agreed to in writing, software
83+
// distributed under the License is distributed on an \"AS IS\" BASIS,
84+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
85+
// See the License for the specific language governing permissions and
86+
// limitations under the License."
87+
88+
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."
89+
90+
# Base Command Function
91+
generate_skill() {
92+
local TOOLSET="$1"
93+
local SKILL_DESC="$2"
94+
local SKILL_NAME="cloud-sql-mysql-$TOOLSET"
95+
96+
echo "Generating skill: $SKILL_NAME..."
97+
98+
npx "@toolbox-sdk/server@${VERSION}" --prebuilt cloud-sql-mysql skills-generate \
99+
--name "$SKILL_NAME" \
100+
--description "$SKILL_DESC" \
101+
--toolset="$TOOLSET" \
102+
--license-header "$LICENSE_HEADER" \
103+
--additional-notes="$ADDITIONAL_NOTES"
104+
}
105+
106+
set -- "${SKILLS[@]}"
107+
while [ $# -gt 0 ]; do
108+
generate_skill "$1" "$2"
109+
shift 2
110+
done
111+
112+
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)