Skip to content

Commit

Permalink
feat: moves library to TypeScript code generation (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe authored Oct 31, 2019
1 parent eecc8b0 commit d815de8
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 35 deletions.
2 changes: 1 addition & 1 deletion generated,README.md,.eslintrc.yml/listBuildTriggers.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async function listBuildTriggers(
};

const [result] = await cb.listBuildTriggers(request);
console.info(JSON.stringify(result.triggers, null, 2));
console.info(JSON.stringify(result, null, 2));
}
// [END cloudbuild_list_build_triggers]

Expand Down
5 changes: 3 additions & 2 deletions generated,README.md,.eslintrc.yml/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
"node": ">=8"
},
"scripts": {
"test": "mocha system-test --timeout=800000"
"test": "c8 mocha system-test --timeout=800000"
},
"dependencies": {
"@google-cloud/cloudbuild": "^0.1.0"
},
"devDependencies": {
"c8": "^6.0.1",
"chai": "^4.2.0",
"mocha": "^6.0.0"
}
}
}
52 changes: 34 additions & 18 deletions generated,README.md,.eslintrc.yml/quickstart.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/**
* 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
*
* 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.
*/
// 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';

Expand All @@ -28,17 +28,33 @@ async function quickstart(
const cb = new CloudBuildClient();

// Starts a build against the branch provided.
const request = {
const [resp] = await cb.runBuildTrigger({
projectId,
triggerId,
source: {
projectId: projectId,
projectId,
dir: './',
branchName,
},
};
await cb.runBuildTrigger(request);
});
console.info(`triggered build for ${triggerId}`);
const [build] = await resp.promise();

const STATUS_LOOKUP = [
'UNKNOWN',
'Queued',
'Working',
'Success',
'Failure',
'Error',
'Timeout',
'Cancelled',
];
for (const step of build.steps) {
console.info(
`step:\n\tname: ${step.name}\n\tstatus: ${STATUS_LOOKUP[build.status]}`
);
}
}
// [END cloudbuild_quickstart]

Expand Down
19 changes: 5 additions & 14 deletions generated,README.md,.eslintrc.yml/system-test/samples.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,19 @@ const PROJECT_ID = process.env.GCLOUD_PROJECT;
const TRIGGER_ID =
process.env.TRIGGER || 'c9033094-51a9-44c5-b3a0-1d882deb4464';

const {CloudBuildClient} = require('@google-cloud/cloudbuild');
const cb = new CloudBuildClient();

describe('Sample Integration Tests', () => {
it('should run quickstart.js', async () => {
execSync(
`node ./samples/quickstart.js ${PROJECT_ID} ${TRIGGER_ID} cloud-build-mvp`,
const stdout = execSync(
`node ./quickstart.js ${PROJECT_ID} ${TRIGGER_ID} cloud-build-mvp`,
{cwd}
);
// confirm that a build has just been kicked off.
const [builds] = await cb.listBuilds({
projectId: PROJECT_ID,
});
const createTime = builds[0].createTime.seconds * 1000;
const delta = Date.now() - createTime;
const maxDelta = 20000; // last build was within 20s.
assert.ok(delta < maxDelta, `delta ${delta} was > ${maxDelta}`);
// build should have exited with success status.
assert.include(stdout, 'status: Success');
});

it('should run list-build-triggers.js', async () => {
const stdout = execSync(
`node ./samples/listBuildTriggers.js ${PROJECT_ID} ${TRIGGER_ID} cloud-build-mvp`,
`node ./listBuildTriggers.js ${PROJECT_ID} ${TRIGGER_ID} cloud-build-mvp`,
{cwd}
);
assert.include(stdout, 'Push-to-any-branch');
Expand Down

0 comments on commit d815de8

Please sign in to comment.