From 27773ebbb8c789b7bedaaa70daea0aedba0ef32f Mon Sep 17 00:00:00 2001 From: francisco souza <108725+fsouza@users.noreply.github.com> Date: Mon, 20 Apr 2020 17:31:53 -0400 Subject: [PATCH] ci: re-enable node example (#219) * Revert "ci: remove run-node-example" This reverts commit fced9376eb03314c41673623f4a0b4895010f187. * Revert "github/workflows/ci: disable node example" This reverts commit bf01313ae3c359bb103bb1e8438c9c5648a4f728. * github/workflows: node 12 please * ci: exit on failure wat * examples/node: simplify & reformat code Co-authored-by: francisco souza --- .github/workflows/main.yml | 6 ++++++ ci/run-go-example.sh | 2 ++ ci/run-node-example.sh | 13 +++++++++++++ ci/run-python-example.sh | 2 ++ examples/node/index.js | 10 ++++++---- 5 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 ci/run-node-example.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 345ab6db6e..dd0246f1be 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -78,6 +78,12 @@ jobs: entrypoint: sh args: ci/run-python-example.sh + - name: test-node-example + uses: docker://node:12-alpine + with: + entrypoint: sh + args: ci/run-node-example.sh + - name: test-go-example uses: docker://golang:1.14-alpine env: diff --git a/ci/run-go-example.sh b/ci/run-go-example.sh index 3f8a07a36a..745e6be859 100644 --- a/ci/run-go-example.sh +++ b/ci/run-go-example.sh @@ -2,6 +2,8 @@ # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. +set -e + ./fake-gcs-server -backend memory -data $PWD/examples/data -public-host storage.gcs.127.0.0.1.nip.io:4443 & ( diff --git a/ci/run-node-example.sh b/ci/run-node-example.sh new file mode 100644 index 0000000000..6064df35f3 --- /dev/null +++ b/ci/run-node-example.sh @@ -0,0 +1,13 @@ +# Copyright 2019 Francisco Souza. All rights reserved. +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. + +set -e + +./fake-gcs-server -backend memory -data $PWD/examples/data & + +( + cd examples/node + npm ci + node index.js +) diff --git a/ci/run-python-example.sh b/ci/run-python-example.sh index 315ee2017a..983f8a83b7 100644 --- a/ci/run-python-example.sh +++ b/ci/run-python-example.sh @@ -2,6 +2,8 @@ # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. +set -e + ./fake-gcs-server -backend memory -data $PWD/examples/data & pip install -r examples/python/requirements.txt diff --git a/examples/node/index.js b/examples/node/index.js index 70430e999b..0a9f494dc0 100644 --- a/examples/node/index.js +++ b/examples/node/index.js @@ -1,10 +1,9 @@ process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0; -process.on("unhandledRejection", err => {throw err}); async function listBuckets() { // [START storage_list_buckets] // Imports the Google Cloud client library - const {Storage} = require("@google-cloud/storage"); + const { Storage } = require("@google-cloud/storage"); // Creates a client const storage = new Storage({ @@ -15,10 +14,13 @@ async function listBuckets() { // Lists all buckets in the current project const [buckets] = await storage.getBuckets(); console.log("Buckets:"); - buckets.forEach(bucket => { + buckets.forEach((bucket) => { console.log(bucket.id); }); // [END storage_list_buckets] } -listBuckets().then(console.log); +listBuckets().catch((err) => { + console.error(err); + process.exit(1); +});