Skip to content

Commit 3d1f537

Browse files
authored
1 parent c959aea commit 3d1f537

File tree

9 files changed

+54
-30
lines changed

9 files changed

+54
-30
lines changed

infra/prod/generate.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ steps:
4747
- '--single-branch'
4848
- '--branch=master'
4949
- https://github.com/googleapis/googleapis
50-
- name: 'us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/librarian@sha256:8ae52838e466022dd701cab8c3f002cb727b3e0e5688864b3d0d68f645541035'
50+
- name: 'us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/librarian@$_IMAGE_SHA'
5151
id: generate
5252
waitFor: ['configure-language-repo-email', 'clone-googleapis']
5353
dir: tmp

infra/prod/publish-release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ steps:
2626
- '--single-branch'
2727
- '--branch=$_BRANCH'
2828
- $_FULL_REPOSITORY
29-
- name: 'us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/librarian@sha256:8ae52838e466022dd701cab8c3f002cb727b3e0e5688864b3d0d68f645541035'
29+
- name: 'us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/librarian@$_IMAGE_SHA'
3030
id: publish-release
3131
waitFor: ['clone-language-repo']
3232
args:

infra/prod/stage-release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ steps:
4141
- 'config'
4242
- 'user.email'
4343
44-
- name: 'us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/librarian@sha256:8ae52838e466022dd701cab8c3f002cb727b3e0e5688864b3d0d68f645541035'
44+
- name: 'us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/librarian@$_IMAGE_SHA'
4545
id: stage-release
4646
waitFor: ['configure-language-repo-email']
4747
dir: tmp

infra/prod/update-image.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ steps:
4747
- '--single-branch'
4848
- '--branch=master'
4949
- https://github.com/googleapis/googleapis
50-
- name: 'us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/librarian@sha256:8ae52838e466022dd701cab8c3f002cb727b3e0e5688864b3d0d68f645541035'
50+
- name: 'us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/librarian@$_IMAGE_SHA'
5151
id: update-image
5252
waitFor: ['configure-language-repo-email', 'clone-googleapis']
5353
dir: tmp

internal/automation/prod/repositories.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
librarian-image-sha: sha256:8ae52838e466022dd701cab8c3f002cb727b3e0e5688864b3d0d68f645541035
12
repositories:
23
- name: "gapic-generator-go"
34
full-name: https://github.com/googleapis/gapic-generator-go

internal/automation/repositories.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package automation
1616

1717
import (
18+
"errors"
1819
"fmt"
1920
"slices"
2021

@@ -26,6 +27,8 @@ import (
2627
//go:embed prod/repositories.yaml
2728
var prodRepositoriesYaml []byte
2829

30+
var errImageSHANotFound = errors.New("image SHA not found")
31+
2932
var availableCommands = map[string]bool{
3033
"generate": true,
3134
"stage-release": true,
@@ -51,6 +54,7 @@ type RepositoryConfig struct {
5154

5255
// RepositoriesConfig represents all the registered librarian GitHub repositories.
5356
type RepositoriesConfig struct {
57+
ImageSHA string `yaml:"librarian-image-sha"`
5458
Repositories []*RepositoryConfig `yaml:"repositories"`
5559
}
5660

@@ -87,6 +91,9 @@ func (c *RepositoryConfig) Validate() error {
8791

8892
// Validate checks the RepositoriesConfig is valid.
8993
func (c *RepositoriesConfig) Validate() error {
94+
if c.ImageSHA == "" {
95+
return errImageSHANotFound
96+
}
9097
for i, r := range c.Repositories {
9198
err := r.Validate()
9299
if err != nil {

internal/automation/repositories_test.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func TestRepositoriesConfig_Validate(t *testing.T) {
2929
{
3030
name: "valid state",
3131
config: &RepositoriesConfig{
32+
ImageSHA: "example-sha",
3233
Repositories: []*RepositoryConfig{
3334
{
3435
Name: "google-cloud-foo",
@@ -37,11 +38,11 @@ func TestRepositoriesConfig_Validate(t *testing.T) {
3738
},
3839
},
3940
},
40-
wantErr: false,
4141
},
4242
{
4343
name: "valid full name",
4444
config: &RepositoriesConfig{
45+
ImageSHA: "example-sha",
4546
Repositories: []*RepositoryConfig{
4647
{
4748
FullName: "https://github.com/googleapis/google-cloud-foo",
@@ -50,11 +51,11 @@ func TestRepositoriesConfig_Validate(t *testing.T) {
5051
},
5152
},
5253
},
53-
wantErr: false,
5454
},
5555
{
5656
name: "missing name",
5757
config: &RepositoriesConfig{
58+
ImageSHA: "example-sha",
5859
Repositories: []*RepositoryConfig{
5960
{
6061
SecretName: "google-cloud-foo-github-token",
@@ -67,6 +68,7 @@ func TestRepositoriesConfig_Validate(t *testing.T) {
6768
{
6869
name: "missing secret name",
6970
config: &RepositoriesConfig{
71+
ImageSHA: "example-sha",
7072
Repositories: []*RepositoryConfig{
7173
{
7274
Name: "google-cloud-foo",
@@ -79,6 +81,7 @@ func TestRepositoriesConfig_Validate(t *testing.T) {
7981
{
8082
name: "missing commands",
8183
config: &RepositoriesConfig{
84+
ImageSHA: "example-sha",
8285
Repositories: []*RepositoryConfig{
8386
{
8487
Name: "google-cloud-foo",
@@ -91,6 +94,7 @@ func TestRepositoriesConfig_Validate(t *testing.T) {
9194
{
9295
name: "empty commands",
9396
config: &RepositoriesConfig{
97+
ImageSHA: "example-sha",
9498
Repositories: []*RepositoryConfig{
9599
{
96100
Name: "google-cloud-foo",
@@ -104,6 +108,7 @@ func TestRepositoriesConfig_Validate(t *testing.T) {
104108
{
105109
name: "invalid command",
106110
config: &RepositoriesConfig{
111+
ImageSHA: "example-sha",
107112
Repositories: []*RepositoryConfig{
108113
{
109114
Name: "google-cloud-foo",
@@ -114,6 +119,11 @@ func TestRepositoriesConfig_Validate(t *testing.T) {
114119
},
115120
wantErr: true,
116121
},
122+
{
123+
name: "empty image sha",
124+
config: &RepositoriesConfig{},
125+
wantErr: true,
126+
},
117127
} {
118128
t.Run(test.name, func(t *testing.T) {
119129
if err := test.config.Validate(); (err != nil) != test.wantErr {
@@ -132,14 +142,16 @@ func TestParseRepositoriesConfig(t *testing.T) {
132142
}{
133143
{
134144
name: "valid state",
135-
content: `repositories:
145+
content: `librarian-image-sha: example-sha
146+
repositories:
136147
- name: google-cloud-python
137148
github-token-secret-name: google-cloud-python-github-token
138149
supported-commands:
139150
- generate
140151
- stage-release
141152
`,
142153
want: &RepositoriesConfig{
154+
ImageSHA: "example-sha",
143155
Repositories: []*RepositoryConfig{
144156
{
145157
Name: "google-cloud-python",
@@ -151,7 +163,8 @@ func TestParseRepositoriesConfig(t *testing.T) {
151163
},
152164
{
153165
name: "valid state with full name",
154-
content: `repositories:
166+
content: `librarian-image-sha: example-sha
167+
repositories:
155168
- name: google-cloud-python
156169
full-name: https://github.com/some-org/google-cloud-python
157170
github-token-secret-name: google-cloud-python-github-token
@@ -160,6 +173,7 @@ func TestParseRepositoriesConfig(t *testing.T) {
160173
- stage-release
161174
`,
162175
want: &RepositoriesConfig{
176+
ImageSHA: "example-sha",
163177
Repositories: []*RepositoryConfig{
164178
{
165179
Name: "google-cloud-python",
@@ -172,7 +186,8 @@ func TestParseRepositoriesConfig(t *testing.T) {
172186
},
173187
{
174188
name: "valid state with branch",
175-
content: `repositories:
189+
content: `librarian-image-sha: example-sha
190+
repositories:
176191
- name: google-cloud-python
177192
branch: preview
178193
github-token-secret-name: google-cloud-python-github-token
@@ -181,6 +196,7 @@ func TestParseRepositoriesConfig(t *testing.T) {
181196
- stage-release
182197
`,
183198
want: &RepositoriesConfig{
199+
ImageSHA: "example-sha",
184200
Repositories: []*RepositoryConfig{
185201
{
186202
Name: "google-cloud-python",
@@ -193,7 +209,8 @@ func TestParseRepositoriesConfig(t *testing.T) {
193209
},
194210
{
195211
name: "invalid yaml",
196-
content: `repositories:
212+
content: `librarian-image-sha: example-sha
213+
repositories:
197214
- name: google-cloud-python
198215
github-token-secret-name: google-cloud-python-github-token # bad indent
199216
supported-commands:
@@ -205,7 +222,8 @@ func TestParseRepositoriesConfig(t *testing.T) {
205222
},
206223
{
207224
name: "validation error",
208-
content: `repositories:
225+
content: `librarian-image-sha: example-sha
226+
repositories:
209227
- name: google-cloud-python
210228
github-token-secret-name: google-cloud-python-github-token
211229
# missing supported-commands

internal/automation/trigger.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,11 @@ func RunCommand(ctx context.Context, command string, projectId string, push bool
7979
}
8080

8181
func runCommandWithClient(ctx context.Context, client CloudBuildClient, ghClient GitHubClient, command string, projectId string, push bool, build bool) error {
82-
config, err := loadRepositoriesConfig()
82+
repositoriesConfig, err := loadRepositoriesConfig()
8383
if err != nil {
84-
slog.Error("error loading repositories config", slog.Any("err", err))
85-
return err
84+
return fmt.Errorf("error loading repositories config: %w", err)
8685
}
87-
return runCommandWithConfig(ctx, client, ghClient, command, projectId, push, build, config)
86+
return runCommandWithConfig(ctx, client, ghClient, command, projectId, push, build, repositoriesConfig)
8887
}
8988

9089
func runCommandWithConfig(ctx context.Context, client CloudBuildClient, ghClient GitHubClient, command string, projectId string, push bool, build bool, config *RepositoriesConfig) error {
@@ -107,6 +106,7 @@ func runCommandWithConfig(ctx context.Context, client CloudBuildClient, ghClient
107106
}
108107

109108
substitutions := map[string]string{
109+
"_IMAGE_SHA": config.ImageSHA,
110110
"_REPOSITORY": repository.Name,
111111
"_FULL_REPOSITORY": gitUrl,
112112
"_GITHUB_TOKEN_SECRET_NAME": repository.SecretName,

0 commit comments

Comments
 (0)