Skip to content
Merged
Show file tree
Hide file tree
Changes from 63 commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
e6c4a9c
add samples testing tooling
Sep 20, 2024
4b4b3fd
edit to trigger tests
Sep 20, 2024
f96d2cf
update reusable workflow path
Sep 20, 2024
cb10e4f
make relative path
Sep 20, 2024
99ffa49
fix config
Sep 20, 2024
011cac8
inline workflow
Sep 20, 2024
24ae0ff
install before lint
Sep 20, 2024
8c15093
install before lint on Makefile
Sep 20, 2024
f35e5a6
install gts
Sep 20, 2024
3a1703e
install repo wide deps
Sep 20, 2024
159548d
add test action
Sep 20, 2024
1fc7db8
add project id
Sep 20, 2024
2a31b48
add auth credentials
Sep 21, 2024
cb1af68
add id-token permissions
Sep 21, 2024
6fc0660
use service account
Sep 21, 2024
c4b09fe
cleanup
Sep 21, 2024
8082788
modify ignored file
Sep 23, 2024
784e8e8
revert change
Sep 23, 2024
0a13f40
make change to trigger tests
Sep 23, 2024
f7e547f
include e2e-test
Sep 23, 2024
34fd1ef
check whether to e2e-test
Sep 23, 2024
70ed258
add e2e-test configuration
Sep 23, 2024
359bf41
add e2e-test as extra config
Sep 23, 2024
1dd8e9e
also check for substring as match
Sep 23, 2024
edc1692
pass entire path to match
Sep 23, 2024
5d730e2
mark as experimental
Sep 24, 2024
7e724a5
add experimental emoji
Sep 24, 2024
5c63239
test on node 18 and 22
Sep 24, 2024
4665437
reorder matrix
Sep 24, 2024
f7287f8
use wip directly without service account
Sep 24, 2024
d8494d2
use kokoro service account
Sep 24, 2024
a3e85be
trigger all tests on root changes
Sep 24, 2024
6108a4a
do not fail fast
Sep 24, 2024
27ba947
make lint a global job
Sep 24, 2024
188e47d
separate nodejs versions
Sep 24, 2024
4c40beb
add checkout to reusable workflow
Sep 24, 2024
cb51d95
add contents read permission
Sep 24, 2024
9811b3c
skip testing everything on root changes
Sep 24, 2024
1b08c9a
give contents read permissions
Sep 24, 2024
5591184
call reusable workflow correctly
Sep 24, 2024
7848775
reusable workflow for nodejs test
Sep 24, 2024
fb8760d
change names
Sep 24, 2024
6815794
more explicit names
Sep 24, 2024
42b40c9
only show version number
Sep 24, 2024
4ec1a19
test all
Sep 24, 2024
9e3bc3e
use node 20
Sep 24, 2024
04448a6
create service account file
Sep 24, 2024
48cf1e6
adjust token lifetime
Sep 24, 2024
88e2d38
lower node version
Sep 24, 2024
c21429e
do not test all
Sep 24, 2024
153c94c
use node 16
Sep 24, 2024
b236312
use node 20
Sep 24, 2024
c1f7300
restore language test
Sep 24, 2024
04cc1e2
Merge branch 'main' of github.com:GoogleCloudPlatform/nodejs-docs-sam…
Sep 25, 2024
bc91620
add install and more comments
Sep 25, 2024
4f8a45b
assign and print variables in the same line
Sep 25, 2024
03b7f1e
Merge branch 'main' of github.com:GoogleCloudPlatform/nodejs-docs-sam…
Sep 26, 2024
4511504
change to trigger tests
Sep 26, 2024
8d169b5
test all
Sep 26, 2024
a818e6e
exclude special tests
Sep 26, 2024
f451f21
more packages to exclude
Sep 26, 2024
1262f3e
support exclude-packages and json comments
Sep 30, 2024
69192c8
use jsonc extension
Sep 30, 2024
5b3f469
use flag package
Sep 30, 2024
8bb4dc5
remove unused actions for config
Sep 30, 2024
0928722
restore changes
Sep 30, 2024
1710ed3
use correct config
Sep 30, 2024
6fe8059
better error messages
Oct 1, 2024
9b6ee80
improve error messages
Oct 1, 2024
5d06e66
Merge branch 'main' of github.com:GoogleCloudPlatform/nodejs-docs-sam…
Oct 1, 2024
9afaa2a
use io/fs.WalkDir
Oct 2, 2024
72e204c
rename variable
Oct 2, 2024
0854b06
experiment with nightly tests
Oct 2, 2024
3f96c33
remove e2e-test for now
Oct 2, 2024
f995455
use ternary operator
Oct 2, 2024
4aabf3b
disable pr tests temporarily
Oct 2, 2024
c96ca22
Merge branch 'main' of github.com:GoogleCloudPlatform/nodejs-docs-sam…
Oct 2, 2024
e7f56a1
use diffs file
Oct 2, 2024
9ee8f52
print git diff outputs as well
Oct 2, 2024
21b97df
remove git utils
Oct 2, 2024
5991759
initial prototype for nightlies
Oct 3, 2024
5f6cc38
update workflow command
Oct 3, 2024
84223b2
only sprintf when wildcard is there
Oct 3, 2024
7e69a04
print on success too
Oct 3, 2024
ca4a100
improve error messages
Oct 3, 2024
8cb15e0
disable parallelism
Oct 3, 2024
22cbf8f
Merge branch 'main' of github.com:GoogleCloudPlatform/nodejs-docs-sam…
Oct 3, 2024
d335ec1
improve error reporting
Oct 3, 2024
ee375a6
clean before each test
Oct 3, 2024
b99d1dc
include parallel flag
Oct 3, 2024
9139ce5
Merge branch 'main' of github.com:GoogleCloudPlatform/nodejs-docs-sam…
Oct 3, 2024
f6d05a2
re-enable tests and disable nightlies experiment
Oct 3, 2024
61412f3
disable fail-fast
Oct 3, 2024
30f24ee
revert clean commands
Oct 3, 2024
333f06a
add files to ignore
Oct 3, 2024
ba3c057
ignore speech package
Oct 3, 2024
a4e91f9
ignore translate package
Oct 3, 2024
e80bcd0
add license headers and support multi-line comments
Oct 4, 2024
1fb450b
revert and add build to lint
Oct 4, 2024
0f60ed1
move tools to single command
Oct 4, 2024
f71163d
update workflow to new command
Oct 4, 2024
400db0e
Add comment for cron schedule
Oct 4, 2024
26b5d2b
run nightlies each on their own job
Oct 4, 2024
2784119
fix typo on path
Oct 4, 2024
cc7d9a0
better messages
Oct 4, 2024
d944a39
exclude talent package
Oct 4, 2024
51bc759
document affected
Oct 7, 2024
da62a12
reorganize files
Oct 7, 2024
82cb3ba
use script to run tests
Oct 7, 2024
91f2e62
run all tests
Oct 7, 2024
1786146
Merge branch 'main' of github.com:GoogleCloudPlatform/nodejs-docs-sam…
Oct 7, 2024
4033572
fix syntax error
Oct 7, 2024
9a7d172
do not fail on npm install
Oct 7, 2024
34db331
print outputs immediately
Oct 7, 2024
069d376
increment failures atomically
Oct 7, 2024
8732c07
disable nightly batch job
Oct 7, 2024
fba5bc6
install repo root package
Oct 7, 2024
d138552
use log.Fatalf
Oct 8, 2024
9ba7912
add unit tests and testing instructions
Oct 8, 2024
35c9c3d
move tools directory
Oct 9, 2024
7926134
Merge branch 'main' of github.com:GoogleCloudPlatform/nodejs-docs-sam…
Oct 9, 2024
4f58bcd
fix tests pkg path
Oct 9, 2024
f965b2d
run tests on action
Oct 9, 2024
932c00a
add go linting
Oct 9, 2024
5012283
use double star on paths
Oct 9, 2024
22f4361
use variadic argument prints
Oct 10, 2024
b7e6c59
remove everything related to run-all
Oct 10, 2024
de73036
add tool summary
Oct 10, 2024
c74db78
use pointer for methods
Oct 10, 2024
25b6929
use table based testing
Oct 10, 2024
cc7fd6b
return nil if error
Oct 10, 2024
687262b
use manual test checks
Oct 15, 2024
0b6d130
Merge branch 'main' of github.com:GoogleCloudPlatform/nodejs-docs-sam…
Oct 15, 2024
ed6906f
moved tests to source directory
Oct 21, 2024
f3f88e6
update test command
Oct 21, 2024
947ea28
Merge branch 'main' into testing-isolation
iennae Nov 5, 2024
a3cb72d
comment schedule trigger
Nov 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/config/nodejs-e2e.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"match": ["run/hello-broken/", "run/helloworld/"],
"ignore": ["README.md", "node_modules/"],
"package": ["package.json"]
}
54 changes: 54 additions & 0 deletions .github/workflows/config/nodejs.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"ignore": ["README.md", "node_modules/"],
"package": ["package.json"],
"exclude-packages": [
"ai-platform/snippets", // PERMISSION_DENIED: Permission denied: Consumer 'projects/undefined' has been suspended.
"appengine/analytics", // [ERR_REQUIRE_ESM]: require() of ES Module
"appengine/metadata/flexible", // [ERR_REQUIRE_ESM]: require() of ES Module
"appengine/metadata/standard", // [ERR_REQUIRE_ESM]: require() of ES Module
"automl", // FAILED_PRECONDITION: Google Cloud AutoML Natural Language was retired on March 15, 2024. Please migrate to Vertex AI instead
"cloud-sql/mysql/mysql", // Error: expected 200 "OK", got 500 "Internal Server Error"
"cloud-sql/mysql/mysql2", // Error: Cannot find module './connect-connector-with-iam-authn.js'
"cloud-sql/postgres/knex", // CloudSQLConnectorError: Malformed instance connection name provided: expected format of "PROJECT:REGION:INSTANCE", got undefined
"cloud-sql/sqlserver/mssql", // TypeError: The "config.server" property is required and must be of type string.
"cloud-sql/sqlserver/tedious", // TypeError: The "config.server" property is required and must be of type string.
"compute", // GoogleError: The resource 'projects/long-door-651/zones/us-central1-a/disks/disk-from-pool-name' was not found
"dataproc", // GoogleError: Error submitting create cluster request: Multiple validation errors
"datastore/functions", // [ERR_REQUIRE_ESM]: require() of ES Module
"dialogflow-cx", // NOT_FOUND: com.google.apps.framework.request.NotFoundException: Agent 'undefined' does not exist
"dlp", // [ERR_REQUIRE_ESM]: require() of ES Module
"document-ai", // [ERR_REQUIRE_ESM]: require() of ES Module
"eventarc/audit-storage", // Environment Variable 'SERVICE_NAME' not found
"eventarc/pubsub", // Environment Variable 'SERVICE_NAME' not found
"functions/billing", // Error: Request failed with status code 500
"functions/concepts", // npm error Missing script: "test"
"functions/firebase", // npm error Missing script: "test"
"functions/helloworld", // npm error Missing script: "test"
"functions/http", // npm error Missing script: "test"
"functions/http/uploadFile", // npm error Missing script: "test"
"functions/imagemagick", // Error: A bucket name is needed to use Cloud Storage
"functions/log", // npm error Missing script: "test"
"functions/ocr/app", // Error: Bucket not provided. Make sure you have a "bucket" property in your request
"functions/pubsub", // npm error Missing script: "test"
"functions/slack", // TypeError [ERR_INVALID_ARG_TYPE]: The "key" argument must be of type ... Received undefined
"functions/v2/imagemagick", // Error: A bucket name is needed to use Cloud Storage.
"generative-ai/snippets", // [VertexAI.ClientError]: got status: 403 Forbidden.
"healthcare/consent", // GaxiosError: dataset not initialized
"healthcare/dicom", // GaxiosError: dataset not initialized
"healthcare/fhir", // Error: Cannot find module 'whatwg-url'
"healthcare/hl7v2", // Error: Cannot find module 'whatwg-url'
"iam/deny", // PERMISSION_DENIED: Permission iam.googleapis.com/denypolicies.create denied on resource cloudresourcemanager.googleapis.com/projects/long-door-651
"memorystore/redis", // npm error Missing script: "test"
"recaptcha_enterprise/demosite/app", // Error: no test specified
"recaptcha_enterprise/snippets", // Cannot use import statement outside a module
"run/idp-sql", // Error: Invalid contents in the credentials file
"run/markdown-preview/editor", // Error: could not create an identity token: Cannot fetch ID token in this environment, use GCE or set the GOOGLE_APPLICATION_CREDENTIALS environment variable to a service account credentials JSON file
"run/system-package", // Error: ENOENT: no such file or directory, access '/usr/bin/dot'
"scheduler", // SyntaxError: Cannot use import statement outside a module
"storagetransfer", // CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
"video-intelligence", // PERMISSION_DENIED: The caller does not have permission
"vision", // REDIS: Error: connect ECONNREFUSED 127.0.0.1:6379
"workflows", // SyntaxError: Cannot use import statement outside a module
"workflows/quickstart" // [ERR_MODULE_NOT_FOUND]: Cannot find package 'ts-node' imported from ...
]
}
104 changes: 104 additions & 0 deletions .github/workflows/experimental.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: ⚗️ experimental
Copy link
Contributor

@NimJay NimJay Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: I recommend using a more descriptive name (instead of name: ⚗️ experimental). This also applies to the file name.

Copy link
Author

@davidcavazos davidcavazos Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually by design. We'll be leaving the existing tests and adding these new tests. Since there might be issues with this new testing infrastructure, we're explicitly marking them as "experimental". That way reviewers know that if they fail, they shouldn't be a blocker to merge a pull request.

Once we feel more comfortable and start removing the old infrastructure, we'll rename this into something more descriptive.

on:
push:
branches:
- main
pull_request:
types:
- opened
- reopened
- synchronize
- labeled

jobs:
affected:
name: Finding affected tests
runs-on: ubuntu-latest
timeout-minutes: 1
outputs:
nodejs: ${{ steps.nodejs.outputs.packages }}
nodejs-e2e: ${{ steps.nodejs-e2e.outputs.packages }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: ^1.22.0
- run: go install ./cmd/affected
working-directory: .github/workflows/samples-tools
- id: nodejs
run: |
PACKAGES=$(affected .github/workflows/config/nodejs.jsonc)
echo "packages=$PACKAGES" | tee -a $GITHUB_OUTPUT
- id: nodejs-e2e
run: |
PACKAGES=$(affected .github/workflows/config/nodejs-e2e.jsonc)
echo "packages=$PACKAGES" | tee -a $GITHUB_OUTPUT

nodejs-lint:
name: Node.js lint
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: make lint
- run: ./.github/workflows/utils/region-tags-tests.sh

nodejs-test:
name: Node.js test
needs: affected
strategy:
matrix:
package: ${{ fromJson(needs.affected.outputs.nodejs) }}
exclude:
- package: '.'
uses: ./.github/workflows/nodejs-test.yaml
with:
path: ${{ matrix.package }}
node-version: 20

# nodejs-e2e-test:
# name: Node.js e2e-test
# needs: affected
# runs-on: ubuntu-latest
# timeout-minutes: 60
# permissions:
# id-token: write # needed for google-github-actions/auth
# strategy:
# matrix:
# node-version: [18, 22]
# package: ${{ fromJson(needs.affected.outputs.nodejs-e2e) }}
# exclude:
# - package: '.'
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-node@v4
# with:
# node-version: ${{ matrix.node-version }}
# - uses: google-github-actions/auth@v2
# with:
# project_id: long-door-651
# workload_identity_provider: projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider
# service_account: [email protected]
# access_token_lifetime: 600s # 10 minutes
# - run: make e2e-test dir=${{ matrix.package }}
# env:
# GOOGLE_SAMPLES_PROJECT: long-door-651
47 changes: 47 additions & 0 deletions .github/workflows/nodejs-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

on:
workflow_call:
inputs:
path:
required: true
type: string
node-version:
required: true
type: number

jobs:
test:
name: ${{ inputs.node-version }}
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
id-token: write # needed for google-github-actions/auth
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
- uses: google-github-actions/auth@v2
with:
project_id: long-door-651
workload_identity_provider: projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider
service_account: [email protected]
access_token_lifetime: 600s # 10 minutes
- run: make test dir=${{ inputs.path }}
env:
GOOGLE_SAMPLES_PROJECT: long-door-651
25 changes: 25 additions & 0 deletions .github/workflows/samples-tools/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work
go.work.sum

# env file
.env
92 changes: 92 additions & 0 deletions .github/workflows/samples-tools/cmd/affected/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package main

import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"slices"

"samples-tools/pkg/utils"
)

func main() {
usage := "usage: affected path/to/config.json [head-commit] [main-commit]"
configPath := utils.ArgRequired(1, usage)
headCommit := utils.ArgWithDefault(2, "HEAD")
mainCommit := utils.ArgWithDefault(3, "origin/main")

config, err := utils.LoadConfig(configPath)
if err != nil {
panic(err)
}

diffs, err := utils.Diffs(headCommit, mainCommit)
if err != nil {
panic(err)
}

packages, err := affected(config, diffs)
if err != nil {
panic(err)
}
if len(packages) > 256 {
panic(fmt.Errorf("GitHub Actions only supports up to 256 packages, got %d packages", len(packages)))
}

matrix, err := json.Marshal(packages)
if err != nil {
panic(err)
}

fmt.Println(string(matrix))
}

func affected(config utils.Config, diffs []string) ([]string, error) {
uniquePackages := make(map[string]bool)
for _, diff := range diffs {
if !config.Matches(diff) {
continue
}
pkg := config.FindPackage(diff)
if slices.Contains(config.ExcludePackages, pkg) {
continue
}
uniquePackages[pkg] = true
}

changed := make([]string, 0, len(uniquePackages))
for pkg := range uniquePackages {
changed = append(changed, pkg)
}

if slices.Contains(changed, ".") {
return findAllPackages(config)
}
return changed, nil
}

func findAllPackages(config utils.Config) ([]string, error) {
var packages []string
err := filepath.WalkDir(".",
func(path string, d os.DirEntry, err error) error {
if err != nil {
return err
}
if path == "." {
return nil
}
if slices.Contains(config.ExcludePackages, path) {
return nil
}
if d.IsDir() && config.Matches(path) && config.IsPackageDir(path) {
packages = append(packages, path)
return nil
}
return nil
})
if err != nil {
return []string{}, err
}
return packages, nil
}
3 changes: 3 additions & 0 deletions .github/workflows/samples-tools/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module samples-tools

go 1.22.0
37 changes: 37 additions & 0 deletions .github/workflows/samples-tools/pkg/utils/args.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package utils

import (
"fmt"
"os"
"strings"
)

func ArgRequired(index int, errorMessage string) string {
if len(os.Args) <= index {
panic(errorMessage)
}
return os.Args[index]
}

func ArgWithDefault(index int, defaultValue string) string {
if len(os.Args) <= index {
return defaultValue
}
return os.Args[index]
}

func InterpolateArgs(args []string, values []string) []string {
var result []string
for _, arg := range args {
for argIdx, value := range values {
arg = strings.ReplaceAll(arg, fmt.Sprintf("$%d", argIdx+1), value)
}
if arg := strings.TrimSpace(strings.TrimSuffix(arg, "$@")); arg != "" {
result = append(result, arg)
}
if strings.HasSuffix(arg, "$@") {
result = append(result, values...)
}
}
return result
}
Loading