Skip to content

Commit 9453ab3

Browse files
authored
feat(Build): introduce cloudbuild v2 (#5924)
1 parent 2a9a4b8 commit 9453ab3

55 files changed

Lines changed: 9295 additions & 2 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Build/.OwlBot.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
deep-copy-regex:
2-
- source: /google/devtools/cloudbuild/v1/.*-php/(.*)
3-
dest: /owl-bot-staging/Build/v1/$1
2+
- source: /google/devtools/cloudbuild/(v1|v2)/.*-php/(.*)
3+
dest: /owl-bot-staging/Build/$1/$2
44
api-name: Build

Build/metadata/V2/Cloudbuild.php

Lines changed: 53 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Build/metadata/V2/Repositories.php

9.51 KB
Binary file not shown.
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?php
2+
/*
3+
* Copyright 2023 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/*
19+
* GENERATED CODE WARNING
20+
* This file was automatically generated - do not edit!
21+
*/
22+
23+
require_once __DIR__ . '/../../../vendor/autoload.php';
24+
25+
// [START cloudbuild_v2_generated_RepositoryManager_BatchCreateRepositories_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\ApiCore\OperationResponse;
28+
use Google\Cloud\Build\V2\BatchCreateRepositoriesResponse;
29+
use Google\Cloud\Build\V2\CreateRepositoryRequest;
30+
use Google\Cloud\Build\V2\Repository;
31+
use Google\Cloud\Build\V2\RepositoryManagerClient;
32+
use Google\Rpc\Status;
33+
34+
/**
35+
* Creates multiple repositories inside a connection.
36+
*
37+
* @param string $formattedParent The connection to contain all the repositories being created.
38+
* Format: projects/&#42;/locations/&#42;/connections/*
39+
* The parent field in the CreateRepositoryRequest messages
40+
* must either be empty or match this field. Please see
41+
* {@see RepositoryManagerClient::connectionName()} for help formatting this field.
42+
* @param string $formattedRequestsParent The connection to contain the repository. If the request is part
43+
* of a BatchCreateRepositoriesRequest, this field should be empty or match
44+
* the parent specified there. Please see
45+
* {@see RepositoryManagerClient::connectionName()} for help formatting this field.
46+
* @param string $requestsRepositoryRemoteUri Git Clone HTTPS URI.
47+
* @param string $requestsRepositoryId The ID to use for the repository, which will become the final
48+
* component of the repository's resource name. This ID should be unique in
49+
* the connection. Allows alphanumeric characters and any of
50+
* -._~%!$&'()*+,;=&#64;.
51+
*/
52+
function batch_create_repositories_sample(
53+
string $formattedParent,
54+
string $formattedRequestsParent,
55+
string $requestsRepositoryRemoteUri,
56+
string $requestsRepositoryId
57+
): void {
58+
// Create a client.
59+
$repositoryManagerClient = new RepositoryManagerClient();
60+
61+
// Prepare any non-scalar elements to be passed along with the request.
62+
$requestsRepository = (new Repository())
63+
->setRemoteUri($requestsRepositoryRemoteUri);
64+
$createRepositoryRequest = (new CreateRepositoryRequest())
65+
->setParent($formattedRequestsParent)
66+
->setRepository($requestsRepository)
67+
->setRepositoryId($requestsRepositoryId);
68+
$requests = [$createRepositoryRequest,];
69+
70+
// Call the API and handle any network failures.
71+
try {
72+
/** @var OperationResponse $response */
73+
$response = $repositoryManagerClient->batchCreateRepositories($formattedParent, $requests);
74+
$response->pollUntilComplete();
75+
76+
if ($response->operationSucceeded()) {
77+
/** @var BatchCreateRepositoriesResponse $result */
78+
$result = $response->getResult();
79+
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
80+
} else {
81+
/** @var Status $error */
82+
$error = $response->getError();
83+
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
84+
}
85+
} catch (ApiException $ex) {
86+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
87+
}
88+
}
89+
90+
/**
91+
* Helper to execute the sample.
92+
*
93+
* This sample has been automatically generated and should be regarded as a code
94+
* template only. It will require modifications to work:
95+
* - It may require correct/in-range values for request initialization.
96+
* - It may require specifying regional endpoints when creating the service client,
97+
* please see the apiEndpoint client configuration option for more details.
98+
*/
99+
function callSample(): void
100+
{
101+
$formattedParent = RepositoryManagerClient::connectionName(
102+
'[PROJECT]',
103+
'[LOCATION]',
104+
'[CONNECTION]'
105+
);
106+
$formattedRequestsParent = RepositoryManagerClient::connectionName(
107+
'[PROJECT]',
108+
'[LOCATION]',
109+
'[CONNECTION]'
110+
);
111+
$requestsRepositoryRemoteUri = '[REMOTE_URI]';
112+
$requestsRepositoryId = '[REPOSITORY_ID]';
113+
114+
batch_create_repositories_sample(
115+
$formattedParent,
116+
$formattedRequestsParent,
117+
$requestsRepositoryRemoteUri,
118+
$requestsRepositoryId
119+
);
120+
}
121+
// [END cloudbuild_v2_generated_RepositoryManager_BatchCreateRepositories_sync]
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/*
3+
* Copyright 2023 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/*
19+
* GENERATED CODE WARNING
20+
* This file was automatically generated - do not edit!
21+
*/
22+
23+
require_once __DIR__ . '/../../../vendor/autoload.php';
24+
25+
// [START cloudbuild_v2_generated_RepositoryManager_CreateConnection_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\ApiCore\OperationResponse;
28+
use Google\Cloud\Build\V2\Connection;
29+
use Google\Cloud\Build\V2\RepositoryManagerClient;
30+
use Google\Rpc\Status;
31+
32+
/**
33+
* Creates a Connection.
34+
*
35+
* @param string $formattedParent Project and location where the connection will be created.
36+
* Format: `projects/&#42;/locations/*`. Please see
37+
* {@see RepositoryManagerClient::locationName()} for help formatting this field.
38+
* @param string $connectionId The ID to use for the Connection, which will become the final
39+
* component of the Connection's resource name. Names must be unique
40+
* per-project per-location. Allows alphanumeric characters and any of
41+
* -._~%!$&'()*+,;=&#64;.
42+
*/
43+
function create_connection_sample(string $formattedParent, string $connectionId): void
44+
{
45+
// Create a client.
46+
$repositoryManagerClient = new RepositoryManagerClient();
47+
48+
// Prepare any non-scalar elements to be passed along with the request.
49+
$connection = new Connection();
50+
51+
// Call the API and handle any network failures.
52+
try {
53+
/** @var OperationResponse $response */
54+
$response = $repositoryManagerClient->createConnection(
55+
$formattedParent,
56+
$connection,
57+
$connectionId
58+
);
59+
$response->pollUntilComplete();
60+
61+
if ($response->operationSucceeded()) {
62+
/** @var Connection $result */
63+
$result = $response->getResult();
64+
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
65+
} else {
66+
/** @var Status $error */
67+
$error = $response->getError();
68+
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
69+
}
70+
} catch (ApiException $ex) {
71+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
72+
}
73+
}
74+
75+
/**
76+
* Helper to execute the sample.
77+
*
78+
* This sample has been automatically generated and should be regarded as a code
79+
* template only. It will require modifications to work:
80+
* - It may require correct/in-range values for request initialization.
81+
* - It may require specifying regional endpoints when creating the service client,
82+
* please see the apiEndpoint client configuration option for more details.
83+
*/
84+
function callSample(): void
85+
{
86+
$formattedParent = RepositoryManagerClient::locationName('[PROJECT]', '[LOCATION]');
87+
$connectionId = '[CONNECTION_ID]';
88+
89+
create_connection_sample($formattedParent, $connectionId);
90+
}
91+
// [END cloudbuild_v2_generated_RepositoryManager_CreateConnection_sync]
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
/*
3+
* Copyright 2023 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/*
19+
* GENERATED CODE WARNING
20+
* This file was automatically generated - do not edit!
21+
*/
22+
23+
require_once __DIR__ . '/../../../vendor/autoload.php';
24+
25+
// [START cloudbuild_v2_generated_RepositoryManager_CreateRepository_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\ApiCore\OperationResponse;
28+
use Google\Cloud\Build\V2\Repository;
29+
use Google\Cloud\Build\V2\RepositoryManagerClient;
30+
use Google\Rpc\Status;
31+
32+
/**
33+
* Creates a Repository.
34+
*
35+
* @param string $formattedParent The connection to contain the repository. If the request is part
36+
* of a BatchCreateRepositoriesRequest, this field should be empty or match
37+
* the parent specified there. Please see
38+
* {@see RepositoryManagerClient::connectionName()} for help formatting this field.
39+
* @param string $repositoryRemoteUri Git Clone HTTPS URI.
40+
* @param string $repositoryId The ID to use for the repository, which will become the final
41+
* component of the repository's resource name. This ID should be unique in
42+
* the connection. Allows alphanumeric characters and any of
43+
* -._~%!$&'()*+,;=&#64;.
44+
*/
45+
function create_repository_sample(
46+
string $formattedParent,
47+
string $repositoryRemoteUri,
48+
string $repositoryId
49+
): void {
50+
// Create a client.
51+
$repositoryManagerClient = new RepositoryManagerClient();
52+
53+
// Prepare any non-scalar elements to be passed along with the request.
54+
$repository = (new Repository())
55+
->setRemoteUri($repositoryRemoteUri);
56+
57+
// Call the API and handle any network failures.
58+
try {
59+
/** @var OperationResponse $response */
60+
$response = $repositoryManagerClient->createRepository(
61+
$formattedParent,
62+
$repository,
63+
$repositoryId
64+
);
65+
$response->pollUntilComplete();
66+
67+
if ($response->operationSucceeded()) {
68+
/** @var Repository $result */
69+
$result = $response->getResult();
70+
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
71+
} else {
72+
/** @var Status $error */
73+
$error = $response->getError();
74+
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
75+
}
76+
} catch (ApiException $ex) {
77+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
78+
}
79+
}
80+
81+
/**
82+
* Helper to execute the sample.
83+
*
84+
* This sample has been automatically generated and should be regarded as a code
85+
* template only. It will require modifications to work:
86+
* - It may require correct/in-range values for request initialization.
87+
* - It may require specifying regional endpoints when creating the service client,
88+
* please see the apiEndpoint client configuration option for more details.
89+
*/
90+
function callSample(): void
91+
{
92+
$formattedParent = RepositoryManagerClient::connectionName(
93+
'[PROJECT]',
94+
'[LOCATION]',
95+
'[CONNECTION]'
96+
);
97+
$repositoryRemoteUri = '[REMOTE_URI]';
98+
$repositoryId = '[REPOSITORY_ID]';
99+
100+
create_repository_sample($formattedParent, $repositoryRemoteUri, $repositoryId);
101+
}
102+
// [END cloudbuild_v2_generated_RepositoryManager_CreateRepository_sync]

0 commit comments

Comments
 (0)