Skip to content

Commit aca4fc8

Browse files
authored
Merge branch 'main' into tpu_queued_resources_create
2 parents bb8dc08 + 24cf623 commit aca4fc8

File tree

11 files changed

+426
-138
lines changed

11 files changed

+426
-138
lines changed

.github/blunderbuss.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ assign_issues_by:
2626
- labels:
2727
- 'api: cloudsql'
2828
to:
29-
- GoogleCloudPlatform/infra-db-sdk
29+
- GoogleCloudPlatform/cloud-sql-connectors
3030
- labels:
3131
- 'api: dlp'
3232
to:
@@ -55,7 +55,7 @@ assign_prs_by:
5555
- labels:
5656
- 'api: cloudsql'
5757
to:
58-
- GoogleCloudPlatform/infra-db-sdk
58+
- GoogleCloudPlatform/cloud-sql-connectors
5959
- labels:
6060
- 'api: dlp'
6161
to:

.github/cloud-samples-tools/cmd/main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ func affectedCmd(configFile string, diffsFile string) {
7272
if err != nil {
7373
log.Fatalln("❌ error getting the diffs: ", diffsFile, "\n", err)
7474
}
75-
diffs := strings.Split(string(diffsBytes), "\n")
75+
// Trim whitespace to remove extra newline from diff output.
76+
diffs := strings.Split(strings.TrimSpace(string(diffsBytes)), "\n")
7677

77-
packages, err := config.Affected(diffs)
78+
// Log to stderr since GitHub Actions expects the output on stdout.
79+
packages, err := config.Affected(os.Stderr, diffs)
7880
if err != nil {
7981
log.Fatalln("❌ error finding the affected packages.\n", err)
8082
}

.github/cloud-samples-tools/pkg/config/config.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package config
1919
import (
2020
"encoding/json"
2121
"errors"
22+
"fmt"
23+
"io"
2224
"io/fs"
2325
"os"
2426
"path/filepath"
@@ -154,8 +156,8 @@ func (c *Config) FindAllPackages(root string) ([]string, error) {
154156
// Affected returns the packages that have been affected from diffs.
155157
// If there are diffs on at leat one global file affecting all packages,
156158
// then this returns all packages matched by the config.
157-
func (c *Config) Affected(diffs []string) ([]string, error) {
158-
changed := c.Changed(diffs)
159+
func (c *Config) Affected(log io.Writer, diffs []string) ([]string, error) {
160+
changed := c.Changed(log, diffs)
159161
if slices.Contains(changed, ".") {
160162
return c.FindAllPackages(".")
161163
}
@@ -165,25 +167,22 @@ func (c *Config) Affected(diffs []string) ([]string, error) {
165167
// Changed returns the packages that have changed.
166168
// It only returns packages that are matched by the config,
167169
// and are not excluded by the config.
168-
func (c *Config) Changed(diffs []string) []string {
170+
func (c *Config) Changed(log io.Writer, diffs []string) []string {
169171
changedUnique := make(map[string]bool)
170172
for _, diff := range diffs {
171173
if !c.Matches(diff) {
172174
continue
173175
}
174176
pkg := c.FindPackage(diff)
175-
if slices.Contains(c.ExcludePackages, pkg) {
176-
continue
177-
}
178177
changedUnique[pkg] = true
179178
}
180179

181-
if len(changedUnique) == 0 {
182-
return []string{"."}
183-
}
184-
185180
changed := make([]string, 0, len(changedUnique))
186181
for pkg := range changedUnique {
182+
if slices.Contains(c.ExcludePackages, pkg) {
183+
fmt.Fprintf(log, "ℹ️ Excluded package %q, skipping.\n", pkg)
184+
continue
185+
}
187186
changed = append(changed, pkg)
188187
}
189188
return changed

.github/cloud-samples-tools/pkg/config/config_test.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,30 +167,40 @@ func TestFindPackage(t *testing.T) {
167167

168168
func TestChanged(t *testing.T) {
169169
config := c.Config{
170-
PackageFile: []string{"package.json"},
171-
Match: []string{"*"},
170+
PackageFile: []string{"package.json"},
171+
Match: []string{"*"},
172+
Ignore: []string{"ignored.txt"},
173+
ExcludePackages: []string{filepath.Join("testdata", "excluded")},
172174
}
173175

174176
tests := []struct {
175177
diffs []string
176178
expected []string
177179
}{
178-
{
180+
{ // Global change, everything is affected.
179181
diffs: []string{filepath.Join("testdata", "file.txt")},
180182
expected: []string{"."},
181183
},
182-
{
184+
{ // Ignored files should not trigger tests.
185+
diffs: []string{filepath.Join("testdata", "ignored.txt")},
186+
expected: []string{},
187+
},
188+
{ // Single affected package.
183189
diffs: []string{filepath.Join("testdata", "my-package", "file.txt")},
184190
expected: []string{filepath.Join("testdata", "my-package")},
185191
},
186-
{
192+
{ // Single affected nested package.
187193
diffs: []string{filepath.Join("testdata", "my-package", "subpackage", "file.txt")},
188194
expected: []string{filepath.Join("testdata", "my-package", "subpackage")},
189195
},
196+
{ // Excluded package.
197+
diffs: []string{filepath.Join("testdata", "excluded", "file.txt")},
198+
expected: []string{},
199+
},
190200
}
191201

192202
for _, test := range tests {
193-
got := config.Changed(test.diffs)
203+
got := config.Changed(os.Stderr, test.diffs)
194204
if !reflect.DeepEqual(test.expected, got) {
195205
t.Fatal("expected equal\n", test.expected, got)
196206
}

.github/cloud-samples-tools/pkg/config/testdata/excluded/package.json

Whitespace-only changes.

.github/config/nodejs-dev.jsonc

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
/*
2+
Copyright 2024 Google LLC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
https://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
{
18+
"package-file": [ "package.json" ],
19+
"ignore": [
20+
".eslintignore",
21+
".eslintrc.json",
22+
".github/.OwlBot.lock.yaml",
23+
".github/.OwlBot.yaml",
24+
".github/ISSUE_TEMPLATE/",
25+
".github/PULL_REQUEST_TEMPLATE.md",
26+
".github/auto-label.yaml",
27+
".github/blunderbuss.yaml",
28+
".github/cloud-samples-tools/",
29+
".github/flakybot.yaml",
30+
".github/header-checker-lint.yaml",
31+
".github/snippet-bot.yml",
32+
".github/trusted-contribution.yml",
33+
".gitignore",
34+
".kokoro/",
35+
".prettierignore",
36+
".prettierrc.js",
37+
"CODEOWNERS",
38+
"CODE_OF_CONDUCT.md",
39+
"CONTRIBUTING.md",
40+
"LICENSE",
41+
"Makefile",
42+
"README.md",
43+
"SECURITY.md",
44+
"buildsetup.sh",
45+
"linkinator.config.json",
46+
"node_modules/",
47+
"owlbot.py",
48+
"renovate.json"
49+
],
50+
// These are all working well in prod, so we can exclude them from dev.
51+
// Once all packages are in prod, we can remove this dev config.
52+
"exclude-packages": [
53+
"functions/concepts", // parent directory
54+
"functions/firebase", // parent directory
55+
"functions/helloworld", // parent directory
56+
"functions/http", // parent directory
57+
"functions/http/uploadFile", // parent directory
58+
"functions/log", // parent directory
59+
"functions/pubsub", // parent directory
60+
"memorystore/redis", // parent directory
61+
"recaptcha_enterprise/demosite/app", // no tests exist
62+
63+
// These tests are already passing in prod, so skip them in dev.
64+
"appengine/building-an-app/build",
65+
"appengine/building-an-app/update",
66+
"appengine/datastore",
67+
"appengine/endpoints",
68+
"appengine/hello-world/flexible",
69+
"appengine/hello-world/flexible_nodejs16_and_earlier",
70+
"appengine/hello-world/standard",
71+
"appengine/memcached",
72+
"appengine/metadata/flexible_nodejs16_and_earlier",
73+
"appengine/pubsub",
74+
"appengine/static-files",
75+
"appengine/storage/flexible",
76+
"appengine/storage/flexible_nodejs16_and_earlier",
77+
"appengine/storage/standard",
78+
"appengine/typescript",
79+
"appengine/websockets",
80+
"asset/snippets",
81+
"auth",
82+
"batch",
83+
"cloud-language",
84+
"cloud-tasks/snippets",
85+
"cloud-tasks/tutorial-gcf/app",
86+
"cloud-tasks/tutorial-gcf/function",
87+
"cloudbuild",
88+
"composer",
89+
"composer/functions/composer-storage-trigger",
90+
"contact-center-insights",
91+
"container",
92+
"container-analysis/snippets",
93+
"datacatalog/cloud-client",
94+
"datacatalog/quickstart",
95+
"datacatalog/snippets",
96+
"datalabeling",
97+
"dialogflow",
98+
"discoveryengine",
99+
"document-warehouse",
100+
"endpoints/getting-started",
101+
"endpoints/getting-started-grpc",
102+
"error-reporting",
103+
"eventarc/generic",
104+
"functions/concepts/afterResponse",
105+
"functions/concepts/afterTimeout",
106+
"functions/concepts/backgroundTermination",
107+
"functions/concepts/filesystem",
108+
"functions/concepts/httpTermination",
109+
"functions/concepts/requests",
110+
"functions/concepts/stateless",
111+
"functions/env_vars",
112+
"functions/firebase/helloAnalytics",
113+
"functions/firebase/helloAuth",
114+
"functions/firebase/helloFirestore",
115+
"functions/firebase/helloRTDB",
116+
"functions/firebase/helloRemoteConfig",
117+
"functions/firebase/makeUpperCase",
118+
"functions/helloworld/helloError",
119+
"functions/helloworld/helloGCS",
120+
"functions/helloworld/helloPubSub",
121+
"functions/helloworld/helloworldGet",
122+
"functions/helloworld/helloworldHttp",
123+
"functions/http/corsEnabledFunction",
124+
"functions/http/corsEnabledFunctionAuth",
125+
"functions/http/httpContent",
126+
"functions/http/httpMethods",
127+
"functions/http/parseXML",
128+
"functions/log/helloWorld",
129+
"functions/log/processEntry",
130+
"functions/memorystore/redis",
131+
"functions/pubsub/publish",
132+
"functions/pubsub/subscribe",
133+
"functions/scheduleinstance",
134+
"functions/security",
135+
"functions/spanner",
136+
"functions/speech-to-speech/functions",
137+
"functions/tips",
138+
"functions/tips/avoidInfiniteRetries",
139+
"functions/tips/connectionPools",
140+
"functions/tips/gcpApiCall",
141+
"functions/tips/lazyGlobals",
142+
"functions/tips/retry",
143+
"functions/tips/scopeDemo",
144+
"functions/v2/autoLabelInstance",
145+
"functions/v2/cloudEventLogging",
146+
"functions/v2/firebase/firestore/helloFirestore",
147+
"functions/v2/firebase/firestore/makeUpperCase",
148+
"functions/v2/firebase/remote-config/helloRemoteConfig",
149+
"functions/v2/firebase/rtdb/helloRTDB",
150+
"functions/v2/helloAuditLog",
151+
"functions/v2/helloBigQuery",
152+
"functions/v2/helloGCS",
153+
"functions/v2/helloPubSub",
154+
"functions/v2/httpLogging",
155+
"functions/v2/log/processEntry",
156+
"functions/v2/ocr/app",
157+
"functions/v2/responseStreaming",
158+
"functions/v2/tips/avoidInfiniteRetries",
159+
"functions/v2/tips/retry",
160+
"functions/v2/typed/googlechatbot",
161+
"functions/v2/typed/greeting",
162+
"healthcare/consent",
163+
"healthcare/datasets",
164+
"healthcare/dicom",
165+
"healthcare/hl7v2",
166+
"kms",
167+
"media/livestream",
168+
"media/transcoder",
169+
"media/video-stitcher",
170+
"mediatranslation",
171+
"monitoring/prometheus",
172+
"monitoring/snippets",
173+
"retail",
174+
"routeoptimization/snippets",
175+
"run/hello-broken",
176+
"run/helloworld",
177+
"run/image-processing",
178+
"run/jobs",
179+
"run/logging-manual",
180+
"run/markdown-preview/renderer",
181+
"run/pubsub",
182+
"run/websockets",
183+
"secret-manager",
184+
"service-directory/snippets",
185+
"storage-control",
186+
"texttospeech",
187+
"tpu",
188+
"workflows/invoke-private-endpoint"
189+
]
190+
}

0 commit comments

Comments
 (0)