diff --git a/.github/workflows/container-snippets.yaml b/.github/workflows/container-snippets.yaml new file mode 100644 index 0000000000..0481e1a68b --- /dev/null +++ b/.github/workflows/container-snippets.yaml @@ -0,0 +1,68 @@ +name: container-snippets +on: + push: + branches: + - main + paths: + - 'container/snippets/**' + pull_request: + paths: + - 'container/snippets/**' + pull_request_target: + types: [labeled] + paths: + - 'container/snippets/**' + 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.sha}} + - uses: 'google-github-actions/auth@v1.0.0' + 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: container/snippets + - run: npm test + working-directory: container/snippets + env: + MOCHA_REPORTER_SUITENAME: container_snippets + MOCHA_REPORTER_OUTPUT: container_snippets_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 eb1ec006e9..ea4290814e 100644 --- a/.github/workflows/workflows.json +++ b/.github/workflows/workflows.json @@ -26,6 +26,7 @@ "composer/functions/composer-storage-trigger", "container-analysis/snippets", "containerengine/hello-world", + "container/snippets", "datacatalog/cloud-client", "datalabeling", "datastore/functions", diff --git a/container/snippets/package.json b/container/snippets/package.json new file mode 100644 index 0000000000..280d4f2064 --- /dev/null +++ b/container/snippets/package.json @@ -0,0 +1,24 @@ +{ + "name": "nodejs-docs-samples-container", + "license": "Apache-2.0", + "author": "Google Inc.", + "engines": { + "node": ">=12.0.0" + }, + "repository": "googleapis/nodejs-cloud-container", + "private": true, + "files": [ + "*.js" + ], + "scripts": { + "test": "mocha system-test --timeout 1000000" + }, + "dependencies": { + "@google-cloud/container": "^4.4.0", + "uuid": "^9.0.0" + }, + "devDependencies": { + "chai": "^4.2.0", + "mocha": "^8.0.0" + } +} diff --git a/container/snippets/quickstart.js b/container/snippets/quickstart.js new file mode 100644 index 0000000000..b623e7de43 --- /dev/null +++ b/container/snippets/quickstart.js @@ -0,0 +1,41 @@ +// Copyright 2017 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. + +'use strict'; + +// [START gke_list_cluster] +async function main() { + // [START container_quickstart] + const container = require('@google-cloud/container'); + + // Create the Cluster Manager Client + const client = new container.v1.ClusterManagerClient(); + + async function quickstart() { + const zone = 'us-central1-a'; + const projectId = await client.getProjectId(); + const request = { + projectId: projectId, + zone: zone, + }; + + const [response] = await client.listClusters(request); + console.log('Clusters: ', response); + } + quickstart(); + // [END container_quickstart] +} + +main().catch(console.error); +// [END gke_list_cluster] diff --git a/container/snippets/system-test/quicktest.test.js b/container/snippets/system-test/quicktest.test.js new file mode 100644 index 0000000000..a301a489a9 --- /dev/null +++ b/container/snippets/system-test/quicktest.test.js @@ -0,0 +1,28 @@ +// Copyright 2017 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. + +'use strict'; + +const {assert} = require('chai'); +const {describe, it} = require('mocha'); +const cp = require('child_process'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); + +describe('container samples - quickstart', () => { + it('should run the quickstart', async () => { + const stdout = execSync('node quickstart'); + assert.match(stdout, /Clusters:/); + }); +});