|
| 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: "detect-changes" |
| 17 | + name: "gcr.io/cloud-builders/git" |
| 18 | + waitFor: ["-"] |
| 19 | + entrypoint: "bash" |
| 20 | + args: |
| 21 | + - -c |
| 22 | + - | |
| 23 | + git fetch --unshallow || true |
| 24 | + git fetch origin $_BASE_BRANCH > /dev/null 2>&1 |
| 25 | + git diff --name-only origin/$_BASE_BRANCH...HEAD > /workspace/changed_files.txt |
| 26 | +
|
| 27 | + - id: "generate-skills" |
| 28 | + name: "node:20" |
| 29 | + waitFor: ["detect-changes"] |
| 30 | + entrypoint: "bash" |
| 31 | + env: |
| 32 | + - "CLOUD_SQL_POSTGRES_PROJECT=$PROJECT_ID" |
| 33 | + - "CLOUD_SQL_POSTGRES_INSTANCE=$_CLOUD_SQL_POSTGRES_INSTANCE" |
| 34 | + - "CLOUD_SQL_POSTGRES_DATABASE=$_DATABASE_NAME" |
| 35 | + - "CLOUD_SQL_POSTGRES_REGION=$_REGION" |
| 36 | + secretEnv: |
| 37 | + ["CLOUD_SQL_POSTGRES_USER", "CLOUD_SQL_POSTGRES_PASSWORD", "GITHUB_TOKEN"] |
| 38 | + args: |
| 39 | + - -c |
| 40 | + - | |
| 41 | + PATTERN="^toolbox_version.txt$" |
| 42 | +
|
| 43 | + if ! grep -qE "$$PATTERN" /workspace/changed_files.txt; then |
| 44 | + echo "No relevant changes for toolbox_version.txt. Skipping generation." |
| 45 | + exit 0 |
| 46 | + fi |
| 47 | +
|
| 48 | + VERSION=$(cat toolbox_version.txt | tr -d '\n') |
| 49 | + echo "Detected toolbox version: $$VERSION" |
| 50 | +
|
| 51 | + echo "Generating skills via npx..." |
| 52 | + npx @toolbox-sdk/server@$${VERSION} --prebuilt cloud-sql-postgres skills-generate \ |
| 53 | + --name "cloud-sql-postgres-lifecycle" \ |
| 54 | + --description "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." \ |
| 55 | + --toolset=lifecycle \ |
| 56 | + --toolbox_version=$${VERSION} \ |
| 57 | + --license-header "// Copyright 2026 Google LLC |
| 58 | + // |
| 59 | + // Licensed under the Apache License, Version 2.0 (the \"License\"); |
| 60 | + // you may not use this file except in compliance with the License. |
| 61 | + // You may obtain a copy of the License at |
| 62 | + // |
| 63 | + // http://www.apache.org/licenses/LICENSE-2.0 |
| 64 | + // |
| 65 | + // Unless required by applicable law or agreed to in writing, software |
| 66 | + // distributed under the License is distributed on an \"AS IS\" BASIS, |
| 67 | + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 68 | + // See the License for the specific language governing permissions and |
| 69 | + // limitations under the License." \ |
| 70 | + --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." |
| 71 | +
|
| 72 | + if [ -z "$(git status --porcelain)" ]; then |
| 73 | + echo "No new files generated. Exiting." |
| 74 | + exit 0 |
| 75 | + fi |
| 76 | +
|
| 77 | + git config --global user.email "cloudbuild@google.com" |
| 78 | + git config --global user.name "Cloud Build Bot" |
| 79 | + git remote set-url origin https://x-access-token:$$GITHUB_TOKEN@github.com/gemini-cli-extensions/cloud-sql-postgresql.git |
| 80 | + git add . |
| 81 | + git commit -m "chore: auto-generate lifecycle skills based on toolbox_version.txt update" |
| 82 | + git push origin HEAD:$_HEAD_BRANCH |
| 83 | +
|
| 84 | +availableSecrets: |
| 85 | + secretManager: |
| 86 | + - versionName: projects/$PROJECT_ID/secrets/cloud_sql_pg_user/versions/latest |
| 87 | + env: CLOUD_SQL_POSTGRES_USER |
| 88 | + - versionName: projects/$PROJECT_ID/secrets/cloud_sql_pg_pass/versions/latest |
| 89 | + env: CLOUD_SQL_POSTGRES_PASSWORD |
| 90 | + - versionName: projects/$PROJECT_ID/secrets/github_token/versions/latest |
| 91 | + env: GITHUB_TOKEN |
| 92 | + |
| 93 | +options: |
| 94 | + logging: CLOUD_LOGGING_ONLY |
| 95 | + automapSubstitutions: true |
| 96 | + substitutionOption: "ALLOW_LOOSE" |
| 97 | + dynamicSubstitutions: true |
| 98 | + |
| 99 | +substitutions: |
| 100 | + _DATABASE_NAME: "test_database" |
| 101 | + _REGION: "us-central1" |
| 102 | + _CLOUD_SQL_POSTGRES_INSTANCE: "cloud-sql-pg-testing" |
0 commit comments