Skip to content

Commit c6b78a3

Browse files
bcoeAce Nassri
authored and
Ace Nassri
committed
feat!: initial library generation (#8)
1 parent f03f09a commit c6b78a3

File tree

6 files changed

+248
-0
lines changed

6 files changed

+248
-0
lines changed

workflows/README.md

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
[//]: # "This README.md file is auto-generated, all changes to this file will be lost."
2+
[//]: # "To regenerate it, use `python -m synthtool`."
3+
<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"/>
4+
5+
# [Workflows: Node.js Samples](https://github.com/googleapis/nodejs-workflows)
6+
7+
[![Open in Cloud Shell][shell_img]][shell_link]
8+
9+
10+
11+
## Table of Contents
12+
13+
* [Before you begin](#before-you-begin)
14+
* [Samples](#samples)
15+
* [Create-execution](#create-execution)
16+
* [Quickstart](#quickstart)
17+
18+
## Before you begin
19+
20+
Before running the samples, make sure you've followed the steps outlined in
21+
[Using the client library](https://github.com/googleapis/nodejs-workflows#using-the-client-library).
22+
23+
`cd samples`
24+
25+
`npm install`
26+
27+
`cd ..`
28+
29+
## Samples
30+
31+
32+
33+
### Create-execution
34+
35+
View the [source code](https://github.com/googleapis/nodejs-workflows/blob/master/samples/create-execution.js).
36+
37+
[![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)
38+
39+
__Usage:__
40+
41+
42+
`node samples/create-execution.js`
43+
44+
45+
-----
46+
47+
48+
49+
50+
### Quickstart
51+
52+
View the [source code](https://github.com/googleapis/nodejs-workflows/blob/master/samples/quickstart.js).
53+
54+
[![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)
55+
56+
__Usage:__
57+
58+
59+
`node samples/quickstart.js`
60+
61+
62+
63+
64+
65+
66+
[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png
67+
[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
68+
[product-docs]: https://cloud.google.com/workflows/docs/

workflows/create-execution.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
async function main(projectId, location, name) {
18+
// [START workflows_create_execution]
19+
/**
20+
* TODO(developer): Uncomment these variables before running the sample.
21+
*/
22+
// const projectId = 'my-project';
23+
// const location = 'us-central1';
24+
// const name = 'my-test-workflow';
25+
const {ExecutionsClient} = require('@google-cloud/workflows');
26+
const client = new ExecutionsClient();
27+
async function createExecution() {
28+
const [resp] = await client.createExecution({
29+
parent: client.workflowPath(projectId, location, name),
30+
});
31+
console.info(`name: ${resp.name}`);
32+
}
33+
createExecution();
34+
// [END workflows_create_execution]
35+
}
36+
37+
process.on('unhandledRejection', (err) => {
38+
console.error(err.message);
39+
process.exitCode = 1;
40+
});
41+
main(...process.argv.slice(2));

workflows/package.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "nodejs-workflows-samples",
3+
"private": true,
4+
"license": "Apache-2.0",
5+
"author": "Google LLC",
6+
"engines": {
7+
"node": ">=10"
8+
},
9+
"files": [
10+
"*.js"
11+
],
12+
"scripts": {
13+
"test": "c8 mocha --timeout 600000 test/*.js"
14+
},
15+
"dependencies": {
16+
"@google-cloud/workflows": "^0.1.0"
17+
},
18+
"devDependencies": {
19+
"c8": "^7.3.0",
20+
"mocha": "^8.1.1"
21+
}
22+
}

workflows/quickstart.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
async function main(projectId, location) {
18+
// [START workflows_quickstart]
19+
/**
20+
* TODO(developer): Uncomment these variables before running the sample.
21+
*/
22+
// const projectId = 'my-project';
23+
// const location = 'us-central1';
24+
const {WorkflowsClient} = require('@google-cloud/workflows');
25+
const client = new WorkflowsClient();
26+
async function listWorkflows() {
27+
const [workflows] = await client.listWorkflows({
28+
parent: client.locationPath(projectId, location),
29+
});
30+
for (const workflow of workflows) {
31+
console.info(`name: ${workflow.name}`);
32+
}
33+
}
34+
listWorkflows();
35+
// [END workflows_quickstart]
36+
}
37+
38+
process.on('unhandledRejection', (err) => {
39+
console.error(err.message);
40+
process.exitCode = 1;
41+
});
42+
main(...process.argv.slice(2));

workflows/test/create-execution.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
const path = require('path');
18+
const assert = require('assert');
19+
const cp = require('child_process');
20+
const {describe, it} = require('mocha');
21+
22+
const execSync = (cmd) => cp.execSync(cmd, {encoding: 'utf-8'});
23+
24+
const cwd = path.join(__dirname, '..');
25+
26+
const project = process.env.GCLOUD_PROJECT;
27+
const location = 'us-central1';
28+
const workflow = 'test-workflow-dont-delete';
29+
30+
describe('create-execution', () => {
31+
it('should create an execution', async () => {
32+
const output = execSync(
33+
`node ./create-execution.js ${project} ${location} ${workflow}`,
34+
{
35+
cwd,
36+
}
37+
);
38+
assert(output.match(/name: projects.*executions.*/));
39+
});
40+
});

workflows/test/quickstart.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
const path = require('path');
18+
const assert = require('assert');
19+
const cp = require('child_process');
20+
const {describe, it} = require('mocha');
21+
22+
const execSync = (cmd) => cp.execSync(cmd, {encoding: 'utf-8'});
23+
24+
const cwd = path.join(__dirname, '..');
25+
26+
const project = process.env.GCLOUD_PROJECT;
27+
28+
describe('Quickstart', () => {
29+
it('should run quickstart', async () => {
30+
const output = execSync(`node ./quickstart.js ${project} us-central1`, {
31+
cwd,
32+
});
33+
assert(output.match(/name: projects.*/));
34+
});
35+
});

0 commit comments

Comments
 (0)