From 2800f5a85af0e0399c71a63169a53ade3e0d42f6 Mon Sep 17 00:00:00 2001 From: sofisl <55454395+sofisl@users.noreply.github.com> Date: Thu, 14 Apr 2022 10:35:02 -0700 Subject: [PATCH] build: make ci testing conditional on engines field in package.json, move configs to Node 12 (#1418) * build: make ci testing conditional on engines field in package.json, move configs to Node 12 Co-authored-by: Benjamin E. Coe --- .../node_library/.github/workflows/ci.yaml | 2 +- .../templates/node_library/.kokoro/common.cfg | 2 +- .../.kokoro/continuous/node10/common.cfg | 34 --------- .../.kokoro/continuous/node10/docs.cfg | 4 -- .../.kokoro/continuous/node10/test.cfg | 9 --- .../.kokoro/presubmit/node10/common.cfg | 34 --------- .../node_library/.kokoro/release/docs.cfg | 2 +- .../node_library/.kokoro/samples-test.sh | 2 +- .../node_library/.kokoro/system-test.sh | 2 +- .../templates/node_library/.kokoro/test.sh | 2 +- synthtool/languages/node.py | 3 +- .../node_templates/standard/package.json | 72 +++++++++++++++++++ tests/test_node.py | 6 ++ 13 files changed, 86 insertions(+), 88 deletions(-) delete mode 100644 synthtool/gcp/templates/node_library/.kokoro/continuous/node10/common.cfg delete mode 100644 synthtool/gcp/templates/node_library/.kokoro/continuous/node10/docs.cfg delete mode 100644 synthtool/gcp/templates/node_library/.kokoro/continuous/node10/test.cfg delete mode 100644 synthtool/gcp/templates/node_library/.kokoro/presubmit/node10/common.cfg create mode 100644 tests/fixtures/node_templates/standard/package.json diff --git a/synthtool/gcp/templates/node_library/.github/workflows/ci.yaml b/synthtool/gcp/templates/node_library/.github/workflows/ci.yaml index c4eb9b183..8730b393c 100644 --- a/synthtool/gcp/templates/node_library/.github/workflows/ci.yaml +++ b/synthtool/gcp/templates/node_library/.github/workflows/ci.yaml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node: [10, 12, 14, 16] + node: [{{metadata['engine'] | int}}, {{metadata['engine'] | int+2}}, {{metadata['engine'] | int+4}}] steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 diff --git a/synthtool/gcp/templates/node_library/.kokoro/common.cfg b/synthtool/gcp/templates/node_library/.kokoro/common.cfg index 5072f652e..0df7d844b 100644 --- a/synthtool/gcp/templates/node_library/.kokoro/common.cfg +++ b/synthtool/gcp/templates/node_library/.kokoro/common.cfg @@ -16,7 +16,7 @@ build_file: "{{ metadata['repository_name'] }}/.kokoro/trampoline_v2.sh" # Configure the docker image for kokoro-trampoline. env_vars: { key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/node:10-user" + value: "gcr.io/cloud-devrel-kokoro-resources/node:12-user" } env_vars: { key: "TRAMPOLINE_BUILD_FILE" diff --git a/synthtool/gcp/templates/node_library/.kokoro/continuous/node10/common.cfg b/synthtool/gcp/templates/node_library/.kokoro/continuous/node10/common.cfg deleted file mode 100644 index a27b03619..000000000 --- a/synthtool/gcp/templates/node_library/.kokoro/continuous/node10/common.cfg +++ /dev/null @@ -1,34 +0,0 @@ -# Format: //devtools/kokoro/config/proto/build.proto - -# Build logs will be here -action { - define_artifacts { - regex: "**/*sponge_log.xml" - } -} - -# Bring in codecov.io token into the build as $KOKORO_KEYSTORE_DIR/73713_dpebot_codecov_token -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 73713 - keyname: "dpebot_codecov_token" - } - } -} - -# Download trampoline resources. -gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" - -# Use the trampoline script to run in docker. -build_file: "{{ metadata['repository_name'] }}/.kokoro/trampoline_v2.sh" - -# Configure the docker image for kokoro-trampoline. -env_vars: { - key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/node:10-user" -} -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/{{ metadata['repository_name'] }}/.kokoro/test.sh" -} diff --git a/synthtool/gcp/templates/node_library/.kokoro/continuous/node10/docs.cfg b/synthtool/gcp/templates/node_library/.kokoro/continuous/node10/docs.cfg deleted file mode 100644 index 2c5d393f3..000000000 --- a/synthtool/gcp/templates/node_library/.kokoro/continuous/node10/docs.cfg +++ /dev/null @@ -1,4 +0,0 @@ -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/{{ metadata['repository_name'] }}/.kokoro/docs.sh" -} diff --git a/synthtool/gcp/templates/node_library/.kokoro/continuous/node10/test.cfg b/synthtool/gcp/templates/node_library/.kokoro/continuous/node10/test.cfg deleted file mode 100644 index 609c0cf0a..000000000 --- a/synthtool/gcp/templates/node_library/.kokoro/continuous/node10/test.cfg +++ /dev/null @@ -1,9 +0,0 @@ -# Bring in codecov.io token into the build as $KOKORO_KEYSTORE_DIR/73713_dpebot_codecov_token -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 73713 - keyname: "dpebot_codecov_token" - } - } -} diff --git a/synthtool/gcp/templates/node_library/.kokoro/presubmit/node10/common.cfg b/synthtool/gcp/templates/node_library/.kokoro/presubmit/node10/common.cfg deleted file mode 100644 index a27b03619..000000000 --- a/synthtool/gcp/templates/node_library/.kokoro/presubmit/node10/common.cfg +++ /dev/null @@ -1,34 +0,0 @@ -# Format: //devtools/kokoro/config/proto/build.proto - -# Build logs will be here -action { - define_artifacts { - regex: "**/*sponge_log.xml" - } -} - -# Bring in codecov.io token into the build as $KOKORO_KEYSTORE_DIR/73713_dpebot_codecov_token -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 73713 - keyname: "dpebot_codecov_token" - } - } -} - -# Download trampoline resources. -gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" - -# Use the trampoline script to run in docker. -build_file: "{{ metadata['repository_name'] }}/.kokoro/trampoline_v2.sh" - -# Configure the docker image for kokoro-trampoline. -env_vars: { - key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/node:10-user" -} -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/{{ metadata['repository_name'] }}/.kokoro/test.sh" -} diff --git a/synthtool/gcp/templates/node_library/.kokoro/release/docs.cfg b/synthtool/gcp/templates/node_library/.kokoro/release/docs.cfg index 4c2a59419..93f7acbbf 100644 --- a/synthtool/gcp/templates/node_library/.kokoro/release/docs.cfg +++ b/synthtool/gcp/templates/node_library/.kokoro/release/docs.cfg @@ -11,7 +11,7 @@ before_action { # doc publications use a Python image. env_vars: { key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/node:10-user" + value: "gcr.io/cloud-devrel-kokoro-resources/node:12-user" } # Download trampoline resources. diff --git a/synthtool/gcp/templates/node_library/.kokoro/samples-test.sh b/synthtool/gcp/templates/node_library/.kokoro/samples-test.sh index 3611785bc..91c1c7878 100755 --- a/synthtool/gcp/templates/node_library/.kokoro/samples-test.sh +++ b/synthtool/gcp/templates/node_library/.kokoro/samples-test.sh @@ -56,7 +56,7 @@ fi # codecov combines coverage across integration and unit tests. Include # the logic below for any environment you wish to collect coverage for: -COVERAGE_NODE=10 +COVERAGE_NODE=12 if npx check-node-version@3.3.0 --silent --node $COVERAGE_NODE; then NYC_BIN=./node_modules/nyc/bin/nyc.js if [ -f "$NYC_BIN" ]; then diff --git a/synthtool/gcp/templates/node_library/.kokoro/system-test.sh b/synthtool/gcp/templates/node_library/.kokoro/system-test.sh index d1e020ce0..b93793e4f 100755 --- a/synthtool/gcp/templates/node_library/.kokoro/system-test.sh +++ b/synthtool/gcp/templates/node_library/.kokoro/system-test.sh @@ -49,7 +49,7 @@ npm run system-test # codecov combines coverage across integration and unit tests. Include # the logic below for any environment you wish to collect coverage for: -COVERAGE_NODE=10 +COVERAGE_NODE=12 if npx check-node-version@3.3.0 --silent --node $COVERAGE_NODE; then NYC_BIN=./node_modules/nyc/bin/nyc.js if [ -f "$NYC_BIN" ]; then diff --git a/synthtool/gcp/templates/node_library/.kokoro/test.sh b/synthtool/gcp/templates/node_library/.kokoro/test.sh index af1ce7e33..a5c7ac04c 100755 --- a/synthtool/gcp/templates/node_library/.kokoro/test.sh +++ b/synthtool/gcp/templates/node_library/.kokoro/test.sh @@ -39,7 +39,7 @@ npm test # codecov combines coverage across integration and unit tests. Include # the logic below for any environment you wish to collect coverage for: -COVERAGE_NODE=10 +COVERAGE_NODE=12 if npx check-node-version@3.3.0 --silent --node $COVERAGE_NODE; then NYC_BIN=./node_modules/nyc/bin/nyc.js if [ -f "$NYC_BIN" ]; then diff --git a/synthtool/languages/node.py b/synthtool/languages/node.py index 315a4ccc5..281c9d4cd 100644 --- a/synthtool/languages/node.py +++ b/synthtool/languages/node.py @@ -24,7 +24,7 @@ import logging import shutil -_REQUIRED_FIELDS = ["name", "repository"] +_REQUIRED_FIELDS = ["name", "repository", "engines"] _TOOLS_DIRECTORY = "/synthtool" @@ -48,6 +48,7 @@ def read_metadata(): data["repository"] = f'{repo["owner"]}/{repo["name"]}' data["repository_name"] = repo["name"] data["lib_install_cmd"] = f'npm install {data["name"]}' + data["engine"] = re.search(r"([0-9][0-9])", data["engines"]["node"]).group() return data diff --git a/tests/fixtures/node_templates/standard/package.json b/tests/fixtures/node_templates/standard/package.json new file mode 100644 index 000000000..bc6436e8c --- /dev/null +++ b/tests/fixtures/node_templates/standard/package.json @@ -0,0 +1,72 @@ +{ + "name": "@google-cloud/dlp", + "description": "DLP API client for Node.js", + "version": "3.1.0", + "license": "Apache-2.0", + "author": "Google Inc", + "engines": { + "node": ">=10.0.0" + }, + "repository": "googleapis/nodejs-dlp", + "main": "build/src/index.js", + "files": [ + "build/protos", + "build/src" + ], + "keywords": [ + "google apis client", + "google api client", + "google apis", + "google api", + "google", + "google cloud platform", + "google cloud", + "cloud", + "google dlp", + "dlp", + "DLP API" + ], + "scripts": { + "test": "c8 mocha build/test", + "samples-test": "cd samples/ && npm link ../ && npm install && npm test && cd ../", + "system-test": "mocha build/system-test", + "docs": "jsdoc -c .jsdoc.js", + "lint": "gts check", + "fix": "gts fix", + "docs-test": "linkinator docs", + "clean": "gts clean", + "compile": "tsc -p . && cp -r protos build/", + "compile-protos": "compileProtos src", + "predocs-test": "npm run docs", + "prepare": "npm run compile-protos && npm run compile", + "prelint": "cd samples; npm link ../; npm install", + "precompile": "gts clean", + "api-extractor": "api-extractor run --local", + "api-documenter": "api-documenter yaml --input-folder=temp" + }, + "dependencies": { + "google-gax": "^2.9.2", + "protobufjs": "^6.8.0" + }, + "devDependencies": { + "@types/mocha": "^8.0.0", + "@types/node": "^12.0.0", + "@types/sinon": "^9.0.0", + "c8": "^7.0.0", + "gts": "^2.0.0", + "jsdoc": "^3.5.5", + "jsdoc-fresh": "^1.0.1", + "jsdoc-region-tag": "^1.0.2", + "linkinator": "^2.0.0", + "mocha": "^8.0.0", + "null-loader": "^4.0.0", + "pack-n-play": "^1.0.0-2", + "sinon": "^10.0.0", + "ts-loader": "^8.0.0", + "typescript": "^3.8.3", + "webpack": "^5.0.0", + "webpack-cli": "^4.0.0", + "@microsoft/api-documenter": "^7.8.10", + "@microsoft/api-extractor": "^7.8.10" + } + } \ No newline at end of file diff --git a/tests/test_node.py b/tests/test_node.py index a44dbd136..383876444 100644 --- a/tests/test_node.py +++ b/tests/test_node.py @@ -43,6 +43,12 @@ def test_quickstart_metadata_with_snippet(): assert "samples/quickstart.js" in sample_names +def test_metadata_engines_field(): + with util.chdir(FIXTURES / "node_templates" / "standard"): + metadata = node.template_metadata() + assert "10" in metadata["engine"] + + def test_quickstart_metadata_without_snippet(): with util.chdir(FIXTURES / "node_templates" / "no_quickstart_snippet"): metadata = node.template_metadata()