|
| 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 | +package main |
| 16 | + |
| 17 | +import ( |
| 18 | + "flag" |
| 19 | + "fmt" |
| 20 | + "os" |
| 21 | + "os/exec" |
| 22 | + "strings" |
| 23 | +) |
| 24 | + |
| 25 | +func main() { |
| 26 | + showcaseVersion := flag.String("version", "", "The showcase version from pom.xml (e.g. 0.39.0)") |
| 27 | + showcaseCommit := flag.String("commit", "", "The showcase commit from librarian.yaml (e.g. 328bec...)") |
| 28 | + flag.Parse() |
| 29 | + |
| 30 | + if *showcaseVersion == "" || *showcaseCommit == "" { |
| 31 | + fmt.Fprintf(os.Stderr, "Error: Both -version and -commit flags must be provided\n") |
| 32 | + os.Exit(1) |
| 33 | + } |
| 34 | + |
| 35 | + tagName := "v" + *showcaseVersion |
| 36 | + remoteURL := "https://github.com/googleapis/gapic-showcase.git" |
| 37 | + |
| 38 | + fmt.Printf("Showcase version: %s\n", *showcaseVersion) |
| 39 | + fmt.Printf("Showcase commit: %s\n", *showcaseCommit) |
| 40 | + |
| 41 | + // Query the remote gapic-showcase repository for the commit hash of the tag v{version}. |
| 42 | + gitCommand := exec.Command("git", "ls-remote", remoteURL, "refs/tags/"+tagName) |
| 43 | + outputBytes, err := gitCommand.Output() |
| 44 | + if err != nil { |
| 45 | + fmt.Fprintf(os.Stderr, "Error running git ls-remote: %v\n", err) |
| 46 | + os.Exit(1) |
| 47 | + } |
| 48 | + |
| 49 | + outputLine := strings.TrimSpace(string(outputBytes)) |
| 50 | + if outputLine == "" { |
| 51 | + fmt.Fprintf(os.Stderr, "Error: Tag %s not found on remote %s\n", tagName, remoteURL) |
| 52 | + os.Exit(1) |
| 53 | + } |
| 54 | + |
| 55 | + outputFields := strings.Fields(outputLine) |
| 56 | + if len(outputFields) < 2 { |
| 57 | + fmt.Fprintf(os.Stderr, "Error parsing git ls-remote output: %q\n", outputLine) |
| 58 | + os.Exit(1) |
| 59 | + } |
| 60 | + expectedCommit := strings.TrimSpace(outputFields[0]) |
| 61 | + fmt.Printf("Expected commit for tag %s: %s\n", tagName, expectedCommit) |
| 62 | + |
| 63 | + if *showcaseCommit != expectedCommit { |
| 64 | + fmt.Fprintf(os.Stderr, "Mismatch: librarian.yaml has commit %q, but tag %q is at commit %q\n", *showcaseCommit, tagName, expectedCommit) |
| 65 | + os.Exit(1) |
| 66 | + } |
| 67 | + |
| 68 | + fmt.Println("Showcase version and commit are in sync!") |
| 69 | +} |
0 commit comments