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-cloudbuild #2824

Merged
merged 50 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
5a73471
feat: initial release of cloud build library (#2)
bcoe Oct 17, 2019
0c512cd
feat(docs): add listBuildTriggers sample to README (#5)
bcoe Oct 17, 2019
a367efc
feat: moves library to TypeScript code generation (#10)
bcoe Oct 31, 2019
19ed643
chore: release 1.0.0 (#3)
release-please[bot] Oct 31, 2019
1e12e42
chore: release 1.1.0 (#20)
release-please[bot] Nov 11, 2019
ac902f3
chore: update license headers
JustinBeckwith Nov 25, 2019
0b3af8f
chore: release 1.2.0 (#25)
release-please[bot] Dec 5, 2019
4e6cbc0
chore: release 1.3.0 (#33)
release-please[bot] Dec 11, 2019
4922427
chore(deps): update dependency c8 to v7 (#38)
renovate-bot Dec 28, 2019
c1b675c
refactor: use explicit mocha imports (#40)
JustinBeckwith Dec 30, 2019
2c638c1
chore(deps): update dependency mocha to v7 (#43)
renovate-bot Jan 6, 2020
aedda70
chore: release 1.3.1
release-please[bot] Jan 6, 2020
450c95a
chore: release 1.3.2 (#49)
release-please[bot] Jan 30, 2020
d8d1c22
chore: release 1.3.3 (#59)
release-please[bot] Feb 10, 2020
f1be19e
chore: release 1.4.0 (#63)
release-please[bot] Feb 13, 2020
abfae12
chore: release 1.5.0 (#67)
release-please[bot] Mar 9, 2020
5626de2
chore(deps): update dependency mocha to v8 (#122)
renovate-bot Jun 11, 2020
9cd95d5
chore: release 2.0.0 (#92)
release-please[bot] Jun 16, 2020
086df83
chore: release 2.0.1 (#126)
release-please[bot] Jul 7, 2020
fc150da
chore: release 2.0.2 (#133)
release-please[bot] Jul 10, 2020
b487c52
chore: release 2.0.3 (#143)
release-please[bot] Jul 28, 2020
3b2a639
chore: release 2.0.4 (#179)
release-please[bot] Nov 3, 2020
f611d87
chore: release 2.0.5 (#182)
release-please[bot] Nov 16, 2020
492df48
chore: release 2.0.6 (#186)
release-please[bot] Dec 2, 2020
f3fbea5
chore: release 2.1.0 (#205)
release-please[bot] Apr 3, 2021
7845fe1
chore: release 2.2.0 (#213)
release-please[bot] Apr 16, 2021
d9341ff
chore: release 2.2.1 (#220)
release-please[bot] May 8, 2021
7d64856
chore: release 2.2.2 (#227)
release-please[bot] May 13, 2021
ead65b5
chore: release 2.2.3 (#232)
release-please[bot] May 27, 2021
ae7646b
chore: release 2.2.4 (#242)
release-please[bot] Jun 24, 2021
0344b08
chore: release 2.2.5 (#247)
release-please[bot] Jul 1, 2021
e9be6a8
chore: release 2.2.6 (#250)
release-please[bot] Jul 15, 2021
465f7e0
chore: release 2.2.7 (#252)
release-please[bot] Jul 21, 2021
48a0f4c
chore: release 2.3.0 (#263)
release-please[bot] Aug 5, 2021
266ea93
chore: release 2.3.1 (#266)
release-please[bot] Aug 12, 2021
4441119
chore: release 2.3.2 (#269)
release-please[bot] Aug 16, 2021
30ca483
chore: release 2.4.0 (#270)
release-please[bot] Aug 16, 2021
664118a
chore: release 2.5.0 (#272)
release-please[bot] Aug 23, 2021
b36e0f4
chore: release 2.6.0 (#275)
release-please[bot] Aug 25, 2021
10273c0
docs(samples): add example tags to generated samples (#287)
gcf-owl-bot[bot] Nov 10, 2021
790f4da
chore(quickstart): mention private pool caveats (#317)
Apr 15, 2022
9ac3f3c
build!: update library to use Node 12 (#325)
alexander-fenster May 17, 2022
1b13448
chore(main): release 3.0.0 (#326)
release-please[bot] May 17, 2022
36351f5
chore(main): release 3.0.1 (#328)
release-please[bot] Jun 30, 2022
651e4f9
chore(main): release 3.1.0 (#334)
release-please[bot] Jul 4, 2022
a82f019
chore(main): release 3.1.1 (#340)
release-please[bot] Sep 8, 2022
bd527c1
chore(main): release 3.1.2 (#345)
release-please[bot] Sep 22, 2022
200a250
testing(cloudbuild): Add GitHub Workflows integration for test running
grayside Nov 10, 2022
7572697
chore(CODEOWNERS): Add cloudbuild ownership
grayside Nov 10, 2022
65cecaf
Merge branch 'main' into nodejs-cloudbuild-migration
grayside Nov 10, 2022
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
67 changes: 67 additions & 0 deletions .github/workflows/cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: cloudbuild
on:
push:
branches:
- main
paths:
- 'cloudbuild/**'
pull_request:
paths:
- 'cloudbuild/**'
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: cloudbuild
- run: npm test
working-directory: cloudbuild
env:
MOCHA_REPORTER_SUITENAME: cloudbuild
MOCHA_REPORTER_OUTPUT: cloudbuild_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}}
1 change: 1 addition & 0 deletions .github/workflows/workflows.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"appengine/typescript",
"appengine/websockets",
"appengine/twilio",
"cloudbuild",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick (feel free to ignore):
Should the folder name be cloud-build to be consistent with existing cloud-* folders in this repo?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm aligning with the the product API name and region tag, and think it's a minor bug where other directories don't but not necessarily worth fixing.

"cloud-language",
"cloud-tasks/tutorial-gcf/app",
"cloud-tasks/tutorial-gcf/function",
Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ run @GoogleCloudPlatform/torus-dpe @GoogleCloudPlatform/nodejs-samples-reviewers
cloud-tasks @GoogleCloudPlatform/torus-dpe @GoogleCloudPlatform/nodejs-samples-reviewers
workflows @GoogleCloudPlatform/torus-dpe @GoogleCloudPlatform/nodejs-samples-reviewers
eventarc @GoogleCloudPlatform/torus-dpe @GoogleCloudPlatform/nodejs-samples-reviewers
cloudbuild @GoogleCloudPlatform/torus-dpe @GoogleCloudPlatform/nodejs-samples-reviewers

# Infrastructure
orgpolicy @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/nodejs-samples-reviewers
Expand Down
43 changes: 43 additions & 0 deletions cloudbuild/listBuildTriggers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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.

'use strict';

// sample-metadata:
// title: List Triggers.
// description: List available build triggers.
// usage: node list-build-triggers.js <PROJECT_ID>

// [START cloudbuild_list_build_triggers]
async function listBuildTriggers(
projectId = 'YOUR_PROJECT_ID' // Your Google Cloud Platform project ID
) {
// Imports the Google Cloud client library
const {CloudBuildClient} = require('@google-cloud/cloudbuild');

// Creates a client
const cb = new CloudBuildClient();

// What project should we list triggers for?
const request = {
projectId,
};

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

const args = process.argv.slice(2);
listBuildTriggers(...args).catch(console.error);
25 changes: 25 additions & 0 deletions cloudbuild/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "nodejs-cloudbuild-samples",
"private": true,
"license": "Apache-2.0",
"files": [
"*.js",
"resources"
],
"author": "Google Inc.",
"repository": "googleapis/nodejs-cloudbuild",
"engines": {
"node": ">=12.0.0"
},
"scripts": {
"test": "c8 mocha system-test --timeout=800000"
},
"dependencies": {
"@google-cloud/cloudbuild": "^3.1.2"
},
"devDependencies": {
"c8": "^7.0.0",
"chai": "^4.2.0",
"mocha": "^8.0.0"
}
}
66 changes: 66 additions & 0 deletions cloudbuild/quickstart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 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';

// [START cloudbuild_quickstart]
async function quickstart(
projectId = 'YOUR_PROJECT_ID', // Your Google Cloud Platform project ID
triggerId = 'YOUR_TRIGGER_ID', // UUID for build trigger.
branchName = 'BRANCH_TO_BUILD' // Branch to run build against.
) {
// Imports the Google Cloud client library
const {CloudBuildClient} = require('@google-cloud/cloudbuild');

// Creates a client
const cb = new CloudBuildClient();

// Note: for Private Pools, you'll have to specify an API endpoint value
// For example:
// const cb = new CloudBuildClient({ apiEndpoint: '<YOUR_POOL_REGION>-cloudbuild.googleapis.com' });

// Starts a build against the branch provided.
const [resp] = await cb.runBuildTrigger({
projectId,
triggerId,
source: {
projectId,
dir: './',
branchName,
},
});
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]

const args = process.argv.slice(2);
quickstart(...args).catch(console.error);
3 changes: 3 additions & 0 deletions cloudbuild/system-test/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
rules:
node/no-extraneous-require: off
49 changes: 49 additions & 0 deletions cloudbuild/system-test/samples.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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.

'use strict';

const path = require('path');
const {assert} = require('chai');
const {describe, it} = require('mocha');
const cp = require('child_process');

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

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

const PROJECT_ID = process.env.GCLOUD_PROJECT;
// Use list-build-triggers.js to figure out the ID of the trigger
// you would like to execute.
const TRIGGER_ID =
process.env.TRIGGER || 'c9033094-51a9-44c5-b3a0-1d882deb4464';

describe('Sample Integration Tests', () => {
it('should run quickstart.js', async () => {
const stdout = execSync(
`node ./quickstart.js ${PROJECT_ID} ${TRIGGER_ID} cloud-build-mvp`,
{cwd}
);
// build should have exited with success status.
assert.include(stdout, 'status: Success');
});

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