Skip to content

Commit 2d88ae9

Browse files
authored
feat: add automation go script for triggering all configured repositories (#1687)
Usage: ``` go run github.com/googleapis/librarian/cmd/automation@<tag-or-ref> \ --command=generate \ --project=<project-id> ``` Fixes #1612 Fixes #1571
1 parent cb623c0 commit 2d88ae9

File tree

13 files changed

+784
-30
lines changed

13 files changed

+784
-30
lines changed

cmd/automation/main.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2024 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+
// Librarian manages Google API client libraries by automating onboarding,
16+
// regeneration, and release. It runs language‑agnostic workflows while
17+
// delegating language‑specific tasks—such as code generation, building, and
18+
// testing—to Docker images.
19+
package main
20+
21+
import (
22+
"log"
23+
"os"
24+
25+
"github.com/googleapis/librarian/internal/automation"
26+
)
27+
28+
func main() {
29+
if err := automation.Run(os.Args[1:]); err != nil {
30+
log.Fatal(err)
31+
}
32+
}

go.mod

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@ module github.com/googleapis/librarian
33
go 1.24.4
44

55
require (
6+
cloud.google.com/go/cloudbuild v1.22.3
67
cloud.google.com/go/iam v1.5.2
78
cloud.google.com/go/longrunning v0.6.7
89
github.com/cbroglie/mustache v1.4.0
910
github.com/go-git/go-git/v5 v5.16.1
1011
github.com/google/go-cmp v0.7.0
1112
github.com/google/go-github/v69 v69.2.0
13+
github.com/googleapis/gax-go/v2 v2.15.0
1214
github.com/iancoleman/strcase v0.3.0
1315
github.com/pb33f/libopenapi v0.25.0
1416
github.com/pelletier/go-toml/v2 v2.2.4
1517
github.com/walle/targz v0.0.0-20140417120357-57fe4206da5a
1618
github.com/yuin/goldmark v1.7.13
19+
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
1720
google.golang.org/genproto v0.0.0-20250728155136-f173205681a0
1821
google.golang.org/genproto/googleapis/api v0.0.0-20250728155136-f173205681a0
1922
google.golang.org/genproto/googleapis/rpc v0.0.0-20250728155136-f173205681a0
@@ -22,6 +25,10 @@ require (
2225
)
2326

2427
require (
28+
cloud.google.com/go v0.120.0 // indirect
29+
cloud.google.com/go/auth v0.16.3 // indirect
30+
cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect
31+
cloud.google.com/go/compute/metadata v0.7.0 // indirect
2532
dario.cat/mergo v1.0.0 // indirect
2633
github.com/Microsoft/go-winio v0.6.2 // indirect
2734
github.com/ProtonMail/go-crypto v1.1.6 // indirect
@@ -31,10 +38,15 @@ require (
3138
github.com/cyphar/filepath-securejoin v0.4.1 // indirect
3239
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
3340
github.com/emirpasic/gods v1.18.1 // indirect
41+
github.com/felixge/httpsnoop v1.0.4 // indirect
3442
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
3543
github.com/go-git/go-billy/v5 v5.6.2 // indirect
44+
github.com/go-logr/logr v1.4.3 // indirect
45+
github.com/go-logr/stdr v1.2.2 // indirect
3646
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
3747
github.com/google/go-querystring v1.1.0 // indirect
48+
github.com/google/s2a-go v0.1.9 // indirect
49+
github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
3850
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
3951
github.com/kevinburke/ssh_config v1.2.0 // indirect
4052
github.com/mailru/easyjson v0.7.7 // indirect
@@ -45,10 +57,20 @@ require (
4557
github.com/speakeasy-api/jsonpath v0.6.2 // indirect
4658
github.com/wk8/go-ordered-map/v2 v2.1.9-0.20240815153524-6ea36470d1bd // indirect
4759
github.com/xanzy/ssh-agent v0.3.3 // indirect
60+
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
61+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.61.0 // indirect
62+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 // indirect
63+
go.opentelemetry.io/otel v1.36.0 // indirect
64+
go.opentelemetry.io/otel/metric v1.36.0 // indirect
65+
go.opentelemetry.io/otel/trace v1.36.0 // indirect
4866
golang.org/x/crypto v0.40.0 // indirect
4967
golang.org/x/net v0.42.0 // indirect
68+
golang.org/x/oauth2 v0.30.0 // indirect
69+
golang.org/x/sync v0.16.0 // indirect
5070
golang.org/x/sys v0.34.0 // indirect
5171
golang.org/x/text v0.27.0 // indirect
72+
golang.org/x/time v0.12.0 // indirect
73+
google.golang.org/api v0.244.0 // indirect
5274
google.golang.org/grpc v1.74.2 // indirect
5375
gopkg.in/warnings.v0 v0.1.2 // indirect
5476
)

go.sum

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
cloud.google.com/go v0.120.0 h1:wc6bgG9DHyKqF5/vQvX1CiZrtHnxJjBlKUyF9nP6meA=
2+
cloud.google.com/go v0.120.0/go.mod h1:/beW32s8/pGRuj4IILWQNd4uuebeT4dkOhKmkfit64Q=
3+
cloud.google.com/go/auth v0.16.3 h1:kabzoQ9/bobUmnseYnBO6qQG7q4a/CffFRlJSxv2wCc=
4+
cloud.google.com/go/auth v0.16.3/go.mod h1:NucRGjaXfzP1ltpcQ7On/VTZ0H4kWB5Jy+Y9Dnm76fA=
5+
cloud.google.com/go/auth/oauth2adapt v0.2.8 h1:keo8NaayQZ6wimpNSmW5OPc283g65QNIiLpZnkHRbnc=
6+
cloud.google.com/go/auth/oauth2adapt v0.2.8/go.mod h1:XQ9y31RkqZCcwJWNSx2Xvric3RrU88hAYYbjDWYDL+c=
7+
cloud.google.com/go/cloudbuild v1.22.3 h1:FnbWf1FjtyrPLVqTb5wYX8eMgrbC5w0BPhpud9fAIu8=
8+
cloud.google.com/go/cloudbuild v1.22.3/go.mod h1:Z9gdGjZIJjMdlHR6YxGOTOQlBfgA1oMHHSyXHo6Knkg=
9+
cloud.google.com/go/compute/metadata v0.7.0 h1:PBWF+iiAerVNe8UCHxdOt6eHLVc3ydFeOCw78U8ytSU=
10+
cloud.google.com/go/compute/metadata v0.7.0/go.mod h1:j5MvL9PprKL39t166CoB1uVHfQMs4tFQZZcKwksXUjo=
111
cloud.google.com/go/iam v1.5.2 h1:qgFRAGEmd8z6dJ/qyEchAuL9jpswyODjA2lS+w234g8=
212
cloud.google.com/go/iam v1.5.2/go.mod h1:SE1vg0N81zQqLzQEwxL2WI6yhetBdbNQuTvIKCSkUHE=
313
cloud.google.com/go/longrunning v0.6.7 h1:IGtfDWHhQCgCjwQjV9iiLnUta9LBCo8R9QmAFsS/PrE=
@@ -31,6 +41,8 @@ github.com/elazarl/goproxy v1.7.2 h1:Y2o6urb7Eule09PjlhQRGNsqRfPmYI3KKQLFpCAV3+o
3141
github.com/elazarl/goproxy v1.7.2/go.mod h1:82vkLNir0ALaW14Rc399OTTjyNREgmdL2cVoIbS6XaE=
3242
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
3343
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
44+
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
45+
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
3446
github.com/gliderlabs/ssh v0.3.8 h1:a4YXD1V7xMF9g5nTkdfnja3Sxy1PVDCj1Zg4Wb8vY6c=
3547
github.com/gliderlabs/ssh v0.3.8/go.mod h1:xYoytBv1sV0aL3CavoDuJIQNURXkkfPA/wxQ1pL1fAU=
3648
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=
@@ -41,6 +53,7 @@ github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMj
4153
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII=
4254
github.com/go-git/go-git/v5 v5.16.1 h1:TuxMBWNL7R05tXsUGi0kh1vi4tq0WfXNLlIrAkXG1k8=
4355
github.com/go-git/go-git/v5 v5.16.1/go.mod h1:4Ge4alE/5gPs30F2H1esi2gPd69R0C39lolkucHBOp8=
56+
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
4457
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
4558
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
4659
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
@@ -56,8 +69,14 @@ github.com/google/go-github/v69 v69.2.0 h1:wR+Wi/fN2zdUx9YxSmYE0ktiX9IAR/BeePzea
5669
github.com/google/go-github/v69 v69.2.0/go.mod h1:xne4jymxLR6Uj9b7J7PyTpkMYstEMMwGZa0Aehh1azM=
5770
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
5871
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
72+
github.com/google/s2a-go v0.1.9 h1:LGD7gtMgezd8a/Xak7mEWL0PjoTQFvpRudN895yqKW0=
73+
github.com/google/s2a-go v0.1.9/go.mod h1:YA0Ei2ZQL3acow2O62kdp9UlnvMmU7kA6Eutn0dXayM=
5974
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
6075
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
76+
github.com/googleapis/enterprise-certificate-proxy v0.3.6 h1:GW/XbdyBFQ8Qe+YAmFU9uHLo7OnF5tL52HFAgMmyrf4=
77+
github.com/googleapis/enterprise-certificate-proxy v0.3.6/go.mod h1:MkHOF77EYAE7qfSuSS9PU6g4Nt4e11cnsDUowfwewLA=
78+
github.com/googleapis/gax-go/v2 v2.15.0 h1:SyjDc1mGgZU5LncH8gimWo9lW1DtIfPibOG81vgd/bo=
79+
github.com/googleapis/gax-go/v2 v2.15.0/go.mod h1:zVVkkxAQHa1RQpg9z2AUCMnKhi0Qld9rcmyfL1OZhoc=
6180
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
6281
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
6382
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
@@ -111,6 +130,10 @@ github.com/yuin/goldmark v1.7.13 h1:GPddIs617DnBLFFVJFgpo1aBfe/4xcvMc3SB5t/D0pA=
111130
github.com/yuin/goldmark v1.7.13/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg=
112131
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
113132
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
133+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.61.0 h1:q4XOmH/0opmeuJtPsbFNivyl7bCt7yRBbeEm2sC/XtQ=
134+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.61.0/go.mod h1:snMWehoOh2wsEwnvvwtDyFCxVeDAODenXHtn5vzrKjo=
135+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 h1:F7Jx+6hwnZ41NSFTO5q4LYDtJRXBf2PD0rNBkeB/lus=
136+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0/go.mod h1:UHB22Z8QsdRDrnAtX4PntOl36ajSxcdUMt1sF7Y6E7Q=
114137
go.opentelemetry.io/otel v1.36.0 h1:UumtzIklRBY6cI/lllNZlALOF5nNIzJVb16APdvgTXg=
115138
go.opentelemetry.io/otel v1.36.0/go.mod h1:/TcFMXYjyRNh8khOAO9ybYkqaDBb/70aVwkNML4pP8E=
116139
go.opentelemetry.io/otel/metric v1.36.0 h1:MoWPKVhQvJ+eeXWHFBOPoBOi20jh6Iq2CcCREuTYufE=
@@ -129,6 +152,10 @@ golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbR
129152
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
130153
golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=
131154
golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
155+
golang.org/x/oauth2 v0.30.0 h1:dnDm7JmhM45NNpd8FDDeLhK6FwqbOf4MLCM9zb1BOHI=
156+
golang.org/x/oauth2 v0.30.0/go.mod h1:B++QgG3ZKulg6sRPGD/mqlHQs5rB3Ml9erfeDY7xKlU=
157+
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
158+
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
132159
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
133160
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
134161
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -143,8 +170,12 @@ golang.org/x/term v0.33.0/go.mod h1:s18+ql9tYWp1IfpV9DmCtQDDSRBUjKaw9M1eAv5UeF0=
143170
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
144171
golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=
145172
golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=
173+
golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
174+
golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
146175
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
147176
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
177+
google.golang.org/api v0.244.0 h1:lpkP8wVibSKr++NCD36XzTk/IzeKJ3klj7vbj+XU5pE=
178+
google.golang.org/api v0.244.0/go.mod h1:dMVhVcylamkirHdzEBAIQWUCgqY885ivNeZYd7VAVr8=
148179
google.golang.org/genproto v0.0.0-20250728155136-f173205681a0 h1:btBcgujH2+KIWEfz0s7Cdtt9R7hpwM4SAEXAdXf/ddw=
149180
google.golang.org/genproto v0.0.0-20250728155136-f173205681a0/go.mod h1:Q4yZQ3kmmIyg6HsMjCGx2vQ8gzN+dntaPmFWz6Zj0fo=
150181
google.golang.org/genproto/googleapis/api v0.0.0-20250728155136-f173205681a0 h1:0UOBWO4dC+e51ui0NFKSPbkHHiQ4TmrEfEZMLDyRmY8=

infra/prod/generate-worker.yaml

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,15 @@
1515
# This runs the `librarian generate` command with a provided repository,
1616
# secret name, and optional library ID
1717
steps:
18-
- name: gcr.io/cloud-builders/git
19-
id: clone-language-repo
20-
waitFor: ['-']
18+
- name: golang:1.24.4
19+
id: generate-dispatcher
20+
entrypoint: go
2121
args:
22-
- 'clone'
23-
- '--depth=1'
24-
- https://github.com/googleapis/$_REPOSITORY
25-
- name: gcr.io/cloud-builders/git
26-
id: clone-googleapis
27-
waitFor: ['-']
28-
args:
29-
- 'clone'
30-
- '--single-branch'
31-
- '--branch=master'
32-
- https://github.com/googleapis/googleapis
33-
- name: 'us-central1-docker.pkg.dev/cloud-sdk-production-pipeline/images-prod/librarian@sha256:dac8d6d46eefecde4241c88348315e6162ccd0d39e84db2b98e4da7393f65c29'
34-
id: generate
35-
waitFor: ['clone-language-repo', 'clone-googleapis']
36-
args:
37-
- 'generate'
38-
- '-repo'
39-
- '/workspace/$_REPOSITORY'
40-
- '-library'
41-
- $_LIBRARY_ID
42-
- '-api-source'
43-
- '/workspace/googleapis'
44-
secretEnv: ['LIBRARIAN_GITHUB_TOKEN']
45-
tags: ['generate-$_REPOSITORY']
22+
- 'run'
23+
- './cmd/automation'
24+
- '--project=$PROJECT_ID'
25+
- '--command=generate'
26+
tags: ['generate-dispatcher']
4627
availableSecrets:
47-
secretManager:
48-
- versionName: projects/$PROJECT_ID/secrets/$_GITHUB_TOKEN_SECRET_NAME/versions/latest
49-
env: 'LIBRARIAN_GITHUB_TOKEN'
5028
options:
5129
logging: CLOUD_LOGGING_ONLY

infra/prod/generate.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
#
15+
# This runs the `librarian generate` command with a provided repository,
16+
# secret name, and optional library ID
17+
steps:
18+
- name: gcr.io/cloud-builders/git
19+
id: clone-language-repo
20+
waitFor: ['-']
21+
args:
22+
- 'clone'
23+
- '--depth=1'
24+
- https://github.com/googleapis/$_REPOSITORY
25+
- name: gcr.io/cloud-builders/git
26+
id: clone-googleapis
27+
waitFor: ['-']
28+
args:
29+
- 'clone'
30+
- '--single-branch'
31+
- '--branch=master'
32+
- https://github.com/googleapis/googleapis
33+
- name: 'us-central1-docker.pkg.dev/cloud-sdk-production-pipeline/images-prod/librarian@sha256:dac8d6d46eefecde4241c88348315e6162ccd0d39e84db2b98e4da7393f65c29'
34+
id: generate
35+
waitFor: ['clone-language-repo', 'clone-googleapis']
36+
args:
37+
- 'generate'
38+
- '-repo'
39+
- '/workspace/$_REPOSITORY'
40+
- '-library'
41+
- $_LIBRARY_ID
42+
- '-api-source'
43+
- '/workspace/googleapis'
44+
secretEnv: ['LIBRARIAN_GITHUB_TOKEN']
45+
tags: ['generate-$_REPOSITORY']
46+
availableSecrets:
47+
secretManager:
48+
- versionName: projects/$PROJECT_ID/secrets/$_GITHUB_TOKEN_SECRET_NAME/versions/latest
49+
env: 'LIBRARIAN_GITHUB_TOKEN'
50+
options:
51+
logging: CLOUD_LOGGING_ONLY

internal/automation/cli.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
// 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+
package automation
16+
17+
import (
18+
"context"
19+
"flag"
20+
"log/slog"
21+
)
22+
23+
// Run parses the command line arguments and triggers the specified command.
24+
func Run(args []string) error {
25+
ctx := context.Background()
26+
options, err := parseFlags(args)
27+
if err != nil {
28+
slog.Error("Error parsing command", slog.Any("err", err))
29+
return err
30+
}
31+
32+
err = RunCommand(ctx, options.Command, options.ProjectId)
33+
if err != nil {
34+
slog.Error("Error running command", slog.Any("err", err))
35+
return err
36+
}
37+
return nil
38+
}
39+
40+
type runOptions struct {
41+
Command string
42+
ProjectId string
43+
}
44+
45+
func parseFlags(args []string) (*runOptions, error) {
46+
flagSet := flag.NewFlagSet("dispatcher", flag.ContinueOnError)
47+
projectId := flagSet.String("project", "cloud-sdk-librarian-prod", "GCP project ID")
48+
command := flagSet.String("command", "generate", "The librarian command to run")
49+
err := flagSet.Parse(args)
50+
if err != nil {
51+
return nil, err
52+
}
53+
return &runOptions{
54+
ProjectId: *projectId,
55+
Command: *command,
56+
}, nil
57+
}

0 commit comments

Comments
 (0)