Skip to content

Commit f5fd9e5

Browse files
committed
ci: add showcase version check workflow
A Go script and workflow are added to check that the showcase commit in librarian.yaml is in sync with the gapic-showcase.version property in java-showcase/gapic-showcase/pom.xml. Fixes googleapis/librarian#6200
1 parent fbb5889 commit f5fd9e5

2 files changed

Lines changed: 150 additions & 0 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
# https://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: Showcase Version Check
16+
17+
on:
18+
schedule:
19+
- cron: '30 3 * * *' # Run daily at 3:30 AM UTC
20+
workflow_dispatch: # Allow manual trigger
21+
pull_request:
22+
paths:
23+
- 'librarian.yaml'
24+
- 'java-showcase/gapic-showcase/pom.xml'
25+
- '.github/workflows/showcase-version-check.yaml'
26+
- '.github/scripts/verify-showcase-version.go'
27+
28+
jobs:
29+
check-version:
30+
runs-on: ubuntu-latest
31+
permissions:
32+
issues: write
33+
steps:
34+
- uses: actions/checkout@v4
35+
36+
- name: Extract showcase version from pom.xml
37+
id: extract_version
38+
shell: bash
39+
run: |
40+
version=$(mvn help:evaluate -f java-showcase/gapic-showcase/pom.xml -Dexpression=gapic-showcase.version -q -DforceStdout 2>/dev/null || true)
41+
if [ -z "$version" ]; then
42+
echo "Warning: Maven evaluation failed. Falling back to XML parsing of pom.xml..."
43+
version=$(grep -oE '<gapic-showcase\.version>[0-9]+\.[0-9]+\.[0-9]+</gapic-showcase\.version>' java-showcase/gapic-showcase/pom.xml | sed -E 's/<[^>]+>//g')
44+
fi
45+
if [ -z "$version" ]; then
46+
echo "Error: Could not find gapic-showcase.version in pom.xml"
47+
exit 1
48+
fi
49+
echo "version=$version" >> "$GITHUB_OUTPUT"
50+
51+
- name: Extract showcase commit from librarian.yaml
52+
id: extract_commit
53+
shell: bash
54+
run: |
55+
commit=$(grep -A 1 "showcase:" librarian.yaml | grep "commit:" | awk '{print $2}')
56+
if [ -z "$commit" ]; then
57+
echo "Error: Could not find showcase commit in librarian.yaml"
58+
exit 1
59+
fi
60+
echo "commit=$commit" >> "$GITHUB_OUTPUT"
61+
62+
- name: Set up Go
63+
uses: actions/setup-go@v5
64+
with:
65+
go-version: '1.24'
66+
67+
- name: Verify showcase version and commit match
68+
run: |
69+
go run .github/scripts/verify-showcase-version.go \
70+
-version "${{ steps.extract_version.outputs.version }}" \
71+
-commit "${{ steps.extract_commit.outputs.commit }}"
72+
73+
- name: Create issue on failure
74+
if: failure()
75+
env:
76+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77+
run: |
78+
gh issue create \
79+
-R "${{ github.repository }}" \
80+
-t "Showcase Version Check Failure" \
81+
-b "The Showcase Version Check workflow has failed. Please check the logs at ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} for details."

0 commit comments

Comments
 (0)