Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate code from googleapis/nodejs-workflows #2826

Merged
merged 22 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/workflows.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@
"datacatalog/quickstart",
"datastore/functions",
"talent",
"contact-center-insights"
"contact-center-insights",
"workflows"
]
67 changes: 67 additions & 0 deletions .github/workflows/workflows.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: workflows
on:
push:
branches:
- main
paths:
- 'workflows/**'
pull_request:
paths:
- 'workflows/**'
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: workflows
- run: npm test
working-directory: workflows
env:
MOCHA_REPORTER_SUITENAME: workflows
MOCHA_REPORTER_OUTPUT: workflows_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}}
68 changes: 68 additions & 0 deletions workflows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
[//]: # "This README.md file is auto-generated, all changes to this file will be lost."
[//]: # "To regenerate it, use `python -m synthtool`."
<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>

# [Workflows: Node.js Samples](https://github.com/googleapis/nodejs-workflows)

[![Open in Cloud Shell][shell_img]][shell_link]



## Table of Contents

* [Before you begin](#before-you-begin)
* [Samples](#samples)
* [Create-execution](#create-execution)
* [Quickstart](#quickstart)

## 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-workflows#using-the-client-library).

`cd samples`

`npm install`

`cd ..`

## Samples



### Create-execution

View the [source code](https://github.com/googleapis/nodejs-workflows/blob/main/samples/create-execution.js).

[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-workflows&page=editor&open_in_editor=samples/create-execution.js,samples/README.md)

__Usage:__


`node samples/create-execution.js`


-----




### Quickstart

View the [source code](https://github.com/googleapis/nodejs-workflows/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-workflows&page=editor&open_in_editor=samples/quickstart.js,samples/README.md)

__Usage:__


`node samples/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-workflows&page=editor&open_in_editor=samples/README.md
[product-docs]: https://cloud.google.com/workflows/docs/
41 changes: 41 additions & 0 deletions workflows/create-execution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2020 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';

async function main(projectId, location, name) {
// [START workflows_create_execution]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'my-project';
// const location = 'us-central1';
// const name = 'my-test-workflow';
const {ExecutionsClient} = require('@google-cloud/workflows');
const client = new ExecutionsClient();
async function createExecution() {
const [resp] = await client.createExecution({
parent: client.workflowPath(projectId, location, name),
});
console.info(`name: ${resp.name}`);
}
createExecution();
// [END workflows_create_execution]
}

process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));
22 changes: 22 additions & 0 deletions workflows/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "nodejs-workflows-samples",
"private": true,
"license": "Apache-2.0",
"author": "Google LLC",
"engines": {
"node": ">=12.0.0"
},
"files": [
"*.js"
],
"scripts": {
"test": "c8 mocha --timeout 600000 test/*.js"
},
"dependencies": {
"@google-cloud/workflows": "^2.1.1"
},
"devDependencies": {
"c8": "^7.3.0",
"mocha": "^8.1.1"
}
}
42 changes: 42 additions & 0 deletions workflows/quickstart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2020 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';

async function main(projectId, location) {
// [START workflows_quickstart]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'my-project';
// const location = 'us-central1';
const {WorkflowsClient} = require('@google-cloud/workflows');
const client = new WorkflowsClient();
async function listWorkflows() {
const [workflows] = await client.listWorkflows({
parent: client.locationPath(projectId, location),
});
for (const workflow of workflows) {
console.info(`name: ${workflow.name}`);
}
}
listWorkflows();
// [END workflows_quickstart]
}

process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));
40 changes: 40 additions & 0 deletions workflows/test/create-execution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2020 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 path = require('path');
const assert = require('assert');
const cp = require('child_process');
const {describe, it} = require('mocha');

const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

const cwd = path.join(__dirname, '..');

const project = process.env.GCLOUD_PROJECT;
const location = 'us-central1';
const workflow = 'test-workflow-dont-delete';

describe('create-execution', () => {
it('should create an execution', async () => {
const output = execSync(
`node ./create-execution.js ${project} ${location} ${workflow}`,
{
cwd,
}
);
assert(output.match(/name: projects.*executions.*/));
});
});
35 changes: 35 additions & 0 deletions workflows/test/quickstart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2020 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 path = require('path');
const assert = require('assert');
const cp = require('child_process');
const {describe, it} = require('mocha');

const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

const cwd = path.join(__dirname, '..');

const project = process.env.GCLOUD_PROJECT;

describe('Quickstart', () => {
it('should run quickstart', async () => {
const output = execSync(`node ./quickstart.js ${project} us-central1`, {
cwd,
});
assert(output.match(/name: projects.*/));
});
});