|
| 1 | +# Copyright 2025 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 | +# This Cloud Build configuration is used by a Louhi flow for the Artifact |
| 15 | +# Registry (AR) Exit Gate process (go/cloud-sdk-ar-exit-gate-onboarding). |
| 16 | +# |
| 17 | +# This runs the `librarian generate` command with a provided repository, |
| 18 | +# secret name, and optional library ID |
| 19 | +steps: |
| 20 | + - name: 'gcr.io/cloud-builders/gcloud-slim' |
| 21 | + id: validate-credentials |
| 22 | + waitFor: ['-'] |
| 23 | + script: | |
| 24 | + #!/usr/bin/env bash |
| 25 | + echo "Your project ID is $PROJECT_ID" |
| 26 | + echo "gcloud config get-value core/account:" |
| 27 | + gcloud config get-value core/account |
| 28 | + echo "pwd is $(pwd)" |
| 29 | + echo "ls -la ." |
| 30 | + ls -la . |
| 31 | + echo "Finding YAML files:" |
| 32 | + find /workspace/librarian -name '*.yaml' |
| 33 | + ROBOT_ACCOUNT=cloud-sdk-librarian-robot |
| 34 | + if [[ $- == *x* ]]; then |
| 35 | + echo "xtrace is ON. Exiting to avoid credentials showing up in logs." |
| 36 | + exit 1 |
| 37 | + fi |
| 38 | + cat infra/prod/repositories.yaml | grep '^\s*-\s*name:' |awk '{print $NF}' |tr -d '"' | while read -r repo_name; do |
| 39 | + echo "Validating credentials for repository: $repo_name" |
| 40 | + GITHUB_TOKEN=$(gcloud secrets versions access latest --secret="${repo_name}-github-token") |
| 41 | + curl --fail -H "Authorization: token ${GITHUB_TOKEN}" "https://api.github.com/repos/googleapis/${repo_name}/collaborators/${ROBOT_ACCOUNT}/permission" |
| 42 | + if [[ $? -ne 0 ]]; then |
| 43 | + echo "Failed to validate credentials for repository: $repo_name" |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | + done |
| 47 | + echo "Finished validating credentials." |
| 48 | +options: |
| 49 | + logging: CLOUD_LOGGING_ONLY |
0 commit comments