Debian Codegraph @

internal/librariangen/run-librarian-release-init-test.sh

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 # Copyright 2025 Google LLC
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 # This script performs an integration test on the librarian CLI
17 # for the `release-init` command.
18
19 set -e # Exit immediately if a command exits with a non-zero status.
20
21 IMAGE_NAME="gcr.io/cloud-devrel-public-resources/librarian-go:infrastructure-public-image-latest"
22 LIBRARIANGEN_LOG=librarian-release-init.log
23 echoscip-shell system . . echo. "Cleaning up from last time: rm -f $LIBRARIANGEN_LOG"
24 rmscip-shell system . . rm. -f "$LIBRARIANGEN_LOG"
25
26 # --- Host Dependency Checks ---
27 if ! command -v "go" &> /dev/nullscip-shell filesystem . . `/dev/null`.;
28 then
29 echoscip-shell system . . echo. "Error: go not found in PATH. Please install it."
30 exit 1
31 fi
32 if ! command -v "git" &> /dev/nullscip-shell filesystem . . `/dev/null`.;
33 then
34 echoscip-shell system . . echo. "Error: git not found in PATH. Please install it."
35 exit 1
36 fi
37
38 # --- Setup ---
39 if [scip-shell system . . `[`. ! -d "$LIBRARIANGEN_GOOGLE_CLOUD_GO_DIR" ]; then
40 echoscip-shell system . . echo. "Error: LIBRARIANGEN_GOOGLE_CLOUD_GO_DIR is not set or not a directory."
41 exit 1
42 fi
43 echoscip-shell system . . echo. "Using google-cloud-go repo from $LIBRARIANGEN_GOOGLE_CLOUD_GO_DIR"
44 GOLDEN_REPO_DIR="$LIBRARIANGEN_GOOGLE_CLOUD_GO_DIR"
45
46 # --- Test Execution ---
47 echoscip-shell system . . echo. ""
48 echoscip-shell system . . echo. "--------------------------------------"
49 echoscip-shell system . . echo. "Running 'release-init' integration test..."
50 echoscip-shell system . . echo. "--------------------------------------"
51
52 # Reset the golden repo to a clean state before running the test.
53 (
54 echoscip-shell system . . echo. "--- Git Reset Summary (Pre-run) ---"
55 pushd "$GOLDEN_REPO_DIR" > /dev/nullscip-shell filesystem . . `/dev/null`.
56 gitscip-shell system . . git. reset --hard HEAD
57 gitscip-shell system . . git. clean -fd
58 popd > /dev/nullscip-shell filesystem . . `/dev/null`.
59 ) >> "$LIBRARIANGEN_LOG" 2>&1
60
61 # Execute
62 echoscip-shell system . . echo. "Running librarian release-init..."
63 goscip-shell system . . go. run github.com/googleapis/librarian/cmd/librarian@HEAD release-init \
64 --image="$IMAGE_NAME" \
65 --repo="$GOLDEN_REPO_DIR" \
66 --library=secretmanager >> "$LIBRARIANGEN_LOG" 2>&1
67
68
69 # --- Verify ---
70 echoscip-shell system . . echo. "Verifying output against golden repository..."
71
72 # Check the git status and diff to verify the changes.
73 (
74 echoscip-shell system . . echo. "--- Git Status Summary ---"
75 pushd "$GOLDEN_REPO_DIR" > /dev/nullscip-shell filesystem . . `/dev/null`.
76 gitscip-shell system . . git. add .
77 gitscip-shell system . . git. status
78 echoscip-shell system . . echo. "--- Git Diff Summary ---"
79 gitscip-shell system . . git. diff --staged
80 popd > /dev/nullscip-shell filesystem . . `/dev/null`.
81 ) >> "$LIBRARIANGEN_LOG" 2>&1
82
83
84 # A simple check to ensure some files were changed. A more robust check
85 # would involve comparing against a known-good diff.
86 if [scip-shell system . . `[`. -z "$(gitscip-shell system . . git. -C "$GOLDEN_REPO_DIR" status --porcelain)" ]; then
87 echoscip-shell system . . echo. "Error: No files were changed in the golden repository."
88 exit 1
89 fi
90
91 echoscip-shell system . . echo. "'release-init' integration test passed successfully."
92 echoscip-shell system . . echo. "Logs are available in: $LIBRARIANGEN_LOG"
93 echoscip-shell system . . echo. "To inspect changes, see the git status of: $GOLDEN_REPO_DIR"