diff --git a/.github/workflows/datalabeling.yaml b/.github/workflows/datalabeling.yaml new file mode 100644 index 0000000000..9106e18a1a --- /dev/null +++ b/.github/workflows/datalabeling.yaml @@ -0,0 +1,67 @@ +name: datalabeling +on: + push: + branches: + - main + paths: + - "datalabeling/**" + pull_request: + paths: + - "datalabeling/**" + pull_request_target: + types: [labeled] + schedule: + - cron: "0 0 * * 0" +jobs: + test: + if: ${{ github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' }} + runs-on: ubuntu-latest + timeout-minutes: 60 + permissions: + contents: "write" + pull-requests: "write" + id-token: "write" + steps: + - uses: actions/checkout@v3.1.0 + with: + ref: ${{github.event.pull_request.head.ref}} + repository: ${{github.event.pull_request.head.repo.full_name}} + - uses: "google-github-actions/auth@v0.8.3" + with: + workload_identity_provider: "projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider" + service_account: "kokoro-system-test@long-door-651.iam.gserviceaccount.com" + create_credentials_file: "true" + access_token_lifetime: 600s + - uses: actions/setup-node@v3.5.1 + with: + node-version: 16 + - run: npm install + working-directory: datalabeling + - run: npm test + working-directory: datalabeling + env: + MOCHA_REPORTER_SUITENAME: datalabeling + MOCHA_REPORTER_OUTPUT: datalabeling_sponge_log.xml + MOCHA_REPORTER: xunit + - if: ${{ github.event.action == 'labeled' && github.event.label.name == 'actions:force-run' }} + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + try { + await github.rest.issues.removeLabel({ + name: 'actions:force-run', + owner: 'GoogleCloudPlatform', + repo: 'nodejs-docs-samples', + issue_number: context.payload.pull_request.number + }); + } catch (e) { + if (!e.message.includes('Label does not exist')) { + throw e; + } + } + - if: ${{ github.event_name == 'schedule'}} + run: | + curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot -o flakybot -s -L + chmod +x ./flakybot + ./flakybot --repo GoogleCloudPlatform/nodejs-docs-samples --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}} diff --git a/.github/workflows/workflows.json b/.github/workflows/workflows.json index 33afd91723..149b84bbb7 100644 --- a/.github/workflows/workflows.json +++ b/.github/workflows/workflows.json @@ -23,6 +23,7 @@ "composer/functions/composer-storage-trigger", "containerengine/hello-world", "datacatalog/cloud-client", + "datalabeling", "datastore/functions", "datacatalog/quickstart", "endpoints/getting-started", diff --git a/datalabeling/.eslintrc.yml b/datalabeling/.eslintrc.yml new file mode 100644 index 0000000000..282535f55f --- /dev/null +++ b/datalabeling/.eslintrc.yml @@ -0,0 +1,3 @@ +--- +rules: + no-console: off diff --git a/datalabeling/README.md b/datalabeling/README.md new file mode 100644 index 0000000000..dbd440a5bf --- /dev/null +++ b/datalabeling/README.md @@ -0,0 +1,52 @@ +[//]: # "This README.md file is auto-generated, all changes to this file will be lost." +[//]: # "To regenerate it, use `python -m synthtool`." +Google Cloud Platform logo + +# [Google Cloud Data Labeling: Node.js Samples](https://github.com/googleapis/nodejs-datalabeling) + +[![Open in Cloud Shell][shell_img]][shell_link] + + + +## Table of Contents + +* [Before you begin](#before-you-begin) +* [Samples](#samples) + * [Get Datasets](#get-datasets) + +## Before you begin + +Before running the samples, make sure you've followed the steps outlined in +[Using the client library](https://github.com/googleapis/nodejs-datalabeling#using-the-client-library). + +`cd samples` + +`npm install` + +`cd ..` + +## Samples + + + +### Get Datasets + +Gets all available Datasets. + +View the [source code](https://github.com/googleapis/nodejs-datalabeling/blob/main/samples/quickstart.js). + +[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-datalabeling&page=editor&open_in_editor=samples/quickstart.js,samples/README.md) + +__Usage:__ + + +`node quickstart.js` + + + + + + +[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png +[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-datalabeling&page=editor&open_in_editor=samples/README.md +[product-docs]: https://cloud.google.com/data-labeling/docs/ diff --git a/datalabeling/package.json b/datalabeling/package.json new file mode 100644 index 0000000000..119b20b1ed --- /dev/null +++ b/datalabeling/package.json @@ -0,0 +1,23 @@ +{ + "name": "nodejs-datalabeling-samples", + "private": true, + "license": "Apache-2.0", + "author": "Google LLC", + "engines": { + "node": ">=12.0.0" + }, + "files": [ + "*.js", + "!test/" + ], + "scripts": { + "test": "mocha --timeout 600000" + }, + "dependencies": { + "@google-cloud/datalabeling": "^3.1.0" + }, + "devDependencies": { + "chai": "^4.2.0", + "mocha": "^8.0.0" + } +} \ No newline at end of file diff --git a/datalabeling/quickstart.js b/datalabeling/quickstart.js new file mode 100644 index 0000000000..58f17cdc4b --- /dev/null +++ b/datalabeling/quickstart.js @@ -0,0 +1,37 @@ +// Copyright 2019 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 +// +// https://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. + +'use strict'; + +// sample-metadata: +// title: Get Datasets +// description: Gets all available Datasets. +// usage: node quickstart.js + +function main() { + // [START datalabeling_quickstart] + const {DataLabelingServiceClient} = require('@google-cloud/datalabeling'); + const client = new DataLabelingServiceClient(); + + async function quickstart() { + const projectId = await client.getProjectId(); + const parent = client.projectPath(projectId); + const [result] = await client.listDatasets({parent}); + console.log('Datasets:'); + console.log(result); + } + quickstart(); + // [END datalabeling_quickstart] +} +main(...process.argv.slice(2)); diff --git a/datalabeling/test/test.js b/datalabeling/test/test.js new file mode 100644 index 0000000000..eb3ba14c81 --- /dev/null +++ b/datalabeling/test/test.js @@ -0,0 +1,28 @@ +// Copyright 2019 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 +// +// https://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. + +'use strict'; + +const {assert} = require('chai'); +const {describe, it} = require('mocha'); +const {execSync} = require('child_process'); + +const exec = cmd => execSync(cmd, {encoding: 'utf8'}); + +describe('quickstart', () => { + it('should run the quickstart', () => { + const stdout = exec('node quickstart.js'); + assert.include(stdout, 'Datasets:'); + }); +});