Skip to content

Commit 53bf581

Browse files
authored
feat: bring legacy-librarian into main (#3564)
This is a one-by-one manual cherry pick of all of the commits that are ahead of main on legacy-librarian. Because of file renames I could not use a simple git cherry-pick for the operations so I decided to do it all by hand, even if there where no conflicts. The one set of files I did not update with these commits were the `infra/prod/*.yaml` files. These files should point to latest once we cut a new release and not some old commit from another branch. This means before we cut over the jobs to run off of main we will want to do a tagged release. Updates: #3472
1 parent 2f71391 commit 53bf581

File tree

19 files changed

+351
-56
lines changed

19 files changed

+351
-56
lines changed

infra/imagebuilders/cli/Dockerfile

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,28 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
FROM golang:1.25.3 AS build
15+
# This stage builds the librariangen binary using the MOSS-compliant base image.
16+
FROM marketplace.gcr.io/google/debian12@sha256:326ccf35aa72f7cc8cbd25b69e819a81c5fd9ed675c6c9ffb51f3214a64f23cf AS builder
17+
18+
# Set environment variables for tool versions for easy updates.
19+
ENV GO_VERSION=1.25.3
20+
21+
# Install build dependencies.
22+
RUN apt-get update && \
23+
apt-get install -y \
24+
build-essential \
25+
ca-certificates \
26+
curl \
27+
git \
28+
wget && \
29+
rm -rf /var/lib/apt/lists/*
30+
31+
# Install the specific Go version required for compatibility.
32+
RUN wget https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz -O go.tar.gz && \
33+
tar -C /usr/local -xzf go.tar.gz && \
34+
rm go.tar.gz
35+
ENV PATH=/usr/local/go/bin:$PATH
36+
RUN go version
1637

1738
WORKDIR /src
1839

@@ -27,7 +48,7 @@ RUN CGO_ENABLED=0 GOOS=linux go build ./cmd/librarian
2748
# while in Docker. Note that for this to work, *this*
2849
# docker image should be run with
2950
# -v /var/run/docker.sock:/var/run/docker.sock
30-
FROM golang:1.25.3
51+
FROM marketplace.gcr.io/google/debian12@sha256:326ccf35aa72f7cc8cbd25b69e819a81c5fd9ed675c6c9ffb51f3214a64f23cf
3152
WORKDIR /app
3253

3354
# From https://docs.docker.com/engine/install/debian/
@@ -58,9 +79,9 @@ RUN echo \
5879
# https://docs.docker.com/engine/release-notes/29/#2900
5980
RUN apt update && \
6081
apt-get -y install \
61-
docker-ce=5:28.5.2-1~debian.13~trixie \
62-
docker-ce-cli=5:28.5.2-1~debian.13~trixie \
63-
docker-ce-rootless-extras=5:28.5.2-1~debian.13~trixie && \
82+
docker-ce=5:27.1.1-1~debian.12~bookworm \
83+
docker-ce-cli=5:27.1.1-1~debian.12~bookworm \
84+
docker-ce-rootless-extras=5:27.1.1-1~debian.12~bookworm && \
6485
rm -rf /var/lib/apt/lists/*
6586

6687
# Add the Google Cloud SDK distribution URI as a package source
@@ -72,5 +93,5 @@ RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.
7293
# Install the gcloud CLI
7394
RUN apt-get update && apt-get install -y google-cloud-sdk
7495

75-
COPY --from=build /src/librarian .
96+
COPY --from=builder /src/librarian .
7697
ENTRYPOINT ["/app/librarian"]

infra/imagebuilders/cloudbuild-exitgate-deprecated.yaml

Lines changed: 0 additions & 26 deletions
This file was deleted.

infra/imagebuilders/container/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
FROM marketplace.gcr.io/google/ubuntu2404 AS builder
15+
# This stage builds the librariangen binary using the MOSS-compliant base image.
16+
FROM marketplace.gcr.io/google/debian12@sha256:326ccf35aa72f7cc8cbd25b69e819a81c5fd9ed675c6c9ffb51f3214a64f23cf AS builder
1617

1718
RUN apt-get update && \
1819
apt-get install -y --no-install-recommends \

infra/imagebuilders/container/run.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414
# limitations under the License.
1515

1616
echo "in release container"
17-
cat /librarian/release-init-request.json
17+
cat /librarian/release-stage-request.json
1818

1919
ls -al /librarian
2020
ls -al /repo
2121
ls -al /output
2222

23-
new_version=$(jq -r '.libraries[0].version' /librarian/release-init-request.json)
23+
new_version=$(jq -r '.libraries[0].version' /librarian/release-stage-request.json)
2424
echo "release version: ${new_version}"
25-
mkdir /output/internal/
25+
mkdir -p /output/internal/cli/
2626
echo "${new_version}" > /output/internal/cli/version.txt
2727

2828
ls -al /output
2929

3030
echo "writing empty response"
31-
echo "{}" > /librarian/release-init-response.json
31+
echo "{}" > /librarian/release-stage-response.json

infra/imagebuilders/dispatcher/Dockerfile

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,28 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
FROM golang:1.25.3 AS build
14+
15+
# This stage builds the librariangen binary using the MOSS-compliant base image.
16+
FROM marketplace.gcr.io/google/debian12@sha256:326ccf35aa72f7cc8cbd25b69e819a81c5fd9ed675c6c9ffb51f3214a64f23cf AS builder
17+
18+
# Set environment variables for tool versions for easy updates.
19+
ENV GO_VERSION=1.25.3
20+
21+
# Install build dependencies.
22+
RUN apt-get update && \
23+
apt-get install -y \
24+
build-essential \
25+
ca-certificates \
26+
curl \
27+
wget && \
28+
rm -rf /var/lib/apt/lists/*
29+
30+
# Install the specific Go version required for compatibility.
31+
RUN wget https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz -O go.tar.gz && \
32+
tar -C /usr/local -xzf go.tar.gz && \
33+
rm go.tar.gz
34+
ENV PATH=/usr/local/go/bin:$PATH
35+
RUN go version
1536

1637
WORKDIR /src
1738

@@ -22,9 +43,8 @@ RUN go mod download
2243
COPY . .
2344
RUN CGO_ENABLED=0 GOOS=linux go build ./cmd/automation
2445

25-
FROM golang:1.25.3
26-
46+
FROM marketplace.gcr.io/google/debian12@sha256:326ccf35aa72f7cc8cbd25b69e819a81c5fd9ed675c6c9ffb51f3214a64f23cf
2747
WORKDIR /app
2848

29-
COPY --from=build /src/automation .
49+
COPY --from=builder /src/automation .
3050
ENTRYPOINT [ "/app/automation" ]

infra/prod/generate.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,5 @@ availableSecrets:
7272
env: 'LIBRARIAN_GITHUB_TOKEN'
7373
options:
7474
logging: CLOUD_LOGGING_ONLY
75+
machineType: 'E2_HIGHCPU_8'
7576
timeout: 10h
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
steps:
15+
- id: get-librarian-image-sha
16+
name: bash
17+
args:
18+
- '-c'
19+
- |
20+
wget https://github.com/mikefarah/yq/releases/download/v4.48.2/yq_linux_amd64 -O /usr/local/bin/yq
21+
chmod +x /usr/local/bin/yq
22+
yq -r '.librarian-image-sha' internal/automation/prod/repositories.yaml > /workspace/librarian_image_sha.txt
23+
cat /workspace/librarian_image_sha.txt
24+
- id: test-generate
25+
name: gcr.io/cloud-builders/docker
26+
entrypoint: bash
27+
waitFor: ['get-librarian-image-sha']
28+
args:
29+
- -c
30+
- |
31+
docker run \
32+
--rm \
33+
us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/librarian@$(cat /workspace/librarian_image_sha.txt) \
34+
generate --help
35+
- id: test-release-stage
36+
name: gcr.io/cloud-builders/docker
37+
entrypoint: bash
38+
waitFor: ['get-librarian-image-sha']
39+
args:
40+
- -c
41+
- |
42+
docker run \
43+
--rm \
44+
us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/librarian@$(cat /workspace/librarian_image_sha.txt) \
45+
release stage --help
46+
- id: test-release-tag
47+
name: gcr.io/cloud-builders/docker
48+
entrypoint: bash
49+
waitFor: ['get-librarian-image-sha']
50+
args:
51+
- -c
52+
- |
53+
docker run \
54+
--rm \
55+
us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/librarian@$(cat /workspace/librarian_image_sha.txt) \
56+
release tag --help
57+
options:
58+
logging: CLOUD_LOGGING_ONLY

internal/legacylibrarian/legacyautomation/prod/repositories.yaml

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
librarian-image-sha: sha256:8ae52838e466022dd701cab8c3f002cb727b3e0e5688864b3d0d68f645541035
1+
librarian-image-sha: sha256:41df234d423cfa86db99d1610f4a463d3150879b5fbb5fe3faeaf31a2a731d3e
22
repositories:
33
- name: "gapic-generator-go"
44
full-name: https://github.com/googleapis/gapic-generator-go
@@ -49,9 +49,9 @@ repositories:
4949
github-token-secret-name: "google-resumable-media-python-github-token"
5050
supported-commands:
5151
- publish-release
52-
- name: "python-aiplatform"
53-
full-name: https://github.com/googleapis/python-aiplatform
54-
github-token-secret-name: "python-aiplatform-github-token"
52+
- name: "proto-plus-python"
53+
full-name: https://github.com/googleapis/proto-plus-python
54+
github-token-secret-name: "proto-plus-python-github-token"
5555
supported-commands:
5656
- publish-release
5757
- name: "python-api-core"
@@ -84,11 +84,21 @@ repositories:
8484
github-token-secret-name: "python-bigquery-sqlalchemy-github-token"
8585
supported-commands:
8686
- publish-release
87+
- name: "python-bigtable"
88+
full-name: https://github.com/googleapis/python-bigtable
89+
github-token-secret-name: "python-bigtable-github-token"
90+
supported-commands:
91+
- publish-release
8792
- name: "python-cloud-core"
8893
full-name: https://github.com/googleapis/python-cloud-core
8994
github-token-secret-name: "python-cloud-core-github-token"
9095
supported-commands:
9196
- publish-release
97+
- name: "python-crc32c"
98+
full-name: https://github.com/googleapis/python-crc32c
99+
github-token-secret-name: "python-crc32c-github-token"
100+
supported-commands:
101+
- publish-release
92102
- name: "python-datastore"
93103
full-name: https://github.com/googleapis/python-datastore
94104
github-token-secret-name: "python-datastore-github-token"
@@ -114,6 +124,11 @@ repositories:
114124
github-token-secret-name: "python-firestore-github-token"
115125
supported-commands:
116126
- publish-release
127+
- name: "python-logging"
128+
full-name: https://github.com/googleapis/python-logging
129+
github-token-secret-name: "python-logging-github-token"
130+
supported-commands:
131+
- publish-release
117132
- name: "python-ndb"
118133
full-name: https://github.com/googleapis/python-ndb
119134
github-token-secret-name: "python-ndb-github-token"
@@ -124,11 +139,21 @@ repositories:
124139
github-token-secret-name: "python-pubsub-github-token"
125140
supported-commands:
126141
- publish-release
142+
- name: "python-pubsublite"
143+
full-name: https://github.com/googleapis/python-pubsublite
144+
github-token-secret-name: "python-pubsublite-github-token"
145+
supported-commands:
146+
- publish-release
127147
- name: "python-runtimeconfig"
128148
full-name: https://github.com/googleapis/python-runtimeconfig
129149
github-token-secret-name: "python-runtimeconfig-github-token"
130150
supported-commands:
131151
- publish-release
152+
- name: "python-spanner"
153+
full-name: https://github.com/googleapis/python-spanner
154+
github-token-secret-name: "python-spanner-github-token"
155+
supported-commands:
156+
- publish-release
132157
- name: "python-spanner-django"
133158
full-name: https://github.com/googleapis/python-spanner-django
134159
github-token-secret-name: "python-spanner-django-github-token"

internal/legacylibrarian/legacyconfig/state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func (c *Commit) IsBulkCommit() bool {
168168

169169
var (
170170
libraryIDRegex = regexp.MustCompile(`^[a-zA-Z0-9/._-]+$`)
171-
semverRegex = regexp.MustCompile(`^v?\d+\.\d+\.\d+$`)
171+
semverRegex = regexp.MustCompile(`^v?\d+\.\d+\.\d+(?:-([a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*))?$`)
172172
hexRegex = regexp.MustCompile("^[a-fA-F0-9]+$")
173173
tagFormatRegex = regexp.MustCompile(`{[^{}]*}`)
174174
)

internal/legacylibrarian/legacylibrarian/command.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,15 +374,20 @@ func getDirectoryFilenames(dir string) ([]string, error) {
374374
// It uses the GitHub client to create a PR with the specified branch, title, and
375375
// description to the repository.
376376
func commitAndPush(ctx context.Context, info *commitInfo) error {
377+
repo := info.languageRepo
377378
if !info.push && !info.commit {
378379
slog.Info("push flag and commit flag are not specified, skipping committing")
380+
isClean, err := repo.IsClean()
381+
if err != nil {
382+
return fmt.Errorf("failed to check if repo is clean: %w", err)
383+
}
384+
if isClean {
385+
slog.Info("no changes to commit, skipping pull request body creation.")
386+
return nil
387+
}
379388
return writePRBody(info)
380389
}
381390

382-
repo := info.languageRepo
383-
if err := repo.AddAll(); err != nil {
384-
return fmt.Errorf("failed to add all files to git: %w", err)
385-
}
386391
isClean, err := repo.IsClean()
387392
if err != nil {
388393
return fmt.Errorf("failed to check if repo is clean: %w", err)
@@ -393,6 +398,10 @@ func commitAndPush(ctx context.Context, info *commitInfo) error {
393398
return nil
394399
}
395400

401+
if err := repo.AddAll(); err != nil {
402+
return fmt.Errorf("failed to add all files to git: %w", err)
403+
}
404+
396405
datetimeNow := formatTimestamp(time.Now())
397406
branch := fmt.Sprintf("librarian-%s", datetimeNow)
398407
if err := repo.CreateBranchAndCheckout(branch); err != nil {

0 commit comments

Comments
 (0)