Skip to content

Commit 628023a

Browse files
authored
build: make tests run faster (#4205)
* build: make tests run faster
1 parent 744cd79 commit 628023a

File tree

162 files changed

+1462
-7479
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+1462
-7479
lines changed

.github/sync-repo-settings.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ branchProtectionRules:
3434
- "samples-presubmit-node14-with-credentials (long-door-651)"
3535
- "samples-presubmit-node14 (long-door-651)"
3636
- "units (14)"
37-
- "unit-presubmit-node16 (long-door-651)"
38-
- "unit-presubmit-node18 (long-door-651)"
39-
- "unit-presubmit-node12 (long-door-651)"
37+
- "units (12)"
38+
- "units (16)"
39+
- "units (18)"
4040
# List of explicit permissions to add (additive only)
4141
permissionRules:
4242
# Team slug to add to repository permissions

.github/workflows/continuous.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ jobs:
1111
node: [14]
1212
steps:
1313
- uses: actions/checkout@v3
14-
- uses: actions/setup-node@v3
14+
- uses: pnpm/action-setup@v2
1515
with:
16-
node-version: ${{ matrix.node }}
16+
version: 7.32.2
1717
- run: node --version
1818
- run: ci/run_conditional_tests.sh
1919
name: Check lint
@@ -24,12 +24,12 @@ jobs:
2424
runs-on: ubuntu-latest
2525
strategy:
2626
matrix:
27-
node: [14]
27+
node: [12, 14, 16, 18]
2828
steps:
2929
- uses: actions/checkout@v3
30-
- uses: actions/setup-node@v3
30+
- uses: pnpm/action-setup@v2
3131
with:
32-
node-version: ${{ matrix.node }}
32+
version: ^6.24.1
3333
- run: node --version
3434
- run: ci/run_conditional_tests.sh
3535
name: Run unit tests

.github/workflows/presubmit.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ jobs:
99
node: [14]
1010
steps:
1111
- uses: actions/checkout@v3
12-
- uses: actions/setup-node@v3
12+
- uses: pnpm/action-setup@v2
1313
with:
14-
node-version: ${{ matrix.node }}
14+
version: 7.32.2
1515
- run: node --version
1616
- run: ci/run_conditional_tests.sh
1717
name: Check lint
@@ -22,12 +22,12 @@ jobs:
2222
runs-on: ubuntu-latest
2323
strategy:
2424
matrix:
25-
node: [14]
25+
node: [12, 14, 16, 18]
2626
steps:
2727
- uses: actions/checkout@v3
28-
- uses: actions/setup-node@v3
28+
- uses: pnpm/action-setup@v2
2929
with:
30-
node-version: ${{ matrix.node }}
30+
version: ^6.24.1
3131
- run: node --version
3232
- run: ci/run_conditional_tests.sh
3333
name: Run unit tests

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ packages/*/CONTRIBUTORS
99
packages/*/COPYING
1010
package-lock.json
1111
__pycache__
12+
packages/*/pnpm-lock.yaml
13+
containers/*/pnpm-lock.yaml

ci/Dockerfile

+6-3
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,19 @@ RUN curl https://github.com/googleapis/repo-automation-bots/releases/download/fl
3131
-o /bin/flakybot -s -L \
3232
&& chmod +x /bin/flakybot
3333

34-
FROM node:${NODE_VERSION}-alpine
34+
ENV PNPM_VERSION=7.32.2
35+
RUN curl https://get.pnpm.io/install.sh | ENV="$HOME/.shrc" SHELL="$(which sh)" sh -
3536

36-
COPY --from=build /bin/flakybot /bin/flakybot
37+
FROM node:${NODE_VERSION}-alpine
3738

3839
# Hack for not found error with flakybot
3940
RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2
4041

4142
COPY --from=build /usr/local/gcloud /usr/local/gcloud
4243
COPY --from=build /bin/flakybot /bin/flakybot
44+
COPY --from=build /root/.local/share/pnpm /root/.local/share/pnpm
4345

4446
RUN apk add --no-cache git bash python3
4547

46-
ENV PATH $PATH:/usr/local/gcloud/google-cloud-sdk/bin
48+
ENV PNPM_HOME=/root/.local/share/pnpm
49+
ENV PATH=$PNPM_HOME:$PATH

ci/cloudbuild.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ steps:
3535
'--push-retry=3',
3636
'--image-fs-extract-retry=3'
3737
]
38+
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
39+
entrypoint: "bash"
40+
args: ["ci/deletecloudbuild.sh"]
41+
env:
42+
- 'REF_NAME=${REF_NAME}'
3843
- name: gcr.io/${PROJECT_ID}/google-cloud-node-${_NODE_VERSION}
3944
id: "run-tests"
4045
timeout: 32400s

ci/deletecloudbuild.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2023 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+
now=$(date -u -d "-15 min" +"%Y-%m-%dT%H:%M:%SZ")
16+
gcloud builds list --format="value(id)" --filter="substitutions.REF_NAME="$REF_NAME" AND status="WORKING" AND create_time<"$now"" | while IFS= read -r line ; do
17+
echo "gcloud builds cancel "$line""
18+
gcloud builds cancel "$line"
19+
done

ci/export/unit-presubmit-node12.yaml

-19
This file was deleted.

ci/export/unit-presubmit-node16.yaml

-19
This file was deleted.

ci/export/unit-presubmit-node18.yaml

-19
This file was deleted.

ci/export_triggers.sh

+1-9
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,4 @@ for NODE_VERSION in ${NODE_VERSIONS[@]}; do
4646
gcloud beta builds triggers export "samples-nightly-node${NODE_VERSION}" --destination "ci/export/samples-nightly-node${NODE_VERSION}.yaml"
4747
echo "exporting presubmit build for node${NODE_VERSION} with credentials"
4848
gcloud beta builds triggers export "samples-presubmit-node${NODE_VERSION}-with-credentials" --destination "ci/export/samples-presubmit-node${NODE_VERSION}-with-credentials.yaml"
49-
done
50-
51-
# Since we don't want to run nightly, presubmit, and continuous for node 16 and node 18, adding these outside of the loop
52-
echo "exporting presubmit unit build for node12 unit tests"
53-
gcloud beta builds triggers export "unit-presubmit-node12" --destination "ci/export/unit-presubmit-node12.yaml"
54-
echo "exporting presubmit unit build for node16 unit tests"
55-
gcloud beta builds triggers export "unit-presubmit-node16" --destination "ci/export/unit-presubmit-node16.yaml"
56-
echo "exporting presubmit unit build for node18 unit tests"
57-
gcloud beta builds triggers export "unit-presubmit-node18" --destination "ci/export/unit-presubmit-node18.yaml"
49+
done

ci/import_triggers.sh

+1-9
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,4 @@ for NODE_VERSION in ${NODE_VERSIONS[@]}; do
4646
gcloud beta builds triggers import --source "ci/export/samples-nightly-node${NODE_VERSION}.yaml"
4747
echo "importing presubmit build for node${NODE_VERSION} with credentials"
4848
gcloud beta builds triggers import --source "ci/export/samples-presubmit-node${NODE_VERSION}-with-credentials.yaml"
49-
done
50-
51-
# Since we don't want to run nightly, and continuous for node 16 and node 18, adding these outside of the loop
52-
echo "importing presubmit unit build for node12 unit tests"
53-
gcloud beta builds triggers import --source "ci/export/unit-presubmit-node12.yaml"
54-
echo "importing presubmit unit build for node16 unit tests"
55-
gcloud beta builds triggers import --source "ci/export/unit-presubmit-node16.yaml"
56-
echo "importing presubmit unit build for node18 unit tests"
57-
gcloud beta builds triggers import --source "ci/export/unit-presubmit-node18.yaml"
49+
done

ci/run_conditional_tests.sh

+4-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ for subdir in ${subdirs[@]}; do
8484
if [[ "${changed}" -eq 0 ]]; then
8585
echo "no change detected in ${d}, skipping"
8686
else
87-
if [[ "${TEST_TYPE}" == "system" ]]; then
87+
if [[ "${TEST_TYPE}" == "system" ]] || [[ "${TEST_TYPE}" == "lint" ]] || [[ "${TEST_TYPE}" == "units" ]]; then
8888
echo "change detected in ${d} for system test"
8989
should_test=true
9090
elif [[ "${tests_with_credentials[*]}" =~ "${d}" ]] && [[ -n "${GOOGLE_APPLICATION_CREDENTIALS}" ]]; then
@@ -97,7 +97,7 @@ for subdir in ${subdirs[@]}; do
9797
fi
9898
else
9999
# If GIT_DIFF_ARG is empty, run all the tests.
100-
if [[ "${TEST_TYPE}" == "system" ]]; then
100+
if [[ "${TEST_TYPE}" == "system" ]] || [[ "${TEST_TYPE}" == "lint" ]] || [[ "${TEST_TYPE}" == "units" ]]; then
101101
echo "run system test for ${d}"
102102
should_test=true
103103
elif [[ "${tests_with_credentials[*]}" =~ "${d}" ]] && [[ -n "${GOOGLE_APPLICATION_CREDENTIALS}" ]]; then
@@ -118,6 +118,8 @@ for subdir in ${subdirs[@]}; do
118118
set -e
119119
if [ ${ret} -ne 0 ]; then
120120
RETVAL=${ret}
121+
# Since there are so many APIs, we should exit early if there's an error
122+
break
121123
fi
122124
popd
123125
fi

ci/run_single_test.sh

+8-7
Original file line numberDiff line numberDiff line change
@@ -41,36 +41,37 @@ if [ ${BUILD_TYPE} != "presubmit" ]; then
4141
fi
4242

4343
# Install dependencies
44-
if [[ "${tests_without_node12[*]}" =~ "${PROJECT}" ]] && [[ ${NODE_VERSION} == "12.22.12" ]]; then
44+
if [[ "${tests_without_node12[*]}" =~ "${PROJECT}" ]] && [[ ${NODE_VERSION} == "12.22.12" ]] && [[ ${TEST_TYPE} != "lint" ]]; then
4545
echo "not running tests for Node 12"
4646
elif [[ ${NODE_VERSION} == "12.22.12" ]]; then
4747
echo "npm install --unsafe-perm --ignore-scripts --engine-strict --only=prod; npm install --unsafe-perm"
4848
npm install --unsafe-perm --ignore-scripts --engine-strict --only=prod; npm install --unsafe-perm
4949
else
50-
echo "npm install --ignore-scripts --engine-strict --omit=dev; npm install"
51-
npm install --ignore-scripts --engine-strict --omit=dev; npm install
50+
echo "pnpm install --ignore-scripts --engine-strict --prod; pnpm install"
51+
pnpm install --ignore-scripts --engine-strict --prod; pnpm install
5252
fi
5353

5454
retval=0
5555

5656
set +e
5757
case ${TEST_TYPE} in
5858
lint)
59-
npm run lint
59+
pnpm prelint
60+
pnpm lint
6061
retval=$?
6162
;;
6263
samples)
63-
npm run samples-test
64+
pnpm samples-test
6465
retval=$?
6566
;;
6667
system)
67-
npm run system-test
68+
pnpm system-test
6869
retval=$?
6970
;;
7071
units)
7172
# Skipping Node 12 tests for projects outside of gapic autogenerated libraries that don't need to run on Node 12
7273
if ! [[ "${tests_without_node12[*]}" =~ "${PROJECT}" ]] || [[ ${NODE_VERSION} != "12.22.12" ]]; then
73-
npm test
74+
pnpm test
7475
retval=$?
7576
fi
7677
;;

containers/node-bootstrap-container/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
"homepage": "https://github.com/googleapis/google-cloud-node#readme",
2222
"dependencies": {
23-
"@octokit/rest": "^19.0.0"
23+
"@octokit/rest": "19.0.0"
2424
},
2525
"devDependencies": {
2626
"mocha": "^9.0.0",

packages/google-analytics-admin/package.json

+7-6
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,18 @@
3030
],
3131
"scripts": {
3232
"clean": "gts clean",
33-
"compile": "tsc -p . && cp -r protos build/ && minifyProtoJson",
33+
"compile": "tsc -p . && cp -r protos build/",
3434
"compile-protos": "compileProtos src",
3535
"docs": "jsdoc -c .jsdoc.js",
3636
"predocs-test": "npm run docs",
3737
"docs-test": "linkinator docs",
3838
"fix": "gts fix",
3939
"lint": "gts check",
40-
"prelint": "cd samples; npm link ../; npm i",
4140
"prepare": "npm run compile-protos && npm run compile",
42-
"samples-test": "npm run compile && cd samples/ && npm link ../ && npm i && npm test",
43-
"system-test": "npm run compile && c8 mocha build/system-test",
41+
"prelint": "cd samples; npm link ../; npm i",
42+
"postpack": "minifyProtoJson",
43+
"samples-test": "cd samples/ && npm link ../ && npm i && npm test",
44+
"system-test": "c8 mocha build/system-test",
4445
"test": "c8 mocha build/test"
4546
},
4647
"dependencies": {
@@ -58,6 +59,7 @@
5859
"jsdoc-fresh": "^2.0.0",
5960
"jsdoc-region-tag": "^2.0.0",
6061
"linkinator": "^4.0.0",
62+
"long": "^5.2.3",
6163
"mocha": "^9.2.2",
6264
"null-loader": "^4.0.0",
6365
"pack-n-play": "^1.0.0-2",
@@ -69,5 +71,4 @@
6971
"node": ">=12.0.0"
7072
},
7173
"homepage": "https://github.com/googleapis/google-cloud-node/tree/main/packages/google-analytics-admin"
72-
}
73-
74+
}

packages/google-analytics-admin/samples/test/quickstart.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Copyright 2023 Google LLC
12
//
23
// Licensed under the Apache License, Version 2.0 (the "License");
34
// you may not use this file except in compliance with the License.
@@ -29,6 +30,6 @@ const cwd = path.join(__dirname, '..');
2930
describe('Quickstart', async () => {
3031
it('should run quickstart', async () => {
3132
const output = execSync('node quickstart.js', {cwd});
32-
assert(output != null);
33+
assert(output !== null);
3334
});
3435
});

packages/google-analytics-data/package.json

+7-6
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,18 @@
3030
],
3131
"scripts": {
3232
"clean": "gts clean",
33-
"compile": "tsc -p . && cp -r protos build/ && minifyProtoJson",
33+
"compile": "tsc -p . && cp -r protos build/",
3434
"compile-protos": "compileProtos src",
3535
"docs": "jsdoc -c .jsdoc.js",
3636
"predocs-test": "npm run docs",
3737
"docs-test": "linkinator docs",
3838
"fix": "gts fix",
3939
"lint": "gts check",
40-
"prelint": "cd samples; npm link ../; npm i",
4140
"prepare": "npm run compile-protos && npm run compile",
42-
"samples-test": "npm run compile && cd samples/ && npm link ../ && npm i && npm test",
43-
"system-test": "npm run compile && c8 mocha build/system-test",
41+
"prelint": "cd samples; npm link ../; npm i",
42+
"postpack": "minifyProtoJson",
43+
"samples-test": "cd samples/ && npm link ../ && npm i && npm test",
44+
"system-test": "c8 mocha build/system-test",
4445
"test": "c8 mocha build/test"
4546
},
4647
"dependencies": {
@@ -56,6 +57,7 @@
5657
"jsdoc-fresh": "^2.0.0",
5758
"jsdoc-region-tag": "^2.0.0",
5859
"linkinator": "^4.0.0",
60+
"long": "^5.2.3",
5961
"mocha": "^9.2.2",
6062
"null-loader": "^4.0.0",
6163
"pack-n-play": "^1.0.0-2",
@@ -69,5 +71,4 @@
6971
"node": ">=12.0.0"
7072
},
7173
"homepage": "https://github.com/googleapis/google-cloud-node/tree/main/packages/google-analytics-data"
72-
}
73-
74+
}

0 commit comments

Comments
 (0)